v-change-sys-timezone 1.9 KB

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