#!/bin/sh

set -e

if [ "$1" = "configure" ]; then
    if ! test -d /vol/dls_data; then
	addgroup --system --quiet dls
	adduser --system --quiet --ingroup dls --no-create-home dls
	mkdir -p /vol/dls_data
	mkdir -p /vol/dls_data/spool
	echo 100 > /vol/dls_data/id_sequence
	chown -R dls:dls /vol/dls_data
	chmod g+w /vol/dls_data
    fi
    chown dls /usr/bin/dls_ctl
    chmod u+s /usr/bin/dls_ctl
    if ! test -f /etc/cron.d/dls_quota; then
	cat <<'EOF' > /etc/cron.d/dls_quota
DOQUOTA=/usr/bin/dls_quota
54 02 * * * dls test -x $DOQUOTA && $DOQUOTA -i 0 -d /vol/dls_data
EOF
    fi
    /usr/bin/update-mime-database /usr/share/mime
    /usr/bin/update-desktop-database
fi

installinit_error() {
	exit $?
}

#DEBHELPER#
