Skip to content

Commit 5dbadaa

Browse files
committed
TimeZone handlers
1 parent 003cbbe commit 5dbadaa

File tree

2 files changed

+73
-1
lines changed

2 files changed

+73
-1
lines changed

bin/v-change-sys-timezone

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/bin/bash
2+
# info: change system timezone
3+
# options: TIMEZONE
4+
#
5+
# The function for changing system timezone.
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument defenition
13+
timezone=$1
14+
15+
# Includes
16+
source $VESTA/func/main.sh
17+
source $VESTA/conf/vesta.conf
18+
19+
is_timezone_valid() {
20+
if [ ! -e "/usr/share/zoneinfo/$timezone" ]; then
21+
echo "Error: tz file $timezone doesn't exist"
22+
log_event $E_NOTEXIST "$EVENT"
23+
exit $E_NOTEXIST
24+
fi
25+
}
26+
27+
28+
#----------------------------------------------------------#
29+
# Verifications #
30+
#----------------------------------------------------------#
31+
32+
check_args '1' "$#" 'TIMEZONE'
33+
is_timezone_valid
34+
35+
36+
#----------------------------------------------------------#
37+
# Action #
38+
#----------------------------------------------------------#
39+
40+
# Changing system timezone
41+
which timedatectls >/dev/null 2>&1
42+
if [ "$?" -eq 0 ]; then
43+
timedatectl set-timezone $timezone
44+
else
45+
if [ -e "/etc/sysconfig/clock" ]; then
46+
sed -i "s/ZONE.*//" /etc/sysconfig/clock
47+
echo "ZONE=\"$timezone\"" >> /etc/sysconfig/clock
48+
fi
49+
if [ -e "/etc/timezone" ]; then
50+
echo "$timezone" > /etc/timezone
51+
fi
52+
rm -f /etc/localtime
53+
ln -sf /usr/share/zoneinfo/$timezone /etc/localtime
54+
fi
55+
56+
# Chaning php timezone
57+
if [ ! -z "$WEB_SYSTEM" ]; then
58+
for conf in $(find /etc/php* -name php.ini); do
59+
sed -i "s|;date.timezone =|date.timezone =|" $conf
60+
sed -i "s|date.timezone =.*|date.timezone = $timezone|" $conf
61+
done
62+
fi
63+
64+
65+
#----------------------------------------------------------#
66+
# Vesta #
67+
#----------------------------------------------------------#
68+
69+
# Logging
70+
log_event "$OK" "$EVENT"
71+
72+
exit

bin/v-get-sys-timezone

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ elif [ -f "/etc/timezone" ]; then
3030

3131
# Checking symlynks
3232
elif [ -h /etc/localtime ]; then
33-
ZONE=$(readlink /etc/localtime | sed "s/\/usr\/share\/zoneinfo\///")
33+
ZONE=$(readlink /etc/localtime | sed "s%.*share/zoneinfo/%%")
3434

3535
# Parsing zoneinfo (very slow)
3636
else

0 commit comments

Comments
 (0)