#!/bin/sh
set -e

# summary of how this script can be called:
#        * <postinst> `configure' <most-recently-configured-version>
#        * <old-postinst> `abort-upgrade' <new version>
#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
#          <new-version>
#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
#          <failed-install-package> <version> `removing'
#          <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package
#

case "$1" in
	configure)
		[ -f /etc/psd.conf ] && . /etc/psd.conf
		if [ -z "$USERS" ]; then
			# empty var means fresh install or user did not setup
			echo '--------------------------------------------------------------------------'
			echo '  Define which users will make use of the sync in /etc/psd.conf'
			echo '  Read the manpage before use or see the wiki page'
			echo '  https://wiki.archlinux.org/index.php/Profile-sync-daemon'
			echo
			echo '  ALWAYS backup your profiles data before using utils like psd!'
			echo '--------------------------------------------------------------------------'
		else
			/bin/true
		fi
		;;
	abort-upgrade|abort-remove|abort-deconfigure)
		/bin/true
		;;
	*)
		echo "postinst called with unknown argument \`$1'" >&2
		exit 1
		;;
esac

systemctl enable psd >/dev/null 2>&1

exit 0
