#!/bin/sh
set -e

. /usr/share/debconf/confmodule

case "$1" in
    configure)
        # Create camper user and group
        if ! getent group camper >/dev/null; then
            addgroup --system --quiet camper
        fi
        if ! getent passwd camper >/dev/null; then
            adduser --quiet \
                    --system \
                    --disabled-login \
                    --no-create-home \
                    --shell /bin/bash \
                    --ingroup camper \
                    --home /usr/share/camper \
                    --gecos "Camper Daemon" \
                    camper
        fi

        # Make sure log directory has correct permissions set
        dpkg-statoverride --list "/var/log/camper" >/dev/null || \
            dpkg-statoverride --add --force --quiet --update camper adm 0750 /var/log/camper
        ;;

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

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

#DEBHELPER#

exit 0