#!/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 $@
#####################################################################
"

configure_function() {
   adduser --quiet \
           --system \
           --disabled-password \
           --home /var/lib/tor \
           --no-create-home \
           --shell /bin/false \
           --group \
           debian-tor >/dev/null 2>&1 || true

   addgroup --quiet debian-tor 2>/dev/null || true

#### meta start
#### project Whonix
#### category networking
#### workstation_only yes
#### description
## <code>/etc/X11/Xsession.d/</code> hook to <code>source</code>
## <code>/usr/libexec/anon-ws-disable-stacked-tor/torbrowser.sh</code>

   ## Add account "user" to the group "debian-tor", so account "user" can access Tor's control port.
   ## Account "user" already exists thanks to the dist-base-files package.
   adduser --quiet user debian-tor

#### meta end
}

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

      configure_function

      true "INFO: End configuring $DPKG_MAINTSCRIPT_PACKAGE."

      ;;

   *)
      ;;
esac

## workaround for 'dh_installinit should run systemd-tmpfiles if a
## /usr/lib/tmpfiles.d/ snippet gets shipped for systemd-only packages
## also' - http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=795519
# In case this system is running systemd, we need to ensure that all
# necessary tmpfiles (if any) are created before starting.
if [ -d /run/systemd/system ] ; then
	systemd-tmpfiles --create /usr/lib/tmpfiles.d/anon-ws-disable-stacked-tor.conf >/dev/null || true
fi

true "INFO: debhelper beginning here."

#DEBHELPER#

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
