]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: support debian/ubuntu specific timezone config file
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 14 Jun 2022 00:02:00 +0000 (09:02 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 14 Jun 2022 11:52:44 +0000 (20:52 +0900)
test/units/testsuite-45.sh

index 2069d2437fdac484933761da9aefabe2fb94f16f..d0f9dd9461d62d71c7e2746e5716b30909ab6fa6 100755 (executable)
@@ -7,9 +7,24 @@ set -o pipefail
 # shellcheck source=test/units/assert.sh
 . "$(dirname "$0")"/assert.sh
 
+restore_timezone() {
+    if [[ -f /tmp/timezone.bak ]]; then
+        mv /tmp/timezone.bak /etc/timezone
+    else
+        rm -f /etc/timezone
+    fi
+}
+
 test_timezone() {
     local ORIG_TZ=
 
+    # Debian/Ubuntu specific file
+    if [[ -f /etc/timezone ]]; then
+        mv /etc/timezone /tmp/timezone.bak
+    fi
+
+    trap restore_timezone EXIT
+
     if [[ -L /etc/localtime ]]; then
         ORIG_TZ=$(readlink /etc/localtime | sed 's#^.*zoneinfo/##')
         echo "original tz: $ORIG_TZ"
@@ -21,13 +36,22 @@ test_timezone() {
     echo 'change timezone'
     assert_eq "$(timedatectl --no-pager set-timezone Europe/Kiev 2>&1)" ""
     assert_eq "$(readlink /etc/localtime | sed 's#^.*zoneinfo/##')" "Europe/Kiev"
+    if [[ -f /etc/timezone ]]; then
+        assert_eq "$(cat /etc/timezone)" "Europe/Kiev"
+    fi
     assert_in "Time zone: Europe/Kiev \(EEST, \+0[0-9]00\)" "$(timedatectl)"
 
     if [[ -n "$ORIG_TZ" ]]; then
         echo 'reset timezone to original'
         assert_eq "$(timedatectl set-timezone "$ORIG_TZ" 2>&1)" ""
         assert_eq "$(readlink /etc/localtime | sed 's#^.*zoneinfo/##')" "$ORIG_TZ"
+        if [[ -f /etc/timezone ]]; then
+            assert_eq "$(cat /etc/timezone)" "$ORIG_TZ"
+        fi
     fi
+
+    restore_timezone
+    trap - EXIT
 }
 
 restore_adjtime() {