#!/bin/bash
# Filename:      ${GRML_FAI_CONFIG}/scripts/GRMLBASE/18-timesetup
# Purpose:       apply default time and timezone settings
# Authors:       (c) Thomas Lehmann <thomas.lehmann@kvt.de>
# Bug-Reports:   send to author and see http://grml.org/bugs/
# License:       This file is licensed under the GPL v2 or any later version.
###############################################################################

set -u
set -e

# FAI sets $target, but shellcheck does not know that.
target=${target:?}

# default timezone settings
if [ -n "$TIMEZONE" ] ; then
   echo "Setting default timezone to $TIMEZONE"
   # update debconf
   area=$(echo "$TIMEZONE" | cut -d '/' -f1)
   zone=$(echo "$TIMEZONE" | cut -d '/' -f2)
   echo "tzdata tzdata/Areas       select $area" | $ROOTCMD debconf-set-selections
   echo "tzdata tzdata/Zones/$area select $zone" | $ROOTCMD debconf-set-selections
   # update files
   if [ -e "$target"/etc/timezone ] ; then
      # only for tzdata before 2024b-6 (Debian trixie).
      echo "$TIMEZONE" > "$target"/etc/timezone
   fi
   chroot "$target" ln -sf /usr/share/zoneinfo/"$TIMEZONE" /etc/localtime
fi

## END OF FILE ################################################################
# vim:ft=sh expandtab ai tw=80 tabstop=4 shiftwidth=2
