summaryrefslogtreecommitdiffstats
path: root/modules.d
diff options
context:
space:
mode:
authorSimon Rettberg2025-04-14 15:51:32 +0200
committerSimon Rettberg2025-04-14 15:51:32 +0200
commit01d89e850419fb43763e0c75034f04b1b7170eff (patch)
treef91f4913ee6f0b9fafac93db792837b36c3102ca /modules.d
parent[busybox] Enable swapon (diff)
downloadsystemd-init-01d89e850419fb43763e0c75034f04b1b7170eff.tar.gz
systemd-init-01d89e850419fb43763e0c75034f04b1b7170eff.tar.xz
systemd-init-01d89e850419fb43763e0c75034f04b1b7170eff.zip
[slx-clock] Try harder to make sure date understands hwclock output
Diffstat (limited to 'modules.d')
-rw-r--r--modules.d/busybox/openslx.config2
-rwxr-xr-xmodules.d/slx-clock/hooks/s3-ntp-sync.sh43
2 files changed, 41 insertions, 4 deletions
diff --git a/modules.d/busybox/openslx.config b/modules.d/busybox/openslx.config
index db64e140..ad3730c8 100644
--- a/modules.d/busybox/openslx.config
+++ b/modules.d/busybox/openslx.config
@@ -115,7 +115,7 @@ CONFIG_FEATURE_TAB_COMPLETION=y
CONFIG_FEATURE_EDITING_FANCY_PROMPT=y
CONFIG_FEATURE_EDITING_WINCH=y
# CONFIG_FEATURE_EDITING_ASK_TERMINAL is not set
-CONFIG_LOCALE_SUPPORT=y
+# CONFIG_LOCALE_SUPPORT is not set
CONFIG_UNICODE_SUPPORT=y
# CONFIG_UNICODE_USING_LOCALE is not set
CONFIG_FEATURE_CHECK_UNICODE_IN_ENV=y
diff --git a/modules.d/slx-clock/hooks/s3-ntp-sync.sh b/modules.d/slx-clock/hooks/s3-ntp-sync.sh
index c4be6161..75853932 100755
--- a/modules.d/slx-clock/hooks/s3-ntp-sync.sh
+++ b/modules.d/slx-clock/hooks/s3-ntp-sync.sh
@@ -1,8 +1,26 @@
-#!/bin/ash
+#!/bin/bash
# Sync time via network
. /etc/openslx
+month_num() {
+ case "$1" in
+ Jan) echo 01 ;;
+ Feb) echo 02 ;;
+ Mar) echo 03 ;;
+ Apr) echo 04 ;;
+ May) echo 05 ;;
+ Jun) echo 06 ;;
+ Jul) echo 07 ;;
+ Aug) echo 08 ;;
+ Sep) echo 09 ;;
+ Oct) echo 10 ;;
+ Nov) echo 11 ;;
+ Dec) echo 12 ;;
+ *) echo "INVALID MONTH NAME '$1'" >&2 ;;
+ esac
+}
+
adjust_rtc() {
if [ "$SLX_BIOS_CLOCK" = "local" ]; then
usleep 100000
@@ -11,10 +29,29 @@ adjust_rtc() {
usleep 100000
hwclock -u -w || echo "... but could not set BIOS clock to UTC"
else
- local rtc sys diff arg
+ local rtc sys diff arg re out mon
for arg in "-l" "-u"; do
- rtc=$( date -d "$( LC_ALL=C hwclock "$arg" | sed -r 's/ *[0-9.]+ seconds$//' )" +%s )
+ rtc=
+ out=$( LC_ALL=C hwclock "$arg" )
+ re="([A-Za-z]{3})\\s+([0-9]{1,2})\\s+([0-9:]{8})\\s+([0-9]{4})"
+ if [[ $out =~ $re ]]; then
+ mon=$( month_num "${BASH_REMATCH[1]}" )
+ [ -n "$mon" ] && rtc="${BASH_REMATCH[4]}-${mon}-${BASH_REMATCH[2]} ${BASH_REMATCH[3]}"
+ fi
+ re="[0-9-]{10}\\s+[0-9:]{8}"
+ if [[ $out =~ $re ]]; then
+ rtc="${BASH_REMATCH[0]}"
+ fi
+ if [ -z "$rtc" ]; then
+ echo "Error parsing hwclock output"
+ break
+ fi
+ rtc=$( date -d "$rtc" +%s )
sys=$( date +%s )
+ if [ -z "$rtc" ] || [ -z "$sys" ]; then
+ echo "Error converting date/time to unix timestamp"
+ break
+ fi
diff=$(( sys - rtc ))
if [ "$diff" -gt -900 ] && [ "$diff" -lt 900 ]; then
# Less than 15 minutes off, assume it's the correct mode