Files
checkbot/deploy/lib/timezone.sh
T
patrickandClaude Sonnet 5.5 d2e2f829ad
test / pytest (3.11) (push) Waiting to run
test / pytest (3.13) (push) Waiting to run
feat: test base (logging with secret masking, timezone, Gitea workflow) and roadmap
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-06 01:24:24 +01:00

47 lines
1.6 KiB
Bash

#!/usr/bin/env bash
# Systemzeitzone setzen (wird von setup-lxc.sh gesourced). Setzt common.sh voraus.
ZONEINFO_DIR=/usr/share/zoneinfo
TZ_RE='^[A-Za-z0-9_+-]+(/[A-Za-z0-9_+-]+)*$'
LOCALTIME_FILE=/etc/localtime
TIMEZONE_FILE=/etc/timezone
validate_timezone_name() {
[[ $1 =~ $TZ_RE ]] || die "Ungültiger Zeitzonenname: '$1' (Beispiel: Europe/Berlin)"
}
current_timezone() {
local tz="" target=""
if command -v timedatectl >/dev/null 2>&1; then
tz=$(timedatectl show -p Timezone --value 2>/dev/null) || tz=""
fi
if [[ -z $tz || $tz == n/a ]]; then
target=$(readlink -f "$LOCALTIME_FILE" 2>/dev/null) || target=""
tz=${target#"$ZONEINFO_DIR"/}
[[ $tz != "$target" ]] || tz=""
fi
printf '%s' "$tz"
}
set_timezone_files() {
ln -sfn "$ZONEINFO_DIR/$1" "$LOCALTIME_FILE" && printf '%s\n' "$1" > "$TIMEZONE_FILE"
}
# In unprivilegierten LXCs fehlt oft ein nutzbares timedatectl (kein D-Bus); dann Dateien direkt schreiben, sonst nur warnen.
ensure_timezone() {
local tz=$1
[[ -f $ZONEINFO_DIR/$tz ]] || die "Zeitzone '$tz' fehlt in $ZONEINFO_DIR (Paket tzdata?)."
if [[ $(current_timezone) == "$tz" ]]; then
log "Zeitzone ist bereits $tz."
return 0
fi
if command -v timedatectl >/dev/null 2>&1 && timedatectl set-timezone "$tz" >/dev/null 2>&1; then
log "Zeitzone auf $tz gesetzt."
elif set_timezone_files "$tz" 2>/dev/null; then
log "Zeitzone auf $tz gesetzt (über $LOCALTIME_FILE)."
else
warn "Zeitzone konnte nicht auf $tz gesetzt werden (unprivilegierter LXC?). Zeitzone am Host/LXC-Konfiguration einstellen."
fi
return 0
}