From 63080746f26a3fb3efab5f1a35b01d8dd331b1c7 Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Fri, 18 Jul 2025 16:52:01 -0400 Subject: [PATCH] Add timezone confiruation to system menu. --- home/stormux/.clirc | 3 ++ usr/local/bin/game_launcher.py | 1 + usr/local/bin/set-timezone.sh | 52 ++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100755 usr/local/bin/set-timezone.sh diff --git a/home/stormux/.clirc b/home/stormux/.clirc index 9de65bc..f4599c3 100755 --- a/home/stormux/.clirc +++ b/home/stormux/.clirc @@ -111,6 +111,9 @@ case "$GAME" in "Install to Disk") /usr/local/bin/install_to_disk.sh ;; + "Set Timezone") + sudo /usr/local/bin/set-timezone.sh + ;; *".md") /usr/bin/markdown -toc "$GAME" | /usr/bin/w3m -T text/html ;; "/usr/bin/"*) $GAME ;; esac diff --git a/usr/local/bin/game_launcher.py b/usr/local/bin/game_launcher.py index 191b774..9553796 100755 --- a/usr/local/bin/game_launcher.py +++ b/usr/local/bin/game_launcher.py @@ -962,6 +962,7 @@ if __name__ == "__main__": menu.add_item("System", "Disable HDMI Screen", lambda: menu.toggle_screen("headless")) menu.add_item("System", "Set System Default Speech Rate", "/usr/local/bin/speechd_rate.py") menu.add_item("System", "Set Default Voice", "/usr/local/bin/set-voice.py") + menu.add_item("System", "Set Timezone", "GAME='Set Timezone' /home/stormux/.clirc") menu.add_item("System", "Upload Files", "/home/stormux/.local/upload_server/uploader.py") menu.add_item("System", "Restart: Can Take Several Minutes", "sudo reboot") menu.add_item("System", "Power Off: Wait 2 Minutes Before Disconnecting Power", "sudo poweroff") diff --git a/usr/local/bin/set-timezone.sh b/usr/local/bin/set-timezone.sh new file mode 100755 index 0000000..04d2153 --- /dev/null +++ b/usr/local/bin/set-timezone.sh @@ -0,0 +1,52 @@ +#!/usr/bin/env bash + +# Timezone configuration for Stormux Gaming Image +# Uses the same interface as standard Stormux images + +export DIALOGOPTS='--insecure --no-lines --visit-items' + +set_timezone() { + # Get the list of timezones + mapfile -t regions < <(timedatectl --no-pager list-timezones | cut -d '/' -f1 | sort -u) + + # Use the same text twice here and just hide the tag field. + region=$(dialog --backtitle "Please select your Region" \ + --no-tags \ + --menu "Use up and down arrows or page-up and page-down to navigate the list, and press 'Enter' to make your selection." 0 0 0 \ + $(for i in ${regions[@]} ; do echo "$i";echo "$i";done) --stdout) + + if [[ -z "$region" ]]; then + echo "No region selected" + exit 1 + fi + + mapfile -t cities < <(timedatectl --no-pager list-timezones | grep "$region" | cut -d '/' -f2 | sort -u) + + # Use the same text twice here and just hide the tag field. + city=$(dialog --backtitle "Please select a city near you" \ + --no-tags \ + --menu "Use up and down arrow or page-up and page-down to navigate the list." 0 0 10 \ + $(for i in ${cities[@]} ; do echo "$i";echo "$i";done) --stdout) + + if [[ -z "$city" ]]; then + echo "No city selected" + exit 1 + fi + + # Set the timezone + if [[ -f /etc/localtime ]]; then + rm /etc/localtime + fi + ln -sf /usr/share/zoneinfo/${region}/${city} /etc/localtime + timedatectl set-ntp true + + echo "Timezone set to ${region}/${city}" +} + +# Check if running as root +if [[ $EUID -ne 0 ]]; then + echo "This script requires root privileges" + exit 1 +fi + +set_timezone \ No newline at end of file