systemd_units=(@_F_systemd_units@)

post_install()
{
	lang=`echo $LANG|cut -d _ -f 1`

	[ "$lang" == "de" ] && lang="ge"

	[ "$lang" == "pt" -a "`echo $LANG|cut -d . -f 1|cut -d @ -f 1`" == "pt_BR" ] \
	&& lang="pt-br"

	if [ ! -e /etc/p3scan/p3scan.mail -a -e /etc/p3scan/p3scan-$lang.mail ] ; then
		cp /etc/p3scan/p3scan-$lang.mail /etc/p3scan/p3scan.mail
	else
		cp /etc/p3scan/p3scan-en.mail /etc/p3scan/p3scan.mail
	fi

	local unit
	local op

	for i in ${systemd_units[@]}; do
		unit=$(echo $i | cut -f 1 -d '=')
		op=$(echo $i | cut -f 2 -d '=')
		if echo $op | grep -q 'e'; then
			systemctl enable $unit.service >/dev/null 2>&1
		fi
		if echo $op | grep -q 's'; then
			systemctl start $unit.service >/dev/null 2>&1
		fi
	done
}

post_upgrade()
{
	systemctl daemon-reload >/dev/null 2>&1
}

pre_remove()
{
	local unit

	for i in ${systemd_units[@]}; do
		unit=$(echo $i | cut -f 1 -d '=')
		systemctl --no-reload disable $unit.service >/dev/null 2>&1
		systemctl stop $unit.service >/dev/null 2>&1
	done
}

post_remove()
{
	systemctl daemon-reload >/dev/null 2>&1
}

op=$1
shift
$op $*
