#!/bin/sh
# Housecarl: runs before the package's files are removed (also on upgrades).
set -e

# On removal (not on upgrade) stop housecarld and the backup timer and remove
# the boot-time links (postrm deals with the timer's). The ruleset in force
# stays until the next boot; then the machine has no Housecarl table.
if [ "$1" = remove ] && [ -d /run/systemd/system ]; then
	systemctl stop housecarl.service housecarl-backup.timer housecarl-backup.service 2>/dev/null || true
	systemctl disable housecarl.service housecarl-ruleset.service 2>/dev/null || true
	if ! command -v deb-systemd-helper >/dev/null 2>&1; then
		systemctl disable housecarl-backup.timer 2>/dev/null || true
	fi
fi

exit 0
