#!/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

if [ "$1" = "purge" ]; then
   ## delete sclockadj only when package is removed using apt-get with purge option
   ## otherwise during `release-upgrade` postrm script might run,
   ## delete sclockadj while sdwdate is still running
   rm --force /usr/libexec/sdwdate/sclockadj

   rm --force "/var/log/sdwdate.log"
   rm -r --force "/var/cache/sdwdate"
fi

# Automatically added by dh_installdeb/13.24.2
dpkg-maintscript-helper rm_conffile /etc/sdwdate.d/30_default -- "$@"
dpkg-maintscript-helper rm_conffile /etc/sdwdate.d/30_sdwdate_default -- "$@"
dpkg-maintscript-helper rm_conffile /etc/sdwdate.d/31_anon_dist_con_check_plugin -- "$@"
dpkg-maintscript-helper rm_conffile /etc/sdwdate.d/31_anon_dist_stream_isolation_plugin -- "$@"
dpkg-maintscript-helper rm_conffile /etc/apparmor.d/abstractions/sdwdate -- "$@"
dpkg-maintscript-helper rm_conffile /etc/apparmor.d/usr.lib.sdwdate.url_to_unixtime -- "$@"
# 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 'sdwdate-start-anondate-set-file-watcher.service' 'sdwdate.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.url_to_unixtime" ] ; then
    rm -f "/etc/apparmor.d/disable/usr.bin.url_to_unixtime" || true
    rm -f "/etc/apparmor.d/force-complain/usr.bin.url_to_unixtime" || true
    rm -f "/etc/apparmor.d/local/usr.bin.url_to_unixtime" || true
    rm -f /var/cache/apparmor/*/"usr.bin.url_to_unixtime" || 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/usr.bin.sdwdate" ] ; then
    rm -f "/etc/apparmor.d/disable/usr.bin.sdwdate" || true
    rm -f "/etc/apparmor.d/force-complain/usr.bin.sdwdate" || true
    rm -f "/etc/apparmor.d/local/usr.bin.sdwdate" || true
    rm -f /var/cache/apparmor/*/"usr.bin.sdwdate" || 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

