-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathtimezone.sh
More file actions
85 lines (70 loc) · 2.86 KB
/
Copy pathtimezone.sh
File metadata and controls
85 lines (70 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Copyright 2019 Alessandro "Locutus73" Miele
# You can download the latest version of this script from:
# https://github.com/MiSTer-devel/Scripts_MiSTer
# Version 1.4 - 2026-06-09 - Update menu system to use dialog
# Version 1.3 - 2025-01-02 - Manual selection with country and city, added automatic/manual option.
# Version 1.2 - 2019-03-02 - Changed "/media/fat/timezone" to "/media/fat/linux/timezone", removed -k option from curl.
# Version 1.1 - 2019-01-08 - Changed "http://ip-api.com/json/" to "http://www.ip-api.com/json/".
# Version 1.0 - 2019-01-08 - First commit.
if ! mode=$(dialog \
--title "Choose timezone setting method" \
--menu "" \
10 40 2 \
a Automatic \
m Manual \
3>&1 1>&2 2>&3) ; then echo "Cancelled"; exit 1; fi
if [ "$mode" == "a" ]; then
echo "Querying ip-api.com for timezone..."
TIMEZONE="$(curl -sLf "http://www.ip-api.com/json/" | jq -rM .timezone)"
elif [ "$mode" == "m" ]; then
COUNTRY_LIST=()
while IFS= read -r country; do
COUNTRY_LIST+=("$country" "")
done < <(
find /usr/share/zoneinfo/posix -mindepth 1 -maxdepth 1 -type d | \
sed 's|/usr/share/zoneinfo/posix/||' | \
sort)
if ! SELECTED_COUNTRY=$(
dialog \
--title "Select your continent/region" \
--menu "" \
20 50 10 \
"${COUNTRY_LIST[@]}" \
3>&1 1>&2 2>&3
) ; then echo "Cancelled"; exit 1; fi
CITY_LIST=()
while IFS= read -r city; do
CITY_LIST+=("$city" "")
done < <(
find "/usr/share/zoneinfo/posix/$SELECTED_COUNTRY" -type f | \
sed "s|/usr/share/zoneinfo/posix/$SELECTED_COUNTRY/||" | \
sort)
if ! CITY_CHOICE=$(
dialog \
--title "Select your city" \
--menu "" \
20 50 10 \
"${CITY_LIST[@]}" \
3>&1 1>&2 2>&3
) ; then echo "Cancelled"; exit 1; fi
TIMEZONE="$SELECTED_COUNTRY/$CITY_CHOICE"
fi
echo "Setting timezone set to $TIMEZONE."
if echo "$TIMEZONE" | grep -qE "^.+[/].+$"; then
cp "/usr/share/zoneinfo/posix/$TIMEZONE" "/media/fat/linux/timezone"
echo "Timezone set to $TIMEZONE."
else
echo "Unable to set timezone to $TIMEZONE. Please check your input or try again."
fi
exit 0