mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-01-11 02:11:01 +01:00
Timedatectl alternative
This commit is contained in:
@@ -1,16 +1,27 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Function to show the current timezone
|
||||
# Function to show the current timezone, with two alternative methods
|
||||
show_timezone() {
|
||||
current_timezone=$(date +%Z)
|
||||
echo "Current timezone: $current_timezone"
|
||||
# Check if the /etc/timezone file exists
|
||||
if [ -f /etc/timezone ]; then
|
||||
timezone=$(cat /etc/timezone)
|
||||
elif [ -f /etc/localtime ]; then
|
||||
timezone=$(readlink /etc/localtime)
|
||||
timezone=${timezone/\/usr\/share\/zoneinfo\//}
|
||||
else
|
||||
timezone="Cannot determine timezone."
|
||||
fi
|
||||
echo "$timezone"
|
||||
}
|
||||
|
||||
# Function to set the timezone
|
||||
set_timezone() {
|
||||
new_timezone="$1"
|
||||
sudo timedatectl set-timezone "$new_timezone"
|
||||
echo "Timezone set to: $new_timezone"
|
||||
echo "$new_timezone" | sudo tee /etc/timezone >/dev/null
|
||||
sudo ln -sf /usr/share/zoneinfo/"$new_timezone" /etc/localtime
|
||||
if [ -f /etc/environment ]; then sudo sed -i "/TZ/c\TZ=$new_timezone" /etc/environment; fi
|
||||
if [ -d /var/run/s6/container_environment ]; then sudo echo "$new_timezone" > /var/run/s6/container_environment/TZ; fi
|
||||
echo "$new_timezone"
|
||||
}
|
||||
|
||||
# Main script
|
||||
@@ -18,11 +29,12 @@ case "$1" in
|
||||
"set-ntp")
|
||||
case "$2" in
|
||||
"false")
|
||||
sudo timedatectl set-ntp false
|
||||
sudo systemctl disable systemd-timesyncd
|
||||
echo "NTP disabled"
|
||||
;;
|
||||
"true")
|
||||
sudo timedatectl set-ntp true
|
||||
sudo systemctl enable systemd-timesyncd
|
||||
sudo systemctl start systemd-timesyncd
|
||||
echo "NTP enabled"
|
||||
;;
|
||||
*)
|
||||
|
||||
Reference in New Issue
Block a user