#!/bin/sh #(c) Copyright Barry Kauler 2007 www.puppylinux.com #2007 Lesser GPL licence v2 (http://www.fsf.org/licensing/licenses/lgpl.html) #utility to select the timezone. #Note, as Puppy will mostly be on PCs coexisting with Windows, #hardware clock (CMOS) is set to local time (see /etc/rc.d/rc.local0) #BK oct2007: updated for 3.02 #w019 april 2009: cli mode so can run from /etc/rc.d/rc.update # 13feb10 rewrite fully by shinobar, accept options usage() { MYNAME=$(basename $0) echo "usage: $MYNAME [newtimezone] $MYNAME cli ask timezone with console dialog $MYNAME --load set timezone according /etc/localtime $MYNAME --list show available choice" exit 1 } loadtimezone() { #need to set Linux system time/date, from hardware clock... hwclock --hctosys --localtime #...--hctosys reads cmos clock to system, referencing /usr/share/zoneinfo/localtime #...--localtime means that cmos clock is set to local-time. # correct timestamp touch /etc/rc.d/BOOTCONFIG } newtimezone() { #validity check... echo "$ZONEINFO" | grep -qw "$ZONERETVAL" || return echo $ZONERETVAL| grep -q 'GMT' && \ ZONERETVAL=$(echo $ZONERETVAL| tr '-' 'x'| tr '+' '-'| tr 'x' '+') echo "$ZONERETVAL" | grep -q '/' || ZONERETVAL="Etc/$ZONERETVAL" rm -f /etc/localtime ln -s /usr/share/zoneinfo/$ZONERETVAL /etc/localtime rm -f /etc/TZ #don't think need this anymore. also removed from /etc/profile. #.../etc/profile now reads /etc/localtime and exports TZ variable. loadtimezone } case "$1" in *-lo*) if [ -f /etc/localtime; then loadtimezone exit fi shift ;; esac LANGORG=$LANG export LANG=C CZONE='/usr/share/zoneinfo/Etc/UTC' [ -L /etc/localtime ] && CZONE=$(readlink /etc/localtime) DEFTAG=$(echo $CZONE| sed -e 's%/usr/share/zoneinfo/%%' -e 's%Etc/%%') echo $DEFTAG| grep -q 'GMT' && \ DEFTAG=$(echo $DEFTAG| tr '-' 'x'| tr '+' '-'| tr 'x' '+') ZONEINFO=$(find /usr/share/zoneinfo -type f -printf '%P\n'| grep -v -E '(GMT|\.tab$)'| sed -e 's%Etc/%%'|sort) GMTS="GMT-12 Eniwetok GMT-11 Samoa GMT-10 Alaska,Hawaii GMT-9 Alaska GMT-8 Los_Angeles GMT-7 Alberta,Montana,Arizona GMT-6 Mexico_City,Saskatchewan GMT-5 Bogota,Lima,New_York GMT-4 Caracas,La_Paz,Canada GMT-3 Brasilia,Buenos_Aires,Georgetown GMT-2 mid-Atlantic GMT-1 Azores,CapeVerdes GMT+0 London,Dublin,Edinburgh,Lisbon,Reykjavik,Casablanca GMT+1 Paris,Berlin,Amsterdam,Brussels,Madrid,Stockholm,Oslo GMT+2 Athens,Helsinki,Istanbul,Jerusalem,Harare GMT+3 Kuwait,Nairobi,Riyadh,Moscow GMT+4 Abu_Dhabi,Muscat,Tblisi,Volgograd,Kabul GMT+5 Islamabad,Karachi GMT+6 Almaty,Dhaka GMT+7 Bangkok,Jakarta GMT+8 Perth,Singapore,Hongkong GMT+9 Tokyo GMT+10 Guam GMT+11 Magadan,Soloman_Is. GMT+12 Wellington,Fiji,Marshall_Islands GMT+13 Rawaki_Islands GMT+14 Line_Islands" GMTINFO=$(echo "$GMTS"| cut -d ' ' -f1) if [ "$DEFTAG" != "" ]; then ZONEINFO=$(echo $DEFTAG; echo "$ZONEINFO" |grep -v "$DEFTAG") fi ZONECHOICES=$(echo "$ZONEINFO"| sed -e 's/$/ ./') # add ' .' at tail for dummy ZONECHOICES="$ZONECHOICES $GMTS" ZONEINFO="$ZONEINFO $GMTINFO" XSTATUS="no" [ "$DISPLAY" ] && XSTATUS="yes" # check parameter [ $# -le 1 ] || usage if [ $# -eq 1 ]; then case "$1" in *-li*) echo "$ZONECHOICES" exit ;; -*) usage;; cli) XSTATUS="no";; *) ZONERETVAL=$1 newtimezone || usage exit ;; esac fi if [ "$XSTATUS" = "yes" ];then ZONEDLG="Xdialog --stdout --title \"Puppy timezone selector\" --default-item $DEFTAG --menubox \"Please choose your timezone.\\nIf a city/region/country in your timezone is not listed, choose a GMT\" 0 0 0 $ZONECHOICES" eval $ZONEDLG >/tmp/zoneretval else ZONEDLG="dialog --aspect 10 --title \"Puppy timezone selector\" --default-item $DEFTAG --menu \"Please choose your timezone. If a city/region/country in your timezone is not listed, choose a GMT\" 0 0 0 ${ZONECHOICES}" eval $ZONEDLG 2>/tmp/zoneretval fi [ $? -ne 0 ] && exit ZONERETVAL="`cat /tmp/zoneretval`" newtimezone ###END###