systemd_units=(@_F_systemd_units@)

post_install()
{
	[ -z "`grep '^postdrop::' /etc/group`" ] && \
		groupadd -g 75 postdrop >& /dev/null
	[ -z "`grep '^postfix::' /etc/group`" ] && \
		groupadd -g 73 postfix >& /dev/null
	[ -z "`grep '^postfix:' /etc/passwd`" ] && \
		useradd -u 73 -d /var/spool/postfix -g postfix postfix	
	chown postfix /var/spool/postfix/{active,bounce,corrupt,defer,deferred,flush,hold,incoming,private,public,trace,maildrop,saved}
	chgrp postdrop /var/spool/postfix/{public,maildrop,trace} /usr/bin/{postqueue,postdrop}
	chmod g+s /usr/bin/{postqueue,postdrop}

	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()
{
	chown postfix /var/spool/postfix/{active,bounce,corrupt,defer,deferred,flush,hold,incoming,private,public,trace,maildrop,saved}
	chgrp postdrop /var/spool/postfix/{public,maildrop,trace} /usr/bin/{postqueue,postdrop}
	chmod g+s /usr/bin/{postqueue,postdrop}

	systemctl daemon-reload >/dev/null 2>&1
}

pre_remove()
{
	userdel postfix &> /dev/null
	groupdel postfix &> /dev/null
	groupdel postdrop &> /dev/null

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