diff --git a/general/overlay/etc/init.d/rcS b/general/overlay/etc/init.d/rcS index 12d3a003..d9ae88ea 100755 --- a/general/overlay/etc/init.d/rcS +++ b/general/overlay/etc/init.d/rcS @@ -1,6 +1,7 @@ #!/bin/sh # Setting the TimeZone for all processes +/usr/sbin/timezone.sh export TZ=$(cat /etc/TZ) # Set the firmware creation time as the base system time diff --git a/general/overlay/usr/sbin/timezone.sh b/general/overlay/usr/sbin/timezone.sh new file mode 100755 index 00000000..e3866b7c --- /dev/null +++ b/general/overlay/usr/sbin/timezone.sh @@ -0,0 +1,41 @@ +#!/bin/sh + +# Get the timezone from the u-boot environment variable +timezone=$(fw_printenv -n timezone 2>/dev/null) +if [ -z "$timezone" ]; then + echo "Timezone env variable not found, using system default." + exit 1 +fi + +echo "User defined timezone: $timezone" + +# Check if the values in /etc/timezone and /etc/TZ match the ones from fw_printenv +current_timezone=$(cat /etc/timezone 2>/dev/null) +current_tz_value=$(cat /etc/TZ 2>/dev/null) + +if [ "$timezone" = "$current_timezone" ] && [ "$timezone" = "$current_tz_value" ]; then + echo "Timezone settings are already up to date." + exit 0 +fi + +# Search for the timezone in the file +matching_line=$(zcat /var/www/a/tz.js.gz | grep -i -F "$timezone") +if [ -z "$matching_line" ]; then + echo "Timezone not found in system file." + exit 1 +fi + +# Extract the value associated with the timezone +value=$(echo "$matching_line" | awk -F',' '{print $2}' | awk -F':' '{print $2}' | tr -d "'}") + +# Write the TZ file first +echo $value > /etc/TZ + +# Then write the timezone file +echo $timezone > /etc/timezone + +export TZ=$value + +if tty -s; then + echo "timezone.sh: You are running from a shell, please restart or log out to update timezone environment variables." +fi