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

set -e

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


