52 lines
1.6 KiB
Bash
52 lines
1.6 KiB
Bash
#!/bin/bash
|
|
|
|
## Script Location
|
|
SCRIPTDIR=$(dirname $0)
|
|
source "$SCRIPTDIR/common/colors.sh"
|
|
source "$SCRIPTDIR/common/functions.sh"
|
|
source "$SCRIPTDIR/common/load-defaults.sh"
|
|
|
|
|
|
get_tz() {
|
|
local tz_type="$1"
|
|
printf "$COL_LIGHT_BLUE" "* Checking Current Timezone in $tz_type"
|
|
if [ "$tz_type" == "/etc/timezone" ]; then
|
|
current_timezone=`cat /etc/timezone`
|
|
elif [ "$tz_type" == "timedatectl" ]; then
|
|
current_timezone=$(timedatectl | grep "zone" | sed -e 's/^[ ]*Time zone: \(.*\) (.*)$/\1/g')
|
|
fi
|
|
printf "$COL_LIGHT_BLUE" "* Timezone in $tz_type is currently set to $current_timezone"
|
|
}
|
|
|
|
set_tz() {
|
|
local tz_type="$1"
|
|
local tz_current="$2"
|
|
local tz_desired="$3"
|
|
printf "$COL_LIGHT_BLUE" "* Desired Timezone is $tz_desired"
|
|
if [ $tz_current != $tz_desired ]
|
|
then
|
|
printf "$COL_LIGHT_BLUE" "* Setting Timezone to $desired_timezone"
|
|
if [ "$tz_type" == "/etc/timezone" ]; then
|
|
sudo ln -fs "/usr/share/zoneinfo/$desired_timezone" /etc/localtime
|
|
sudo dpkg-reconfigure -f noninteractive tzdata
|
|
elif [ "$tz_type" == "timedatectl" ]; then
|
|
timedatectl set-timezone $desired_timezone
|
|
fi
|
|
printf "$COL_LIGHT_BLUE" "* Timezone in $tz_type should now be set to $desired_timezone"
|
|
else
|
|
printf "$COL_LIGHT_BLUE" "* Timezone is already set to $tz_desired"
|
|
fi
|
|
}
|
|
|
|
|
|
if [ "$desired_timezone" == 0 ]; then
|
|
desired_timezone=$(whiptail --title "Set Timezone" --inputbox "What timezone should we set?" 10 80)
|
|
fi
|
|
|
|
declare -a TIMEPLACES=("/etc/timezone" "timedatectl")
|
|
for timeitem in "${TIMEPLACES[@]}"
|
|
do
|
|
get_tz $timeitem
|
|
set_tz $timeitem $current_timezone $desired_timezone
|
|
done
|