Skip to content

Commit

Permalink
Re-design config_timezone for TZ + localtime handling + drop config_time
Browse files Browse the repository at this point in the history
The file /etc/default/rcS no longer exists, and also /etc/adjtime
doesn't necessarily exist any longer.

Instead, even /etc/timezone is gone nowadays, see e.g.
systemd/systemd#35413

We don't need to support the bootoption "utc" any longer, as this is the
default nowadays.

Don't invoke hwlock at all anymore, instead set /etc/localtime to the
timezone requested via boot option tz=..., if set.  Accordingly drop
Depends on util-linux-extra, which we no longer need now with the
hwclock removal. And use `timedatectl set-local-rtc 1` as interface for
/etc/adjtime with its localtime handling.

Drop $CONFIG_TIME + config_time with this cleanup and handle all of the
remaining timezone handling within $CONFIG_TIMEZONE + config_timezone.

Thanks to Chris and Darsha for the debugging session, and clarifying this.
  • Loading branch information
mika committed Jan 30, 2025
1 parent 72ec5d5 commit e96da70
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 75 deletions.
3 changes: 1 addition & 2 deletions autoconfig
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ CONFIG_SERVICES='yes' # check for services to run, provided via bootpara
CONFIG_SSH='yes' # check for bootparam ssh
CONFIG_SWRAID='yes' # check for software raid devices [only in live-mode]
CONFIG_TESTCD='yes' # CD checker
CONFIG_TIME='yes' # set clock, check for bootparam utc/gmt [only in live-mode]
CONFIG_TIMEZONE='yes' # get bootparam 'tz' and set it as /etc/localtime [only in live-mode]
CONFIG_TIMEZONE='yes' # get bootparam 'tz' + bootoption 'localtime'
CONFIG_VIRTUALBOX_SHARED_FOLDERS='yes' # set up shared folders in VirtualBox environment
CONFIG_VIRTUALBOX_SETUP='yes' # set up VirtuaBox service (iff present)
CONFIG_VNC='yes' # check for bootparam vnc
Expand Down
93 changes: 23 additions & 70 deletions autoconfig.functions
Original file line number Diff line number Diff line change
Expand Up @@ -299,54 +299,6 @@ config_userlocal() {
}
# }}}

# {{{ Set clock (Local time is more often used than GMT, so it is default)
config_time(){
# don't touch the files if running from harddisk:
if [ -z "$INSTALLED" ]; then
# The default hardware clock timezone is stated as representing local time.
UTC="--localtime"

if [ -f /etc/default/rcS ] ; then
grep -q "^UTC=" /etc/default/rcS || echo "UTC=no" >> /etc/default/rcS
checkbootparam 'utc' >>$DEBUG 2>&1 && sed -i "s|^UTC=.*$|UTC=yes|" /etc/default/rcS
checkbootparam 'gmt' >>$DEBUG 2>&1 && sed -i "s|^UTC=.*$|UTC=yes|" /etc/default/rcS
checkbootparam 'localtime' >>$DEBUG 2>&1 && sed -i "s|^UTC=.*$|UTC=no|" /etc/default/rcS
grep -q -i "^UTC=yes" /etc/default/rcS && UTC="-u"
# recent initscripts package versions don't ship /etc/default/rcS anymore, instead rely on /etc/adjtime
elif [ -f /etc/adjtime ] ; then
checkbootparam 'utc' >>$DEBUG 2>&1 && sed -i "s/^LOCAL/UTC/" /etc/adjtime
checkbootparam 'gmt' >>$DEBUG 2>&1 && sed -i "s/^LOCAL/UTC/" /etc/adjtime
checkbootparam 'localtime' >>$DEBUG 2>&1 && sed -i "s/^UTC$/LOCAL/" /etc/adjtime
grep -q "^UTC$" /etc/adjtime && UTC="-u"
fi

# hwclock uses the TZ variable
KTZ="$(getbootparam 'tz' 2>>$DEBUG)"
[ -z "$KTZ" ] && [ -r /etc/timezone ] && KTZ=$(< /etc/timezone)
if [ ! -f "/usr/share/zoneinfo/$KTZ" ] ; then
ewarn "Warning: unknown timezone $KTZ" ; eend 1
KTZ="UTC"
ewarn "Falling back to timezone $KTZ" ; eend 0
fi

if ! [ -r /dev/rtc ] ; then
ewarn "Warning: realtime clock not available, trying to execute hwclock anyway." ; eend 0
fi

ERROR=$(TZ="$KTZ" hwclock $UTC -s 2>&1 | head -1) ; RC=$?
if [ -n "$ERROR" ] ; then
eindent
ERROR=$(TZ="$KTZ" hwclock $UTC -s --directisa 2>&1 | head -1)
if [ -n "$ERROR" ] ; then
eerror "Problem running hwclock: $ERROR" ; eend 1
fi
eoutdent
fi

fi
}
# }}}

# {{{ print kernel info
config_kernel(){
if $VIRTUAL && [ -n "$VIRTUAL_ENV" ] ; then
Expand Down Expand Up @@ -398,29 +350,30 @@ config_secureboot(){
}
# }}}

# {{{ timezone
# {{{ Configure timezone when using boot option tz, or RTC for boot option localtime
config_timezone(){
# don't touch the files if running from harddisk:
if [ -z "$INSTALLED" ]; then
KTZ="$(getbootparam 'tz' 2>>$DEBUG)"
if [ -n "$KTZ" ] ; then
if [ ! -f "/usr/share/zoneinfo/$KTZ" ]
then
ewarn "Warning: unknown timezone $KTZ"; eend 0
else
einfo "Setting timezone."
# update debconf
area=$(echo $KTZ | cut -d '/' -f1)
zone=$(echo $KTZ | cut -d '/' -f2)
echo "tzdata tzdata/Areas select $area" | debconf-set-selections
echo "tzdata tzdata/Zones/$area select $zone" | debconf-set-selections
# update files
echo $KTZ > /etc/timezone
rm -f /etc/localtime
cp "/usr/share/zoneinfo/$KTZ" /etc/localtime ; eend $?
fi
fi
fi
local timezone
timezone="$(getbootparam 'tz' 2>>$DEBUG)"

if checkbootparam 'localtime' ; then
einfo "Bootoption localtime is set, configuring RTC to local time."
timedatectl set-local-rtc 1
eend $?
fi

# nothing further to do for us if boot option isn't set
if [ -z "${timezone:-}" ] ; then
return 0
fi

if ! [ -e "/usr/share/zoneinfo/${timezone}" ] ; then
ewarn "Warning: unknown timezone ${timezone}, falling back to UTC" ; eend 1
timezone="UTC"
fi

einfo "Setting timezone to ${timezone}"
ln -sf /usr/share/zoneinfo/"${timezone}" /etc/localtime
eend $?
}
# }}}

Expand Down
1 change: 0 additions & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ Depends:
kbd | console-utilities,
rsync,
udev,
util-linux-extra | util-linux (<= 2.38-1),
zsh,
${misc:Depends},
${shlibs:Depends},
Expand Down
2 changes: 0 additions & 2 deletions grml-autoconfig
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ checkvalue $CONFIG_LOG && config_log

checkvalue $CONFIG_HOSTNAME && config_hostname

checkvalue $CONFIG_TIME && config_time

checkvalue $CONFIG_KERNEL && config_kernel

checkvalue $CONFIG_SECUREBOOT && config_secureboot
Expand Down

0 comments on commit e96da70

Please sign in to comment.