#! /bin/sh
set -e

NAME=apt-proxy
APTPROXY_USER=aptproxy
APTPROXY_LOGFILE=/var/log/$NAME.log
CACHEDIR=/var/cache/apt-proxy

PREV="$2"

case "$1" in
    configure)
        # Check if the user exist and do what is needed
        if ! id $APTPROXY_USER > /dev/null 2>&1; then
            # Create user
            echo creating $APTPROXY_USER user...
            adduser --quiet --system --ingroup nogroup \
                --home $CACHEDIR --no-create-home $APTPROXY_USER
        fi

        # Make apt-proxy user own cache directory
        chown -R $APTPROXY_USER $CACHEDIR
        # Create a blank logfile owned by apt-proxy user
        touch $APTPROXY_LOGFILE
        chown $APTPROXY_USER:adm $APTPROXY_LOGFILE
        chmod 640 $APTPROXY_LOGFILE


        #if dpkg --compare-versions "$PREV"  lt-nl 1.9.36.4 && [ -r /etc/apt-proxy/apt-proxy-v2.conf ]; then
		# rename apt-proxy-v2.conf to apt-proxy.conf
	#	echo renaming config file...
        #fi
        ;;
    abort-upgrade|abort-remove|abort-deconfigure)
        ;;
    *)
        echo "postinst called with unknown argument \`$1'" >&2
        ;;
esac

#DEBHELPER#

exit 0
