From 5dbadaa7307fede5d6d211ad202605b8ad90507d Mon Sep 17 00:00:00 2001 From: Serghey Rodin Date: Fri, 29 May 2015 01:50:40 +0300 Subject: [PATCH] TimeZone handlers --- bin/v-change-sys-timezone | 72 +++++++++++++++++++++++++++++++++++++++ bin/v-get-sys-timezone | 2 +- 2 files changed, 73 insertions(+), 1 deletion(-) create mode 100755 bin/v-change-sys-timezone diff --git a/bin/v-change-sys-timezone b/bin/v-change-sys-timezone new file mode 100755 index 00000000..b66a65af --- /dev/null +++ b/bin/v-change-sys-timezone @@ -0,0 +1,72 @@ +#!/bin/bash +# info: change system timezone +# options: TIMEZONE +# +# The function for changing system timezone. + + +#----------------------------------------------------------# +# Variable&Function # +#----------------------------------------------------------# + +# Argument defenition +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 "$EVENT" + 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" "$EVENT" + +exit diff --git a/bin/v-get-sys-timezone b/bin/v-get-sys-timezone index c9ccea2b..8a3607b4 100755 --- a/bin/v-get-sys-timezone +++ b/bin/v-get-sys-timezone @@ -30,7 +30,7 @@ elif [ -f "/etc/timezone" ]; then # Checking symlynks elif [ -h /etc/localtime ]; then - ZONE=$(readlink /etc/localtime | sed "s/\/usr\/share\/zoneinfo\///") + ZONE=$(readlink /etc/localtime | sed "s%.*share/zoneinfo/%%") # Parsing zoneinfo (very slow) else