Add timezone confiruation to system menu.
This commit is contained in:
Executable
+52
@@ -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
|
||||
Reference in New Issue
Block a user