mirror of
https://github.com/myvesta/vesta
synced 2025-08-19 21:04:07 -07:00
TimeZone handlers
This commit is contained in:
parent
003cbbea47
commit
5dbadaa730
2 changed files with 73 additions and 1 deletions
72
bin/v-change-sys-timezone
Executable file
72
bin/v-change-sys-timezone
Executable file
|
@ -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
|
|
@ -30,7 +30,7 @@ elif [ -f "/etc/timezone" ]; then
|
||||||
|
|
||||||
# Checking symlynks
|
# Checking symlynks
|
||||||
elif [ -h /etc/localtime ]; then
|
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)
|
# Parsing zoneinfo (very slow)
|
||||||
else
|
else
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue