post_install() {
	# /etc/fetchmail must be owned by fetchmail for service to work.
	echo "If you run fetchmail as a service and not a cron job"
	echo "then 'chown fetchmail /etc/fetchmailrc'"

	if ! getent group fetchmail &>/dev/null; then
		groupadd -r fetchmail >/dev/null
	fi
	if ! getent passwd fetchmail &>/dev/null; then
		useradd -r -u 90 -g fetchmail -d /dev/null -s /bin/nologin -c "Fetchmail" fetchmail >/dev/null
	fi
	fetchmail_shell=$(getent passwd fetchmail | cut -d: -f7)
	if [ "$fetchmail_shell" != '/bin/nologin' ]; then
		chsh -s /bin/nologin fetchmail &>/dev/null
	fi
}

post_upgrade() {
	if ! getent group fetchmail &>/dev/null; then
		groupadd -r fetchmail >/dev/null
	fi
	if ! getent passwd fetchmail &>/dev/null; then
		useradd -r -u 90 -g fetchmail -d /dev/null -s /bin/nologin -c "Fetchmail" fetchmail >/dev/null
	fi

	if [ "$(vercmp $2 6.3.19-3)" -lt 0 ] ; then
		usermod -d '/var/lib/fetchmail' -s /bin/nologin fetchmail
	fi

	fetchmail_shell=$(getent passwd fetchmail | cut -d: -f7)
	if [ "$fetchmail_shell" != '/bin/nologin' ]; then
		chsh -s /bin/nologin fetchmail &>/dev/null
	fi
}

pre_remove() {
	if getent passwd fetchmail &>/dev/null; then
		userdel fetchmail >/dev/null
	fi
	if getent group fetchmail &>/dev/null; then
		groupdel fetchmail >/dev/null
	fi
}
