function post_install() {
#!/bin/sh

# Use separate commands to enable and start the daemon on systems with
# systemd, OpenRC and SysVinit.
if command -v systemctl >/dev/null 2>&1; then
    # systemd based start
    systemctl daemon-reload
    systemctl enable littlesnitch.service
    systemctl restart littlesnitch.service
elif command -v rc-service >/dev/null 2>&1; then
    # OpenRC based start
    rc-update add littlesnitch default
    rc-service littlesnitch start
elif command -v update-rc.d >/dev/null 2>&1; then
    # SysVinit based start
    update-rc.d littlesnitch defaults
    service littlesnitch start
fi

# If anything above fails, report success anyway. the installation as such
# has succeeded and we should not fail for during atomic install just
# because the daemon did not start immediately.
exit 0

}

function pre_remove() {
#!/bin/sh

# $1 = "remove" (deb) or "0" (rpm) on actual removal
# $1 = "upgrade" (deb) or "1" (rpm) on upgrade -- do nothing, avoid a monitoring gap
if [ "$1" = "remove" ] || [ "$1" = "0" ]; then
    if command -v systemctl >/dev/null 2>&1; then
        # systemd
        systemctl disable --now littlesnitch.service
    elif command -v rc-service >/dev/null 2>&1; then
        # OpenRC
        rc-service littlesnitch stop
        rc-update del littlesnitch default
    elif command -v update-rc.d >/dev/null 2>&1; then
        # SysVinit
        service littlesnitch stop
        update-rc.d littlesnitch remove
    fi
fi

# Report success in any case. If the daemon did not terminate right now,
# the next reboot will fix the issue. If we fail here, an atomic install
# might roll back the entire operation, making it impossible to remove
# Little Snitch.
exit 0

}

