#!/bin/bash

## Copyright (C) 2012 - 2025 ENCRYPTED SUPPORT LLC <adrelanos@whonix.org>
## See the file COPYING for copying conditions.

if [ -f /usr/libexec/helper-scripts/pre.bsh ]; then
   source /usr/libexec/helper-scripts/pre.bsh
fi

set -e

true "
#####################################################################
## INFO: BEGIN: $DPKG_MAINTSCRIPT_PACKAGE $DPKG_MAINTSCRIPT_NAME $@
#####################################################################
"

## Make systemd drop-in config snippets take effect.
if [ -d /run/systemd/system ]; then
        systemctl --system daemon-reload >/dev/null || true
fi

case "$1" in
   configure)
      true "INFO: Configuring $DPKG_MAINTSCRIPT_PACKAGE..."

      ## force-reload Tor, if running.
      service_tor_status_exit_code="0"
      systemctl --no-pager --no-block status tor@default >/dev/null 2>&1 || { service_tor_status_exit_code="$?" ; true; };
      if [ "$service_tor_status_exit_code" = "0" ]; then
         systemctl --no-pager --no-block force-reload tor@default || true
      fi

      true "INFO: End configuring $DPKG_MAINTSCRIPT_PACKAGE."

      ;;

   *)
      ;;
esac

true "INFO: debhelper beginning here."

# Automatically added by dh_installdeb/13.24.2
dpkg-maintscript-helper rm_conffile /etc/tor/torrc.examples -- "$@"
dpkg-maintscript-helper rm_conffile /etc/torrc.d/torrc.examples -- "$@"
dpkg-maintscript-helper rm_conffile /etc/torrc.d/40_anon_connection_wizard.torrc -- "$@"
dpkg-maintscript-helper rm_conffile /etc/torrc.d/50_user.torrc -- "$@"
dpkg-maintscript-helper rm_conffile /etc/torrc.d/95_whonix.torrc -- "$@"
dpkg-maintscript-helper rm_conffile /etc/audit/rules.d/30_anon-gw-anonymizer-config.rules -- "$@"
# End automatically added section
# Automatically added by dh_installsystemd/13.24.2
if [ "$1" = remove ] && [ -d /run/systemd/system ] ; then
	systemctl --system daemon-reload >/dev/null || true
fi
# End automatically added section
# Automatically added by dh_installsystemd/13.24.2
if [ "$1" = "purge" ]; then
	if [ -x "/usr/bin/deb-systemd-helper" ]; then
		deb-systemd-helper purge 'anon-gw-anonymizer-config.service' >/dev/null || true
	fi
fi
# End automatically added section
# Automatically added by dh_apparmor/4.1.0-1
if [ "$1" = "purge" ] && ! [ -e "/etc/apparmor.d/usr.bin.obfsproxy" ] ; then
    rm -f "/etc/apparmor.d/disable/usr.bin.obfsproxy" || true
    rm -f "/etc/apparmor.d/force-complain/usr.bin.obfsproxy" || true
    rm -f "/etc/apparmor.d/local/usr.bin.obfsproxy" || true
    rm -f /var/cache/apparmor/*/"usr.bin.obfsproxy" || true
    rmdir /etc/apparmor.d/disable 2>/dev/null || true
    rmdir /etc/apparmor.d/local   2>/dev/null || true
    rmdir /etc/apparmor.d         2>/dev/null || true
fi
# End automatically added section
# Automatically added by dh_apparmor/4.1.0-1
if [ "$1" = "purge" ] && ! [ -e "/etc/apparmor.d/system_tor" ] ; then
    rm -f "/etc/apparmor.d/disable/system_tor" || true
    rm -f "/etc/apparmor.d/force-complain/system_tor" || true
    rm -f "/etc/apparmor.d/local/system_tor" || true
    rm -f /var/cache/apparmor/*/"system_tor" || true
    rmdir /etc/apparmor.d/disable 2>/dev/null || true
    rmdir /etc/apparmor.d/local   2>/dev/null || true
    rmdir /etc/apparmor.d         2>/dev/null || true
fi
# End automatically added section


true "INFO: Done with debhelper."

true "
#####################################################################
## INFO: END  : $DPKG_MAINTSCRIPT_PACKAGE $DPKG_MAINTSCRIPT_NAME $@
#####################################################################
"

## Explicitly "exit 0", so eventually trapped errors can be ignored.
exit 0
