#!/bin/sh
# postinst script for radicale

set -e

NAME=radicale
ACCOUNTNAME=$NAME
DAEMON_UID=$ACCOUNTNAME
DAEMON_GID=$ACCOUNTNAME
CALDIR=/var/lib/$NAME
ACCOUNTHOME=$CALDIR
GECOS="Radicale CalDAV server"

case "$1" in
  configure)
	if ! getent passwd $ACCOUNTNAME >/dev/null 2>&1; then
		adduser --system --home $ACCOUNTHOME --no-create-home \
			--gecos "$GECOS" --group --disabled-password \
			--quiet $ACCOUNTNAME
	fi
	;;
esac

# Automatically added by dh_installinit/13.11.3
if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then
	if [ -z "${DPKG_ROOT:-}" ] && [ -x "/etc/init.d/radicale" ]; then
		update-rc.d radicale defaults-disabled >/dev/null
		if [ -n "$2" ]; then
			_dh_action=restart
		else
			_dh_action=start
		fi
		invoke-rc.d --skip-systemd-native radicale $_dh_action || exit 1
	fi
fi
# End automatically added section
# Automatically added by dh_installsystemd/13.11.3
if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then
	if deb-systemd-helper debian-installed 'radicale.service'; then
		# The following line should be removed in trixie or trixie+1
		deb-systemd-helper unmask 'radicale.service' >/dev/null || true

		if deb-systemd-helper --quiet was-enabled 'radicale.service'; then
			# Create new symlinks, if any.
			deb-systemd-helper enable 'radicale.service' >/dev/null || true
		fi
	fi

	# Update the statefile to add new symlinks (if any), which need to be cleaned
	# up on purge. Also remove old symlinks.
	deb-systemd-helper update-state 'radicale.service' >/dev/null || true
fi
# End automatically added section

