#!/bin/bash

## Copyright (C) 2014 - 2015 Jason Mehring <nrgaway@gmail.com>
## Copyright (C) 2012 - 2025 ENCRYPTED SUPPORT LLC <adrelanos@whonix.org>
## See the file COPYING for copying conditions.

set -e

case "${1}" in
    configure)
        adduser --home /run/updatesproxycheck --no-create-home --quiet --system --group --shell /bin/false "updatesproxycheck" || true
        ;;

    abort-upgrade|abort-remove|abort-deconfigure)
        exit 0
        ;;

    triggered)
        for trigger in ${2}; do
            case "${trigger}" in

                ## Replace IP addresses
                /usr/share/whonix-gw-network-conf/network_internal_ip.txt | \
                /etc/resolv.conf | \
                /etc/resolv.conf.anondist | \
                /etc/resolv.conf.whonix | \
                /etc/rinetd.conf.anondist | \
                /etc/tor/torrc | \
                /usr/local/etc/torrc.d/50_user.conf | \
                /usr/share/anon-gw-anonymizer-config/torrc.examples | \
                /home/user/.torchat/torchat.ini | \
                /home/user/.xchat2/xchat.conf | \
                /home/user/.config/hexchat/hexchat.conf | \
                /usr/lib/leaktest-workstation/simple_ping.py | \
                /usr/share/anon-apps-config/kioslaverc | \
                /usr/share/anon-torchat/.torchat/torchat.ini | \
                /usr/share/tor/tor-service-defaults-torrc.anondist.base)
                    ## Do not break in case qubesdb-vm is also upgraded and not running.
                    ## https://github.com/QubesOS/qubes-issues/issues/2497
                    /usr/lib/qubes-whonix/replace-ips || true
                    ;;

                *)
                    echo "postinst called with unknown trigger \`${2}'" >&2
                    exit 1
                    ;;
            esac
        done
        exit 0
        ;;

    *)
        echo "postinst called with unknown argument \`${1}'" >&2
        exit 1
        ;;
esac

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

#DEBHELPER#

exit 0
