#!/bin/sh
set -eu
# Restore the real CUPS transport before removing the guard files, including
# the updater's rollback to a package that predates network policies.
if [ "$1" = remove ] || { [ "$1" = upgrade ] && [ -n "${2:-}" ] && dpkg --compare-versions "$2" lt 0.3.18; }; then
  if [ -f /usr/lib/sikano-print/network/policy.py ]; then
    /usr/bin/python3 -I -B /usr/lib/sikano-print/network/policy.py --restore-all
  fi
fi
case "$1" in
  remove|upgrade|failed-upgrade|deconfigure)
    if [ -d /run/systemd/system ]; then systemctl stop sikano-print-network.service sikano-print-airprint.service sikano-print-bluetooth.service; fi
    ;;
esac
if [ "$1" = remove ] && [ -d /run/systemd/system ]; then
  systemctl stop sikano-print-updater.service sikano-print.service
  systemctl disable sikano-print-updater.service sikano-print.service sikano-print-network.service sikano-print-airprint.service sikano-print-bluetooth.service
fi
