Mailing list header changes (fuck you Google)
[citadel.git] / citadel / guesstimezone.sh
1 #!/bin/sh
2
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.
5
6 # Copyright (c) by Art Cancro
7
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)
11 # any later version.
12
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
16 # more details.
17
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. 
21
22 convert_timezone()
23 {
24     case "$1" in
25         (right/*|posix/*)
26             convert_timezone "${1#*/}"
27             ;;
28         ("Africa/Asmera")
29             echo "Africa/Asmara"
30             ;;
31         ("America/Argentina/ComodRivadavia"|"America/Catamarca")
32             echo "America/Argentina/Catamarca"
33             ;;
34         ("America/Buenos_Aires")
35             echo "America/Argentina/Buenos_Aires"
36             ;;
37         ("America/Cordoba"|"America/Rosario")
38             echo "America/Argentina/Cordoba"
39             ;;
40         ("America/Jujuy")
41             echo "America/Argentina/Jujuy"
42             ;;
43         ("America/Mendoza")
44             echo "America/Argentina/Mendoza"
45             ;;
46         ("Antarctica/South_Pole")
47             echo "Antarctica/McMurdo"
48             ;;
49         "Asia/Ashkhabad")
50             echo "Asia/Ashgabat"
51             ;;
52         ("Asia/Calcutta")
53             echo "Asia/Kolkata"
54             ;;
55         "Asia/Chungking")
56             echo "Asia/Chongqing"
57             ;;
58         "Asia/Dacca")
59             echo "Asia/Dhaka"
60             ;;
61         ("Asia/Katmandu")
62             echo "Asia/Kathmandu"
63             ;;
64         "Asia/Macao")
65             echo "Asia/Macau"
66             ;;
67         ("Asia/Saigon")
68             echo "Asia/Ho_Chi_Minh"
69             ;;
70         "Asia/Thimbu")
71             echo "Asia/Thimphu"
72             ;;
73         "Asia/Ulan_Bator")
74             echo "Asia/Ulaanbaatar"
75             ;;
76         "Atlantic/Faeroe")
77             echo "Atlantic/Faroe"
78             ;;
79         "Australia/ACT" | "Australia/NSW")
80             echo "Australia/Sydney"
81             ;;
82         "Australia/LHI")
83             echo "Australia/Lord_Howe"
84             ;;
85         "Australia/North")
86             echo "Australia/Darwin"
87             ;;
88         "Australia/Queensland")
89             echo "Australia/Brisbane"
90             ;;
91         "Australia/South")
92             echo "Australia/Adelaide"
93             ;;
94         "Australia/Tasmania")
95             echo "Australia/Hobart"
96             ;;
97         "Australia/Victoria")
98             echo "Australia/Melbourne"
99             ;;
100         "Australia/West")
101             echo "Australia/Perth"
102             ;;
103         "Brazil/Acre")
104             echo "America/Rio_Branco"
105             ;;
106         "Brazil/DeNoronha")
107             echo "America/Noronha"
108             ;;
109         "Brazil/East")
110             echo "America/Sao_Paulo"
111             ;;
112         "Brazil/West")
113             echo "America/Manaus"
114             ;;
115         "Canada/Atlantic")
116             echo "America/Halifax"
117             ;;
118         "Canada/Central")
119             echo "America/Winnipeg"
120             ;;
121         "Canada/East-Saskatchewan")
122             echo "America/Regina"
123             ;;
124         "Canada/Eastern")
125             echo "America/Toronto"
126             ;;
127         "Canada/Mountain")
128             echo "America/Edmonton"
129             ;;
130         "Canada/Newfoundland")
131             echo "America/St_Johns"
132             ;;
133         "Canada/Pacific")
134             echo "America/Vancouver"
135             ;;
136         "Canada/Saskatchewan")
137             echo "America/Regina"
138             ;;
139         "Canada/Yukon")
140             echo "America/Whitehorse"
141             ;;
142         "CET")
143             echo "Europe/Paris"
144             ;;
145         "Chile/Continental")
146             echo "America/Santiago"
147             ;;
148         "Chile/EasterIsland")
149             echo "Pacific/Easter"
150             ;;
151         "CST6CDT")
152             echo "SystemV/CST6CDT"
153             ;;
154         "Cuba")
155             echo "America/Havana"
156             ;;
157         "EET")
158             echo "Europe/Helsinki"
159             ;;
160         "Egypt")
161             echo "Africa/Cairo"
162             ;;
163         "Eire")
164             echo "Europe/Dublin"
165             ;;
166         "EST")
167             echo "SystemV/EST5"
168             ;;
169         "EST5EDT")
170             echo "SystemV/EST5EDT"
171             ;;
172         "GB")
173             echo "Europe/London"
174             ;;
175         "GB-Eire")
176             echo "Europe/London"
177             ;;
178         "GMT")
179             echo "Etc/GMT"
180             ;;
181         "GMT0")
182             echo "Etc/GMT0"
183             ;;
184         "GMT-0")
185             echo "Etc/GMT-0"
186             ;;
187         "GMT+0")
188             echo "Etc/GMT+0"
189             ;;
190         "Greenwich")
191             echo "Etc/Greenwich"
192             ;;
193         "Hongkong")
194             echo "Asia/Hong_Kong"
195             ;;
196         "HST")
197             echo "Pacific/Honolulu"
198             ;;
199         "Iceland")
200             echo "Atlantic/Reykjavik"
201             ;;
202         "Iran")
203             echo "Asia/Tehran"
204             ;;
205         "Israel")
206             echo "Asia/Tel_Aviv"
207             ;;
208         "Jamaica")
209             echo "America/Jamaica"
210             ;;
211         "Japan")
212             echo "Asia/Tokyo"
213             ;;
214         "Kwajalein")
215             echo "Pacific/Kwajalein"
216             ;;
217         "Libya")
218             echo "Africa/Tripoli"
219             ;;
220         "MET")
221             echo "Europe/Paris"
222             ;;
223         "Mexico/BajaNorte")
224             echo "America/Tijuana"
225             ;;
226         "Mexico/BajaSur")
227             echo "America/Mazatlan"
228             ;;
229         "Mexico/General")
230             echo "America/Mexico_City"
231             ;;
232         "Mideast/Riyadh87")
233             echo "Asia/Riyadh87"
234             ;;
235         "Mideast/Riyadh88")
236             echo "Asia/Riyadh88"
237             ;;
238         "Mideast/Riyadh89")
239             echo "Asia/Riyadh89"
240             ;;
241         "MST")
242             echo "SystemV/MST7"
243             ;;
244         "MST7MDT")
245             echo "SystemV/MST7MDT"
246             ;;
247         "Navajo")
248             echo "America/Denver"
249             ;;
250         "NZ")
251             echo "Pacific/Auckland"
252             ;;
253         "NZ-CHAT")
254             echo "Pacific/Chatham"
255             ;;
256         "Poland")
257             echo "Europe/Warsaw"
258             ;;
259         "Portugal")
260             echo "Europe/Lisbon"
261             ;;
262         "PRC")
263             echo "Asia/Shanghai"
264             ;;
265         "PST8PDT")
266             echo "SystemV/PST8PDT"
267             ;;
268         "ROC")
269             echo "Asia/Taipei"
270             ;;
271         "ROK")
272             echo "Asia/Seoul"
273             ;;
274         "Singapore")
275             echo "Asia/Singapore"
276             ;;
277         "Turkey")
278             echo "Europe/Istanbul"
279             ;;
280         "UCT")
281             echo "Etc/UCT"
282             ;;
283         "Universal")
284             echo "Etc/UTC"
285             ;;
286         "US/Alaska")
287             echo "America/Anchorage"
288             ;;
289         "US/Aleutian")
290             echo "America/Adak"
291             ;;
292         "US/Arizona")
293             echo "America/Phoenix"
294             ;;
295         "US/Central")
296             echo "America/Chicago"
297             ;;
298         "US/East-Indiana")
299             echo "America/Indianapolis"
300             ;;
301         "US/Eastern")
302             echo "America/New_York"
303             ;;
304         "US/Hawaii")
305             echo "Pacific/Honolulu"
306             ;;
307         "US/Indiana-Starke")
308             echo "America/Indianapolis"
309             ;;
310         "US/Michigan")
311             echo "America/Detroit"
312             ;;
313         "US/Mountain")
314             echo "America/Denver"
315             ;;
316         "US/Pacific")
317             echo "America/Los_Angeles"
318             ;;
319         "US/Samoa")
320             echo "Pacific/Pago_Pago"
321             ;;
322         "UTC")
323             echo "Etc/UTC"
324             ;;
325         "WET")
326             echo "Europe/Lisbon"
327             ;;
328         "W-SU")
329             echo "Europe/Moscow"
330             ;;
331         "Zulu")
332             echo "Etc/UTC"
333             ;;
334         *)
335             echo "$1"
336             ;;
337     esac
338 }
339
340 md5sum </dev/null >/dev/null 2>/dev/null || exit 1
341
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
346 do
347         THISTIMESUM=`md5sum $filename | awk ' { print $1 } '`
348         if [ $LOCALTIMESUM = $THISTIMESUM ] ; then
349                 echo $filename | cut -c21-
350                 exit 0
351         fi
352 done 2>/dev/null
353
354 # seems we haven't found the timezone yet, let's see whether /etc/timezone has some info
355
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
363         echo $TIMEZONE 
364         exit 0
365     fi
366 fi
367
368 exit 2