#!/bin/sh
echo "BEGIN postinstall@0.9.4-1: $*" 1>&2

if [ -f /opt/smscon-editor/smsconEditorCopyConfig ]
then
    # remove files from older versions that are no longer needed.
    chmod 666  /opt/smscon-editor/smsconEditorCopyConfig
    rm -f      /opt/smscon-editor/smsconEditorCopyConfig
fi

chmod 740  /opt/smscon-editor/smsconEditorCreatePass
chmod 755  /opt/smscon-editor/smscon-editor
chown root /opt/smscon-editor/*
chmod 644  /usr/share/applications/hildon/smscon-editor.desktop
chown root /usr/share/applications/hildon/smscon-editor.desktop
chmod 644  /etc/sudoers.d/smscon-editor.sudoers
chown root /etc/sudoers.d/smscon-editor.sudoers
update-sudoers

rm -f      /opt/smscon-editor/*.py[oc]
python -m compileall /opt/smscon-editor
chmod 644  /opt/smscon-editor/*.py*
rm -f      /opt/smscon-editor/*.py
chown root /opt/smscon-editor/*

# Do not call smsconEditorCreatePass here, it would try to send sms to yet undefined number.
test -f    /opt/smscon-editor/smsconEditorPass || (echo "12345" | md5sum >/opt/smscon-editor/smsconEditorPass)
chmod 644  /opt/smscon-editor/smsconEditorPass
chown root /opt/smscon-editor/smsconEditorPass

# Make a symlink for starting the UI easier from terminal
if [ -f /usr/bin/smscon-editor ]; then
   rm -rf /usr/bin/smscon-editor
fi
ln -s /opt/smscon-editor/smscon-editor /usr/bin/smscon-editor

gtk-update-icon-cache -f /usr/share/icons/hicolor

echo "  END postinstall@0.9.4-1: $*" 1>&2
