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

timezone_utc() {
   if [ -f /etc/noutc ] || [ -f /usr/local/etc/noutc ]; then
      echo "File /etc/noutc / /usr/local/etc/noutc exists. Not setting timezone to UTC."
      return 0
   fi

   LC_ALL=C
   LANG=C
   unset TZ
   umask 022

   AREA="Etc"
   ZONE="UTC"

   echo "$AREA/$ZONE" > "/etc/timezone"
   cp -f "/usr/share/zoneinfo/$AREA/$ZONE" "/etc/localtime.dpkg-new" && \
      mv -f "/etc/localtime.dpkg-new" "/etc/localtime"

   echo
   echo "Current default time zone: '$AREA/$ZONE'"

   TZBase=$(LC_ALL=C TZ=UTC0 date)
   UTdate=$(LC_ALL=C TZ=UTC0 date -d "$TZBase")
   TZdate=$(unset TZ ; LC_ALL=C LANG=C date -d "$TZBase")
   echo "Local time is now:      $TZdate."
   echo "Universal Time is now:  $UTdate."
   echo
}

timezone_utc

## Make systemd drop-in config snippets take effect.
if [ -d /run/systemd/system ]; then
        systemctl --system daemon-reload >/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
