#!/bin/sh -e

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
#

USER=kiosek
HOME=/home/$USER
XORG=/etc/X11/xorg.conf
XWRAP=/etc/X11/Xwrapper.config

case "$1" in
    configure)
	# nalinkovani vseho potrebneho, co se bude hodit
	ln -sfn /afs/zcu.cz/public/kiosky/firefox/etc /etc/kiosek
	ln -sfn /etc/kiosek/xscreensaver /etc/X11/app-defaults/XScreenSaver-gl
	[ ! -d /var/www ] && mkdir /var/www
	ln -sfn /afs/zcu.cz/public/kiosky/firefox/var/www /var/www/kiosek
	[ ! -d /var/lib ] && mkdir /var/lib
	ln -sfn /afs/zcu.cz/public/kiosky/firefox/var/lib /var/lib/kiosek
	#ln -sfn /afs/zcu.cz/public/kiosky/firefox/var/xscreensaver /var/xscreensaver/kiosek

	# nalinkovani bookmarku a filtru
	#ln -sfn /var/lib/kiosek/allowed-sites.txt /home/kiosek/config/firefox/*.default/
	#ln -sfn /var/lib/kiosek/bookmarks.html /home/kiosek/config/firefox/*.default/
	
	# uprava xorgu
	#cp $XORG $XORG.pre_kiosek
	#cp $XWRAP $XWRAP.pre_kiosek

	#if [ -e ${XORG}.pre_kiosek ] ; then
	#	cat ${XORG}.pre_kiosek | awk '/^[^#].*DontZap/    { print "Option \"DontZap\" \"Yes\"\n Option \"DontVTSwitch\" \"Yes\"\n"; next} \
        #	/^[^#].*XkbLayout/  { print "Option \"XkbLayout\" \"cz,us\"\nOption \"XKbOptions\" \"grp:alt_shift_toggle\"\n"; next} \
	#	//' > $XORG
	#fi
	if [ -e ${XWRAP}.pre_kiosek ] ; then
		cat ${XWRAP}.pre_kiosek | sed -e 's/^[^#]*allowed_users.*/allowed_users=anybody/' > $XWRAP
	fi

	chown -R $USER:users $HOME

        update-rc.d kiosek defaults 99
	[ -f /etc/init.d/gdm ] && update-rc.d -f gdm remove

        #update-mozilla-firefox-chrome
    ;;

    abort-upgrade|abort-remove|abort-deconfigure)

    ;;

    *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

echo "Please restart any running Firefoxes, or you will experience problems."

exit 0
