1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
#!/bin/bash
set -e
export LC_ALL=C
type=$1
preversion=$2
zone_banner() {
TZBase=$(LC_ALL=C TZ=UTC0 date)
UTdate=$(TZ=UTC0 date -d "$TZBase")
TZdate=$(TZ="$timezone" date -d "$TZBase")
extra_info="
Local time is now: $TZdate.
Universal Time is now: $UTdate."
echo "Current default timezone: '$timezone'.$extra_info"
echo "Run 'tzconfig' if you wish to change it."
}
set_timezone() {
frontend=`echo "$DEBIAN_FRONTEND" | tr '[:upper:]' '[:lower:]'`
if [ "$frontend" = noninteractive ]; then
echo "Non-interactive mode, setting timezone to UTC. Run tzconfig to change."
echo "UTC" >/etc/timezone
ln -sf /usr/share/zoneinfo/UTC /etc/localtime
else
echo "Running 'tzconfig' to set this system's timezone."
/usr/sbin/tzconfig
fi
}
realpath()
{
fname=${1%/} # strips trailing '/'
while [ -L "$fname" ]; do
oldfname="$fname"
fname="$(command ls -l $fname)"
fname="${fname#*\> }"
if [ "$fname" = . ] ; then
fname="$(dirname $oldfname)"
elif echo $fname | grep -vq '^/' - ; then
fname="$(dirname $oldfname)/$fname"
fi
done
pushd $(dirname $fname) > /dev/null
fname=$(pwd -P)/$(basename $fname)
popd > /dev/null
echo $fname
}
if [ "$type" = "configure" ]
then
if [ -f /etc/timezone ]; then
timezone=$(head -n 1 /etc/timezone | sed -e "s/ .*//")
else
timezone=Factory
fi
if [ "$timezone" = Factory ]; then
if [ -L /etc/localtime ]; then
localtime_link=$(realpath /etc/localtime)
if [ -f "$localtime_link" ]; then
link_not_dangling=true
fi
if [ "$link_not_dangling" = true ]; then
timezone=$(echo $localtime_link | sed 's%^/usr/share/zoneinfo/%%')
fi
fi
fi
if [ -f /usr/share/zoneinfo/$timezone ] && [ "$timezone" != Factory ]
then
# zic -l $timezone
rm -f /etc/localtime && \
cp -f /usr/share/zoneinfo/$timezone /etc/localtime
zone_banner
# Handle problem caused by lame old tzconfig.
elif [ "$timezone" = "US/Pacific-New" ]
then
echo "US/Pacific" > /etc/timezone
# zic -l US/Pacific
rm -f /etc/localtime && \
cp -f /usr/share/zoneinfo/US/Pacific /etc/localtime
zone_banner
else
set_timezone
fi
if [ "$(date +%Z)" = "/etc/localtime" ]; then
set_timezone
fi
fi
#DEBHELPER#
exit 0
|