#!/bin/sh -e

set -e

# summary of how this script can be called:
#        * <new-preinst> `install'
#        * <new-preinst> `install' <old-version>
#        * <new-preinst> `upgrade' <old-version>
#        * <old-preinst> `abort-upgrade' <new-version>
#
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package

USER=kiosek
GROUP=$USER

case "$1" in
    install|upgrade)

        if [ "$1" = "upgrade" -a -f /etc/init.d/kiosek ]; then
		/etc/init.d/kiosek stop
	fi

        if [ "$1" = "install" ]; then
            addgroup --system $GROUP
	    adduser --system --home /home/$USER --shell /bin/sh --disabled-password $USER
	    #instalace baliku zavislich
	    # browser se nekdy snazi sahat na /dev/dsp .. tak zamezime hlaskam
	    adduser $USER audio
	    adduser $USER video
	    adduser $USER users
            echo "Diverting the xcreensaver-getimage-file..."
            dpkg-divert --divert /usr/bin/xcreensaver-getimage-file --rename /usr/bin/xcreensaver-getimage-file.tvkiosek
	fi
    ;;

    abort-upgrade)
    ;;

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

exit 0
