|
| 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 |
0 commit comments