xref: /titanic_52/usr/src/cmd/zic/tzselect.ksh (revision 80868c5387b92f32fe0e8ea709e36cb535287e03)
17c478bd9Sstevel@tonic-gate#! /usr/bin/ksh
27c478bd9Sstevel@tonic-gate#
3*80868c53Srobbin# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
4*80868c53Srobbin# Use is subject to license terms.
57c478bd9Sstevel@tonic-gate#
67c478bd9Sstevel@tonic-gate# ident	"%Z%%M%	%I%	%E% SMI"
77c478bd9Sstevel@tonic-gate#
8*80868c53Srobbin# '@(#)tzselect.ksh	1.8'
97c478bd9Sstevel@tonic-gate
107c478bd9Sstevel@tonic-gate# Ask the user about the time zone, and output the resulting TZ value to stdout.
117c478bd9Sstevel@tonic-gate# Interact with the user via stderr and stdin.
127c478bd9Sstevel@tonic-gate
13*80868c53Srobbin# Contributed by Paul Eggert
147c478bd9Sstevel@tonic-gate
157c478bd9Sstevel@tonic-gate# Porting notes:
167c478bd9Sstevel@tonic-gate#
177c478bd9Sstevel@tonic-gate# This script requires several features of the Korn shell.
187c478bd9Sstevel@tonic-gate# If your host lacks the Korn shell,
197c478bd9Sstevel@tonic-gate# you can use either of the following free programs instead:
207c478bd9Sstevel@tonic-gate#
217c478bd9Sstevel@tonic-gate#	<a href=ftp://ftp.gnu.org/pub/gnu/>
227c478bd9Sstevel@tonic-gate#	Bourne-Again shell (bash)
237c478bd9Sstevel@tonic-gate#	</a>
247c478bd9Sstevel@tonic-gate#
257c478bd9Sstevel@tonic-gate#	<a href=ftp://ftp.cs.mun.ca/pub/pdksh/pdksh.tar.gz>
267c478bd9Sstevel@tonic-gate#	Public domain ksh
277c478bd9Sstevel@tonic-gate#	</a>
287c478bd9Sstevel@tonic-gate#
297c478bd9Sstevel@tonic-gate# This script also uses several features of modern awk programs.
307c478bd9Sstevel@tonic-gate# If your host lacks awk, or has an old awk that does not conform to POSIX.2,
317c478bd9Sstevel@tonic-gate# you can use either of the following free programs instead:
327c478bd9Sstevel@tonic-gate#
337c478bd9Sstevel@tonic-gate#	<a href=ftp://ftp.gnu.org/pub/gnu/>
347c478bd9Sstevel@tonic-gate#	GNU awk (gawk)
357c478bd9Sstevel@tonic-gate#	</a>
367c478bd9Sstevel@tonic-gate#
377c478bd9Sstevel@tonic-gate#	<a href=ftp://ftp.whidbey.net/pub/brennan/>
387c478bd9Sstevel@tonic-gate#	mawk
397c478bd9Sstevel@tonic-gate#	</a>
407c478bd9Sstevel@tonic-gate
417c478bd9Sstevel@tonic-gateAWK=/usr/bin/nawk
427c478bd9Sstevel@tonic-gateGREP=/usr/bin/grep
437c478bd9Sstevel@tonic-gateEXPR=/usr/bin/expr
447c478bd9Sstevel@tonic-gateLOCALE=/usr/bin/locale
457c478bd9Sstevel@tonic-gateSORT=/usr/bin/sort
467c478bd9Sstevel@tonic-gatePRINTF=/usr/bin/printf
477c478bd9Sstevel@tonic-gateDATE=/usr/bin/date
487c478bd9Sstevel@tonic-gateGETTEXT=/usr/bin/gettext
497c478bd9Sstevel@tonic-gate
507c478bd9Sstevel@tonic-gateTZDIR=/usr/share/lib/zoneinfo
517c478bd9Sstevel@tonic-gate
527c478bd9Sstevel@tonic-gate# Messages
537c478bd9Sstevel@tonic-gateERR_NO_SETUP="%s: time zone files are not set up correctly"
547c478bd9Sstevel@tonic-gateINFO_LOCATION="Please identify a location so that time zone rules \
557c478bd9Sstevel@tonic-gatecan be set correctly."
567c478bd9Sstevel@tonic-gateINFO_SELECT_CONT="Please select a continent or ocean."
577c478bd9Sstevel@tonic-gateINFO_POSIX="none - I want to specify the time zone using the POSIX \
587c478bd9Sstevel@tonic-gateTZ format."
597c478bd9Sstevel@tonic-gateWARN_ENTER_NUM="Please enter a number in range."
607c478bd9Sstevel@tonic-gateINFO_ENTER_POSIX="Please enter the desired value of the TZ environment \
617c478bd9Sstevel@tonic-gatevariable."
627c478bd9Sstevel@tonic-gateINFO_POSIX_EX="For example, GST-10 is a zone named GST that is 10 hours \
637c478bd9Sstevel@tonic-gateahead (east) of UTC."
647c478bd9Sstevel@tonic-gateERR_INV_POSIX="\`%s\' is not a conforming POSIX time zone string."
657c478bd9Sstevel@tonic-gateINFO_SELECT_CNTRY="Please select a country or region."
667c478bd9Sstevel@tonic-gateINFO_SELECT_TZ="Please select one of the following time zone regions."
677c478bd9Sstevel@tonic-gateINFO_EXTRA1="Local time is now:       %s"
687c478bd9Sstevel@tonic-gateINFO_EXTRA2="Universal Time is now:   %s"
697c478bd9Sstevel@tonic-gateINFO_INFO="The following information has been given:"
707c478bd9Sstevel@tonic-gateINFO_TZ="Therefore TZ='%s' will be used."
717c478bd9Sstevel@tonic-gateINFO_OK="Is the above information OK?"
727c478bd9Sstevel@tonic-gateINFO_YES="Yes"
737c478bd9Sstevel@tonic-gateINFO_NO="No"
747c478bd9Sstevel@tonic-gateWARN_ENTER_YORN="Please enter 1 for Yes, or 2 for No."
757c478bd9Sstevel@tonic-gateINFO_FINE="Here is the TZ value again, this time on standard output:"
767c478bd9Sstevel@tonic-gate
777c478bd9Sstevel@tonic-gate# I18n support
787c478bd9Sstevel@tonic-gateTEXTDOMAINDIR=/usr/lib/locale; export TEXTDOMAINDIR
797c478bd9Sstevel@tonic-gateTEXTDOMAIN=SUNW_OST_OSCMD; export TEXTDOMAIN
807c478bd9Sstevel@tonic-gateDOMAIN2=SUNW_OST_ZONEINFO
817c478bd9Sstevel@tonic-gate
827c478bd9Sstevel@tonic-gate# Make sure the tables are readable.
837c478bd9Sstevel@tonic-gateTZ_COUNTRY_TABLE=$TZDIR/tab/country.tab
847c478bd9Sstevel@tonic-gateTZ_ZONE_TABLE=$TZDIR/tab/zone_sun.tab
857c478bd9Sstevel@tonic-gatefor f in $TZ_COUNTRY_TABLE $TZ_ZONE_TABLE
867c478bd9Sstevel@tonic-gatedo
877c478bd9Sstevel@tonic-gate	<$f || {
887c478bd9Sstevel@tonic-gate		$PRINTF >&2 "`$GETTEXT "$ERR_NO_SETUP"`\n"  $0
897c478bd9Sstevel@tonic-gate		exit 1
907c478bd9Sstevel@tonic-gate	}
917c478bd9Sstevel@tonic-gatedone
927c478bd9Sstevel@tonic-gate
937c478bd9Sstevel@tonic-gatenewline='
947c478bd9Sstevel@tonic-gate'
957c478bd9Sstevel@tonic-gateIFS=$newline
967c478bd9Sstevel@tonic-gate
977c478bd9Sstevel@tonic-gate# For C locale, don't need to call gettext(1)
987c478bd9Sstevel@tonic-gateloc_messages=`$LOCALE | $GREP LC_MESSAGES | $AWK -F"=" '{print $2}`
997c478bd9Sstevel@tonic-gateif [ "$loc_messages" = "\"C\""  -o "$loc_messages" = "C" ]; then
1007c478bd9Sstevel@tonic-gate	is_C=1
1017c478bd9Sstevel@tonic-gateelse
1027c478bd9Sstevel@tonic-gate	is_C=0
1037c478bd9Sstevel@tonic-gatefi
1047c478bd9Sstevel@tonic-gate
1057c478bd9Sstevel@tonic-gateiafrica=`$GETTEXT $DOMAIN2 Africa`
1067c478bd9Sstevel@tonic-gateiamerica=`$GETTEXT $DOMAIN2 Americas`
1077c478bd9Sstevel@tonic-gateiantarctica=`$GETTEXT $DOMAIN2 Antarctica`
1087c478bd9Sstevel@tonic-gateiarcticocean=`$GETTEXT $DOMAIN2 "Arctic Ocean"`
1097c478bd9Sstevel@tonic-gateiasia=`$GETTEXT $DOMAIN2 Asia`
1107c478bd9Sstevel@tonic-gateiatlanticocean=`$GETTEXT $DOMAIN2 "Atlantic Ocean"`
1117c478bd9Sstevel@tonic-gateiaustralia=`$GETTEXT $DOMAIN2 Australia`
1127c478bd9Sstevel@tonic-gateieurope=`$GETTEXT $DOMAIN2 Europe`
1137c478bd9Sstevel@tonic-gateipacificocean=`$GETTEXT $DOMAIN2 "Pacific Ocean"`
1147c478bd9Sstevel@tonic-gateiindianocean=`$GETTEXT $DOMAIN2 "Indian Ocean"`
1157c478bd9Sstevel@tonic-gatenone=`$GETTEXT "$INFO_POSIX"`
1167c478bd9Sstevel@tonic-gate
1177c478bd9Sstevel@tonic-gate# Begin the main loop.  We come back here if the user wants to retry.
1187c478bd9Sstevel@tonic-gatewhile
1197c478bd9Sstevel@tonic-gate	$PRINTF >&2 "`$GETTEXT "$INFO_LOCATION"`\n"
1207c478bd9Sstevel@tonic-gate
1217c478bd9Sstevel@tonic-gate	continent=
1227c478bd9Sstevel@tonic-gate	country=
1237c478bd9Sstevel@tonic-gate	region=
1247c478bd9Sstevel@tonic-gate
1257c478bd9Sstevel@tonic-gate	# Ask the user for continent or ocean.
1267c478bd9Sstevel@tonic-gate	$PRINTF >&2 "`$GETTEXT "$INFO_SELECT_CONT"`\n"
1277c478bd9Sstevel@tonic-gate
1287c478bd9Sstevel@tonic-gate	select continent in \
1297c478bd9Sstevel@tonic-gate	    $iafrica \
1307c478bd9Sstevel@tonic-gate	    $iamerica \
1317c478bd9Sstevel@tonic-gate	    $iantarctica \
1327c478bd9Sstevel@tonic-gate	    $iarcticocean \
1337c478bd9Sstevel@tonic-gate	    $iasia \
1347c478bd9Sstevel@tonic-gate	    $iatlanticocean \
1357c478bd9Sstevel@tonic-gate	    $iaustralia \
1367c478bd9Sstevel@tonic-gate	    $ieurope \
1377c478bd9Sstevel@tonic-gate	    $iindianocean \
1387c478bd9Sstevel@tonic-gate	    $ipacificocean \
1397c478bd9Sstevel@tonic-gate	    $none
1407c478bd9Sstevel@tonic-gate
1417c478bd9Sstevel@tonic-gate	do
1427c478bd9Sstevel@tonic-gate	    case $continent in
1437c478bd9Sstevel@tonic-gate	    '')
1447c478bd9Sstevel@tonic-gate		$PRINTF >&2 "`$GETTEXT "$WARN_ENTER_NUM"`\n";;
1457c478bd9Sstevel@tonic-gate
1467c478bd9Sstevel@tonic-gate	    ?*)
1477c478bd9Sstevel@tonic-gate		case $continent in
1487c478bd9Sstevel@tonic-gate	    $iafrica) continent=Africa;;
1497c478bd9Sstevel@tonic-gate	    $iamerica) continent=America;;
1507c478bd9Sstevel@tonic-gate	    $iantarctica) continent=Antarctica;;
1517c478bd9Sstevel@tonic-gate	    $iarcticocean) continent=Arctic;;
1527c478bd9Sstevel@tonic-gate	    $iasia) continent=Asia;;
1537c478bd9Sstevel@tonic-gate	    $iatlanticocean) continent=Atlantic;;
1547c478bd9Sstevel@tonic-gate	    $iaustralia) continent=Australia;;
1557c478bd9Sstevel@tonic-gate	    $ieurope) continent=Europe;;
1567c478bd9Sstevel@tonic-gate	    $iindianocean) continent=Indian;;
1577c478bd9Sstevel@tonic-gate	    $ipacificocean) continent=Pacific;;
1587c478bd9Sstevel@tonic-gate	    $none) continent=none;;
1597c478bd9Sstevel@tonic-gate		esac
1607c478bd9Sstevel@tonic-gate		break
1617c478bd9Sstevel@tonic-gate	    esac
1627c478bd9Sstevel@tonic-gate	done
1637c478bd9Sstevel@tonic-gate	case $continent in
1647c478bd9Sstevel@tonic-gate	'')
1657c478bd9Sstevel@tonic-gate		exit 1;;
1667c478bd9Sstevel@tonic-gate	none)
1677c478bd9Sstevel@tonic-gate		# Ask the user for a POSIX TZ string.  Check that it conforms.
1687c478bd9Sstevel@tonic-gate		while
1697c478bd9Sstevel@tonic-gate			$PRINTF >&2 "`$GETTEXT "$INFO_ENTER_POSIX"`\n"
1707c478bd9Sstevel@tonic-gate			$PRINTF >&2 "`$GETTEXT "$INFO_POSIX_EX"`\n"
1717c478bd9Sstevel@tonic-gate
1727c478bd9Sstevel@tonic-gate			read TZ
1737c478bd9Sstevel@tonic-gate			env LC_ALL=C $AWK -v TZ="$TZ" 'BEGIN {
1747c478bd9Sstevel@tonic-gate				tzname = "[^-+,0-9][^-+,0-9][^-+,0-9]+"
1757c478bd9Sstevel@tonic-gate				time = "[0-2]?[0-9](:[0-5][0-9](:[0-5][0-9])?)?"
1767c478bd9Sstevel@tonic-gate				offset = "[-+]?" time
1777c478bd9Sstevel@tonic-gate				date = "(J?[0-9]+|M[0-9]+\.[0-9]+\.[0-9]+)"
1787c478bd9Sstevel@tonic-gate				datetime = "," date "(/" time ")?"
1797c478bd9Sstevel@tonic-gate				tzpattern = "^(:.*|" tzname offset "(" tzname \
1807c478bd9Sstevel@tonic-gate				  "(" offset ")?(" datetime datetime ")?)?)$"
1817c478bd9Sstevel@tonic-gate				if (TZ ~ tzpattern) exit 1
1827c478bd9Sstevel@tonic-gate				exit 0
1837c478bd9Sstevel@tonic-gate			}'
1847c478bd9Sstevel@tonic-gate		do
1857c478bd9Sstevel@tonic-gate			$PRINTF >&2 "`$GETTEXT "$ERR_INV_POSIX"`\n" $TZ
1867c478bd9Sstevel@tonic-gate
1877c478bd9Sstevel@tonic-gate		done
1887c478bd9Sstevel@tonic-gate		TZ_for_date=$TZ;;
1897c478bd9Sstevel@tonic-gate	*)
1907c478bd9Sstevel@tonic-gate		# Get list of names of countries in the continent or ocean.
1917c478bd9Sstevel@tonic-gate		countries=$($AWK -F'\t' \
1927c478bd9Sstevel@tonic-gate			-v continent="$continent" \
1937c478bd9Sstevel@tonic-gate			-v TZ_COUNTRY_TABLE="$TZ_COUNTRY_TABLE" \
1947c478bd9Sstevel@tonic-gate		'
1957c478bd9Sstevel@tonic-gate			/^#/ { next }
1967c478bd9Sstevel@tonic-gate			$3 ~ ("^" continent "/") {
1977c478bd9Sstevel@tonic-gate				if (!cc_seen[$1]++) cc_list[++ccs] = $1
1987c478bd9Sstevel@tonic-gate			}
1997c478bd9Sstevel@tonic-gate			END {
2007c478bd9Sstevel@tonic-gate				while (getline <TZ_COUNTRY_TABLE) {
2017c478bd9Sstevel@tonic-gate					if ($0 !~ /^#/) cc_name[$1] = $2
2027c478bd9Sstevel@tonic-gate				}
2037c478bd9Sstevel@tonic-gate				for (i = 1; i <= ccs; i++) {
2047c478bd9Sstevel@tonic-gate					country = cc_list[i]
2057c478bd9Sstevel@tonic-gate					if (cc_name[country]) {
2067c478bd9Sstevel@tonic-gate					  country = cc_name[country]
2077c478bd9Sstevel@tonic-gate					}
2087c478bd9Sstevel@tonic-gate					print country
2097c478bd9Sstevel@tonic-gate				}
2107c478bd9Sstevel@tonic-gate			}
2117c478bd9Sstevel@tonic-gate		' <$TZ_ZONE_TABLE | $SORT -f)
2127c478bd9Sstevel@tonic-gate
2137c478bd9Sstevel@tonic-gate		# i18n country names
2147c478bd9Sstevel@tonic-gate		c=0
2157c478bd9Sstevel@tonic-gate		set -A icountry
2167c478bd9Sstevel@tonic-gate		for country in $countries
2177c478bd9Sstevel@tonic-gate		do
2187c478bd9Sstevel@tonic-gate			if [ $is_C -eq 1 ]; then
2197c478bd9Sstevel@tonic-gate				icountry[c]=$country
2207c478bd9Sstevel@tonic-gate			else
2217c478bd9Sstevel@tonic-gate				icountry[c]=`${GETTEXT} ${DOMAIN2} $country`
2227c478bd9Sstevel@tonic-gate			fi
2237c478bd9Sstevel@tonic-gate			ocountry[c]="$country"
2247c478bd9Sstevel@tonic-gate			c=$(( $c + 1 ))
2257c478bd9Sstevel@tonic-gate		done
2267c478bd9Sstevel@tonic-gate		maxnum=$c
2277c478bd9Sstevel@tonic-gate
2287c478bd9Sstevel@tonic-gate		# If there's more than one country, ask the user which one.
2297c478bd9Sstevel@tonic-gate		case $countries in
2307c478bd9Sstevel@tonic-gate		*"$newline"*)
2317c478bd9Sstevel@tonic-gate			$PRINTF >&2 "`$GETTEXT "$INFO_SELECT_CNTRY"`\n"
2327c478bd9Sstevel@tonic-gate			select xcountry in ${icountry[*]}
2337c478bd9Sstevel@tonic-gate			do
2347c478bd9Sstevel@tonic-gate			    case $xcountry in
2357c478bd9Sstevel@tonic-gate			    '')
2367c478bd9Sstevel@tonic-gate				$PRINTF >&2 "`$GETTEXT "$WARN_ENTER_NUM"`\n"
2377c478bd9Sstevel@tonic-gate				;;
2387c478bd9Sstevel@tonic-gate			    ?*)   c=0
2397c478bd9Sstevel@tonic-gate				  while true; do
2407c478bd9Sstevel@tonic-gate                		    if [ "$xcountry" = "${icountry[$c]}" ];
2417c478bd9Sstevel@tonic-gate				    then
2427c478bd9Sstevel@tonic-gate					    country="${ocountry[$c]}"
2437c478bd9Sstevel@tonic-gate                        		    break
2447c478bd9Sstevel@tonic-gate                		    fi
2457c478bd9Sstevel@tonic-gate                		    if [ $c -lt $maxnum ]; then
2467c478bd9Sstevel@tonic-gate					    c=$(( $c + 1 ))
2477c478bd9Sstevel@tonic-gate                		    else
2487c478bd9Sstevel@tonic-gate                        		    break
2497c478bd9Sstevel@tonic-gate                		    fi
2507c478bd9Sstevel@tonic-gate        		         done
2517c478bd9Sstevel@tonic-gate				 break
2527c478bd9Sstevel@tonic-gate			     esac
2537c478bd9Sstevel@tonic-gate			done
2547c478bd9Sstevel@tonic-gate
2557c478bd9Sstevel@tonic-gate			case $xcountry in
2567c478bd9Sstevel@tonic-gate			'') exit 1
2577c478bd9Sstevel@tonic-gate			esac;;
2587c478bd9Sstevel@tonic-gate		*)
2597c478bd9Sstevel@tonic-gate			country=$countries
2607c478bd9Sstevel@tonic-gate			xcountry=$countries
2617c478bd9Sstevel@tonic-gate		esac
2627c478bd9Sstevel@tonic-gate
2637c478bd9Sstevel@tonic-gate
2647c478bd9Sstevel@tonic-gate		# Get list of names of time zone rule regions in the country.
2657c478bd9Sstevel@tonic-gate		regions=$($AWK -F'\t' \
2667c478bd9Sstevel@tonic-gate			-v country="$country" \
2677c478bd9Sstevel@tonic-gate			-v TZ_COUNTRY_TABLE="$TZ_COUNTRY_TABLE" \
2687c478bd9Sstevel@tonic-gate		'
2697c478bd9Sstevel@tonic-gate			BEGIN {
2707c478bd9Sstevel@tonic-gate				cc = country
2717c478bd9Sstevel@tonic-gate				while (getline <TZ_COUNTRY_TABLE) {
2727c478bd9Sstevel@tonic-gate					if ($0 !~ /^#/  &&  country == $2) {
2737c478bd9Sstevel@tonic-gate						cc = $1
2747c478bd9Sstevel@tonic-gate						break
2757c478bd9Sstevel@tonic-gate					}
2767c478bd9Sstevel@tonic-gate				}
2777c478bd9Sstevel@tonic-gate			}
2787c478bd9Sstevel@tonic-gate			$1 == cc { print $5 }
2797c478bd9Sstevel@tonic-gate		' <$TZ_ZONE_TABLE)
2807c478bd9Sstevel@tonic-gate
2817c478bd9Sstevel@tonic-gate		# I18n region names
2827c478bd9Sstevel@tonic-gate		c=0
2837c478bd9Sstevel@tonic-gate		set -A iregion
2847c478bd9Sstevel@tonic-gate		for region in $regions
2857c478bd9Sstevel@tonic-gate		do
2867c478bd9Sstevel@tonic-gate			if [ $is_C -eq 1 ]; then
2877c478bd9Sstevel@tonic-gate				iregion[c]=$region
2887c478bd9Sstevel@tonic-gate			else
2897c478bd9Sstevel@tonic-gate				iregion[c]=`${GETTEXT} ${DOMAIN2} $region`
2907c478bd9Sstevel@tonic-gate			fi
2917c478bd9Sstevel@tonic-gate			oregion[c]="$region"
2927c478bd9Sstevel@tonic-gate			c=$(( $c + 1 ))
2937c478bd9Sstevel@tonic-gate		done
2947c478bd9Sstevel@tonic-gate		maxnum=$c
2957c478bd9Sstevel@tonic-gate
2967c478bd9Sstevel@tonic-gate		# If there's more than one region, ask the user which one.
2977c478bd9Sstevel@tonic-gate		case $regions in
2987c478bd9Sstevel@tonic-gate		*"$newline"*)
2997c478bd9Sstevel@tonic-gate			$PRINTF >&2 "`$GETTEXT "$INFO_SELECT_TZ"`\n"
3007c478bd9Sstevel@tonic-gate
3017c478bd9Sstevel@tonic-gate			select xregion in ${iregion[*]}
3027c478bd9Sstevel@tonic-gate			do
3037c478bd9Sstevel@tonic-gate				case $xregion in
3047c478bd9Sstevel@tonic-gate				'')
3057c478bd9Sstevel@tonic-gate				$PRINTF >&2 "`$GETTEXT "$WARN_ENTER_NUM"`\n"
3067c478bd9Sstevel@tonic-gate				;;
3077c478bd9Sstevel@tonic-gate				?*) c=0
3087c478bd9Sstevel@tonic-gate                                    while true; do
3097c478bd9Sstevel@tonic-gate                                       if [ "$xregion" = "${iregion[$c]}" ];
3107c478bd9Sstevel@tonic-gate				       then
3117c478bd9Sstevel@tonic-gate                                            region="${oregion[$c]}"
3127c478bd9Sstevel@tonic-gate                                            break
3137c478bd9Sstevel@tonic-gate                                       fi
3147c478bd9Sstevel@tonic-gate                                       if [ $c -lt $maxnum ]; then
3157c478bd9Sstevel@tonic-gate					    c=$(( $c + 1 ))
3167c478bd9Sstevel@tonic-gate                                       else
3177c478bd9Sstevel@tonic-gate                                            break
3187c478bd9Sstevel@tonic-gate                                       fi
3197c478bd9Sstevel@tonic-gate                                    done
3207c478bd9Sstevel@tonic-gate				    break
3217c478bd9Sstevel@tonic-gate				esac
3227c478bd9Sstevel@tonic-gate			done
3237c478bd9Sstevel@tonic-gate
3247c478bd9Sstevel@tonic-gate			case $region in
3257c478bd9Sstevel@tonic-gate			'') exit 1
3267c478bd9Sstevel@tonic-gate			esac;;
3277c478bd9Sstevel@tonic-gate		*)
3287c478bd9Sstevel@tonic-gate			region=$regions
3297c478bd9Sstevel@tonic-gate			xregion=$regions
3307c478bd9Sstevel@tonic-gate		esac
3317c478bd9Sstevel@tonic-gate
3327c478bd9Sstevel@tonic-gate		# Determine TZ from country and region.
3337c478bd9Sstevel@tonic-gate		TZ=$($AWK -F'\t' \
3347c478bd9Sstevel@tonic-gate			-v country="$country" \
3357c478bd9Sstevel@tonic-gate			-v region="$region" \
3367c478bd9Sstevel@tonic-gate			-v TZ_COUNTRY_TABLE="$TZ_COUNTRY_TABLE" \
3377c478bd9Sstevel@tonic-gate		'
3387c478bd9Sstevel@tonic-gate			BEGIN {
3397c478bd9Sstevel@tonic-gate				cc = country
3407c478bd9Sstevel@tonic-gate				while (getline <TZ_COUNTRY_TABLE) {
3417c478bd9Sstevel@tonic-gate					if ($0 !~ /^#/  &&  country == $2) {
3427c478bd9Sstevel@tonic-gate						cc = $1
3437c478bd9Sstevel@tonic-gate						break
3447c478bd9Sstevel@tonic-gate					}
3457c478bd9Sstevel@tonic-gate				}
3467c478bd9Sstevel@tonic-gate			}
3477c478bd9Sstevel@tonic-gate
3487c478bd9Sstevel@tonic-gate			$1 == cc && $5 == region {
3497c478bd9Sstevel@tonic-gate				# Check if tzname mapped to
3507c478bd9Sstevel@tonic-gate				# backward compatible tzname
3517c478bd9Sstevel@tonic-gate				if ($4 == "-") {
3527c478bd9Sstevel@tonic-gate					print $3
3537c478bd9Sstevel@tonic-gate				} else {
3547c478bd9Sstevel@tonic-gate					print $4
3557c478bd9Sstevel@tonic-gate				}
3567c478bd9Sstevel@tonic-gate			}
3577c478bd9Sstevel@tonic-gate		' <$TZ_ZONE_TABLE)
3587c478bd9Sstevel@tonic-gate
3597c478bd9Sstevel@tonic-gate		# Make sure the corresponding zoneinfo file exists.
3607c478bd9Sstevel@tonic-gate		TZ_for_date=$TZDIR/$TZ
3617c478bd9Sstevel@tonic-gate		<$TZ_for_date || {
3627c478bd9Sstevel@tonic-gate			$PRINTF >&2 "`$GETTEXT "$ERR_NO_SETUP"`\n" $0
3637c478bd9Sstevel@tonic-gate			exit 1
3647c478bd9Sstevel@tonic-gate		}
3657c478bd9Sstevel@tonic-gate		# Absolute path TZ's not supported
3667c478bd9Sstevel@tonic-gate		TZ_for_date=$TZ
3677c478bd9Sstevel@tonic-gate	esac
3687c478bd9Sstevel@tonic-gate
3697c478bd9Sstevel@tonic-gate
3707c478bd9Sstevel@tonic-gate	# Use the proposed TZ to output the current date relative to UTC.
3717c478bd9Sstevel@tonic-gate	# Loop until they agree in seconds.
3727c478bd9Sstevel@tonic-gate	# Give up after 8 unsuccessful tries.
3737c478bd9Sstevel@tonic-gate
3747c478bd9Sstevel@tonic-gate	extra_info1=
3757c478bd9Sstevel@tonic-gate	extra_info2=
3767c478bd9Sstevel@tonic-gate	for i in 1 2 3 4 5 6 7 8
3777c478bd9Sstevel@tonic-gate	do
3787c478bd9Sstevel@tonic-gate		TZdate=$(LANG=C TZ="$TZ_for_date" $DATE)
3797c478bd9Sstevel@tonic-gate		UTdate=$(LANG=C TZ=UTC0 $DATE)
3807c478bd9Sstevel@tonic-gate		TZsec=$($EXPR "$TZdate" : '.*:\([0-5][0-9]\)')
3817c478bd9Sstevel@tonic-gate		UTsec=$($EXPR "$UTdate" : '.*:\([0-5][0-9]\)')
3827c478bd9Sstevel@tonic-gate		case $TZsec in
3837c478bd9Sstevel@tonic-gate		$UTsec)
3847c478bd9Sstevel@tonic-gate			extra_info1=$($PRINTF "`$GETTEXT "$INFO_EXTRA1"`" \
3857c478bd9Sstevel@tonic-gate			"$TZdate")
3867c478bd9Sstevel@tonic-gate			extra_info2=$($PRINTF "`$GETTEXT "$INFO_EXTRA2"`" \
3877c478bd9Sstevel@tonic-gate			"$UTdate")
3887c478bd9Sstevel@tonic-gate			break
3897c478bd9Sstevel@tonic-gate		esac
3907c478bd9Sstevel@tonic-gate	done
3917c478bd9Sstevel@tonic-gate
3927c478bd9Sstevel@tonic-gate
3937c478bd9Sstevel@tonic-gate	# Output TZ info and ask the user to confirm.
3947c478bd9Sstevel@tonic-gate
3957c478bd9Sstevel@tonic-gate	$PRINTF >&2 "\n"
3967c478bd9Sstevel@tonic-gate	$PRINTF >&2 "`$GETTEXT "$INFO_INFO"`\n"
3977c478bd9Sstevel@tonic-gate	$PRINTF >&2 "\n"
3987c478bd9Sstevel@tonic-gate
3997c478bd9Sstevel@tonic-gate	case $country+$region in
4007c478bd9Sstevel@tonic-gate	?*+?*)	$PRINTF >&2 "	$xcountry$newline	$xregion\n";;
4017c478bd9Sstevel@tonic-gate	?*+)	$PRINTF >&2 "	$xcountry\n";;
4027c478bd9Sstevel@tonic-gate	+)	$PRINTF >&2 "	TZ='$TZ'\n"
4037c478bd9Sstevel@tonic-gate	esac
4047c478bd9Sstevel@tonic-gate	$PRINTF >&2 "\n"
4057c478bd9Sstevel@tonic-gate	$PRINTF >&2 "`$GETTEXT "$INFO_TZ"`\n" "$TZ"
4067c478bd9Sstevel@tonic-gate	$PRINTF >&2 "$extra_info1\n"
4077c478bd9Sstevel@tonic-gate	$PRINTF >&2 "$extra_info2\n"
4087c478bd9Sstevel@tonic-gate	$PRINTF >&2 "`$GETTEXT "$INFO_OK"`\n"
4097c478bd9Sstevel@tonic-gate
4107c478bd9Sstevel@tonic-gate	ok=
4117c478bd9Sstevel@tonic-gate	# select ok in Yes No
4127c478bd9Sstevel@tonic-gate	Yes="`$GETTEXT "$INFO_YES"`"
4137c478bd9Sstevel@tonic-gate	No="`$GETTEXT "$INFO_NO"`"
4147c478bd9Sstevel@tonic-gate	select ok in $Yes $No
4157c478bd9Sstevel@tonic-gate	do
4167c478bd9Sstevel@tonic-gate	    case $ok in
4177c478bd9Sstevel@tonic-gate	    '')
4187c478bd9Sstevel@tonic-gate		$PRINTF >&2 "`$GETTEXT "$WARN_ENTER_YORN"`\n"
4197c478bd9Sstevel@tonic-gate		;;
4207c478bd9Sstevel@tonic-gate	    ?*) break
4217c478bd9Sstevel@tonic-gate	    esac
4227c478bd9Sstevel@tonic-gate	done
4237c478bd9Sstevel@tonic-gate	case $ok in
4247c478bd9Sstevel@tonic-gate	'') exit 1;;
4257c478bd9Sstevel@tonic-gate	$Yes) break
4267c478bd9Sstevel@tonic-gate	esac
4277c478bd9Sstevel@tonic-gatedo :
4287c478bd9Sstevel@tonic-gatedone
4297c478bd9Sstevel@tonic-gate
4307c478bd9Sstevel@tonic-gate$PRINTF >&2 "`$GETTEXT "$INFO_FINE"`\n"
4317c478bd9Sstevel@tonic-gate
4327c478bd9Sstevel@tonic-gate$PRINTF "%s\n" "$TZ"
433