3 # guesstimezone.sh - an ugly hack of a script to try to guess the time
4 # zone currently in use on the host system, and output its name.
6 # Copyright (c) by Art Cancro
8 # This program is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by the Free
10 # Software Foundation; either version 3 of the License, or (at your option)
13 # This program is distributed in the hope that it will be useful, but WITHOUT
14 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 # You should have received a copy of the GNU General Public License along
19 # with this program; if not, write to the Free Software Foundation, Inc.,
20 # 675 Mass Ave, Cambridge, MA 02139, USA.
26 convert_timezone
"${1#*/}"
31 ("America/Argentina/ComodRivadavia"|
"America/Catamarca")
32 echo "America/Argentina/Catamarca"
34 ("America/Buenos_Aires")
35 echo "America/Argentina/Buenos_Aires"
37 ("America/Cordoba"|
"America/Rosario")
38 echo "America/Argentina/Cordoba"
41 echo "America/Argentina/Jujuy"
44 echo "America/Argentina/Mendoza"
46 ("Antarctica/South_Pole")
47 echo "Antarctica/McMurdo"
68 echo "Asia/Ho_Chi_Minh"
74 echo "Asia/Ulaanbaatar"
79 "Australia/ACT" |
"Australia/NSW")
80 echo "Australia/Sydney"
83 echo "Australia/Lord_Howe"
86 echo "Australia/Darwin"
88 "Australia/Queensland")
89 echo "Australia/Brisbane"
92 echo "Australia/Adelaide"
95 echo "Australia/Hobart"
98 echo "Australia/Melbourne"
101 echo "Australia/Perth"
104 echo "America/Rio_Branco"
107 echo "America/Noronha"
110 echo "America/Sao_Paulo"
113 echo "America/Manaus"
116 echo "America/Halifax"
119 echo "America/Winnipeg"
121 "Canada/East-Saskatchewan")
122 echo "America/Regina"
125 echo "America/Toronto"
128 echo "America/Edmonton"
130 "Canada/Newfoundland")
131 echo "America/St_Johns"
134 echo "America/Vancouver"
136 "Canada/Saskatchewan")
137 echo "America/Regina"
140 echo "America/Whitehorse"
146 echo "America/Santiago"
148 "Chile/EasterIsland")
149 echo "Pacific/Easter"
152 echo "SystemV/CST6CDT"
155 echo "America/Havana"
158 echo "Europe/Helsinki"
170 echo "SystemV/EST5EDT"
194 echo "Asia/Hong_Kong"
197 echo "Pacific/Honolulu"
200 echo "Atlantic/Reykjavik"
209 echo "America/Jamaica"
215 echo "Pacific/Kwajalein"
218 echo "Africa/Tripoli"
224 echo "America/Tijuana"
227 echo "America/Mazatlan"
230 echo "America/Mexico_City"
245 echo "SystemV/MST7MDT"
248 echo "America/Denver"
251 echo "Pacific/Auckland"
254 echo "Pacific/Chatham"
266 echo "SystemV/PST8PDT"
275 echo "Asia/Singapore"
278 echo "Europe/Istanbul"
287 echo "America/Anchorage"
293 echo "America/Phoenix"
296 echo "America/Chicago"
299 echo "America/Indianapolis"
302 echo "America/New_York"
305 echo "Pacific/Honolulu"
308 echo "America/Indianapolis"
311 echo "America/Detroit"
314 echo "America/Denver"
317 echo "America/Los_Angeles"
320 echo "Pacific/Pago_Pago"
340 md5sum </dev
/null
>/dev
/null
2>/dev
/null ||
exit 1
342 # this check will find the timezone if /etc/localtime is a link to the right timezone file
343 # or that file has been copied to /etc/localtime and not changed afterwards
344 LOCALTIMESUM
=`md5sum /etc/localtime | awk ' { print $1 } ' 2>/dev/null`
345 find /usr
/share
/zoneinfo
-type f
-print |
while read filename
347 THISTIMESUM
=`md5sum $filename | awk ' { print $1 } '`
348 if [ $LOCALTIMESUM = $THISTIMESUM ] ; then
349 echo $filename | cut
-c21-
354 # seems we haven't found the timezone yet, let's see whether /etc/timezone has some info
356 if [ -e /etc
/timezone
]; then
357 TIMEZONE
="$(head -n 1 /etc/timezone)"
358 TIMEZONE
="${TIMEZONE%% *}"
359 TIMEZONE
="${TIMEZONE##/}"
360 TIMEZONE
="${TIMEZONE%%/}"
361 TIMEZONE
="$(convert_timezone $TIMEZONE)"
362 if [ -f "/usr/share/zoneinfo/$TIMEZONE" ] ; then