forked from outroll/vesta
-
Notifications
You must be signed in to change notification settings - Fork 47
/
v-change-sys-timezone
executable file
·72 lines (56 loc) · 1.92 KB
/
v-change-sys-timezone
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
#!/bin/bash
# info: change system timezone
# options: TIMEZONE
#
# The function for changing system timezone.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
timezone=$1
# Includes
source $VESTA/func/main.sh
source $VESTA/conf/vesta.conf
is_timezone_valid() {
if [ ! -e "/usr/share/zoneinfo/$timezone" ]; then
echo "Error: tz file $timezone doesn't exist"
log_event $E_NOTEXIST "$ARGUMENTS"
exit $E_NOTEXIST
fi
}
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '1' "$#" 'TIMEZONE'
is_timezone_valid
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Changing system timezone
which timedatectls >/dev/null 2>&1
if [ "$?" -eq 0 ]; then
timedatectl set-timezone $timezone
else
if [ -e "/etc/sysconfig/clock" ]; then
sed -i "s/ZONE.*//" /etc/sysconfig/clock
echo "ZONE=\"$timezone\"" >> /etc/sysconfig/clock
fi
if [ -e "/etc/timezone" ]; then
echo "$timezone" > /etc/timezone
fi
rm -f /etc/localtime
ln -sf /usr/share/zoneinfo/$timezone /etc/localtime
fi
# Chaning php timezone
if [ ! -z "$WEB_SYSTEM" ]; then
for conf in $(find /etc/php* -name php.ini); do
sed -i "s|;date.timezone =|date.timezone =|" $conf
sed -i "s|date.timezone =.*|date.timezone = $timezone|" $conf
done
fi
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Logging
log_event "$OK" "$ARGUMENTS"
exit