#!/bin/sh
# postinst script
#
# see: dh_installdeb(1)

set -e

# summary of how this script can be called:
#        * <postinst> `configure' <most-recently-configured-version>
#        * <old-postinst> `abort-upgrade' <new version>
#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
#          <new-version>
#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
#          <failed-install-package> <version> `removing'
#          <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package
#
# quoting from the policy:
#     Any necessary prompting should almost always be confined to the
#     post-installation script, and should be protected with a conditional
#     so that unnecessary prompting doesn't happen if a package's
#     installation fails and the `postinst' is called with `abort-upgrade',
#     `abort-remove' or `abort-deconfigure'.



if [ "$1" == "configure" ] || [ "$1" == "upgrade" ]; then

	# folder that should remain after updates
	persistentFolder=/home/user/.qtmobilehotspot
	[ ! -d $persistentFolder ] && mkdir $persistentFolder
	chown user:users $persistentFolder

	# remove the dummy plugin (not useful for end-users)
	dummyPlugin=/opt/qtmobilehotspot/plugins/libqtmhdummy.so
	[ -e $dummyPlugin ] && rm $dummyPlugin

	# make files executable
	appExecutable=/opt/qtmobilehotspot/qtmobilehotspot
		[ -e $appExecutable ] && chmod a+x $appExecutable
	startupScript=/opt/qtmobilehotspot/util/start.sh
		[ -e $startupScript ] && chmod a+x $startupScript
	protectionScript=/opt/qtmobilehotspot/util/systemprotection.sh
		[ -e $protectionScript ] && chmod a+x $protectionScript
	privoxyExecutable=/opt/qtmobilehotspot/util/qtmhprivoxy/privoxy.executable
		[ -e $privoxyExecutable ] && chmod a+x $privoxyExecutable
	
	# copy windows driver to MyDocs
	mydocsFolder=/home/user/MyDocs
	destFolder=$mydocsFolder/QtMobileHotspot-Driver
	fromFolder=/opt/qtmobilehotspot/docs/windows-usb-driver
	if [ -d $mydocsFolder ]; then
		[ ! -d $destFolder ] && mkdir $destFolder
		cp -R $fromFolder $destFolder
	fi

fi

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.
#DEBHELPER#

exit 0


