systemd_units=(@_F_systemd_units@)

post_install()
{
	/usr/bin/getent group _ntp  2>&1 > /dev/null || /usr/sbin/groupadd -g 29 _ntp
    /usr/bin/getent passwd _ntp 2>&1 > /dev/null || /usr/sbin/useradd -u 29 -g 29 -s /sbin/nologin -c "OpenNTP daemon" -d /var/empty _ntp

	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()
{
	## that changed and INSTALL tells to do that
	/usr/bin/getent passwd _ntp  2>&1 > /dev/null && /usr/sbin/usermod -d /var/empty _ntp
	rm -rf /var/empty/ntpd
	systemctl daemon-reload >/dev/null 2>&1
}

pre_remove()
{
	/usr/bin/getent passwd _ntp  2>&1 > /dev/null && /usr/sbin/userdel _ntp >/dev/null 2>&1
	/usr/bin/getent group _ntp 2>&1 > /dev/null && /usr/sbin/groupdel _ntp >/dev/null 2>&1

	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 $*
