-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimezone.sh
More file actions
57 lines (49 loc) · 1.28 KB
/
timezone.sh
File metadata and controls
57 lines (49 loc) · 1.28 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
#!/usr/bin/env bash
set -euo pipefail
# ---------- helpers ----------
log() { echo -e "\n==> $*"; }
if [[ "${EUID}" -ne 0 ]]; then
echo "Please run as root: sudo $0"
exit 1
fi
# ---------- get timezone from argument or prompt ----------
TIMEZONE="${1:-}"
if [[ -z "${TIMEZONE}" ]]; then
echo ""
echo "Common timezones:"
echo " UTC"
echo " America/New_York"
echo " America/Los_Angeles"
echo " Europe/London"
echo " Europe/Paris"
echo " Asia/Tokyo"
echo " Asia/Singapore"
echo " Asia/Dubai"
echo " Asia/Tehran"
echo " Australia/Sydney"
echo ""
echo "List all: timedatectl list-timezones"
echo ""
read -p "Enter timezone: " TIMEZONE
fi
if [[ -z "${TIMEZONE}" ]]; then
echo "ERROR: No timezone specified"
exit 1
fi
# ---------- verify timezone exists ----------
if ! timedatectl list-timezones | grep -q "^${TIMEZONE}$"; then
echo "ERROR: Invalid timezone '${TIMEZONE}'"
echo "Use 'timedatectl list-timezones' to list valid options"
exit 1
fi
# ---------- set timezone ----------
log "Setting timezone to ${TIMEZONE}..."
timedatectl set-timezone "${TIMEZONE}"
log "Done."
echo ""
echo "=========================================="
echo " Timezone Configuration Complete!"
echo "=========================================="
echo ""
timedatectl
echo ""