#!/bin/sh
# preinst script for gnuspool
#
# see: dh_installdeb(1)

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

Username=gnuspool
Groupname=lp
Homedir=/var/gnuspool
Uid=50

case "$1" in
    install|upgrade)
	if ! grep -q "^$Username:" /etc/passwd; then
	    grep -q "^$Groupname:" /etc/group || Groupname=root
	    while grep -q "^[^:]*:[^:]*:$Uid:" /etc/passwd; do Uid=`expr $Uid + 1`; done
	    useradd -c 'GNUspool system user' -d $Homedir -g $Groupname -u $Uid -r -o $Username
	fi
    ;;

    abort-upgrade) :
    ;;

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

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

#DEBHELPER#

exit 0
