[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

debconf tzconfig



As requested, here is a tzconfig varient that uses debconf for its UI. A
sample run (note that new installers will be seeing the dialog frontend
instead):


root@silk:/home/joey/debian/packages/base-config>./newtzconfig     
Time Zone Configuration
-----------------------

Your current time zone is set to US/Eastern.

Do you want to change your current time zone? y 

Pick the geographic area in which you live.

  1. Africa             5. Asia            9. Indian Ocean
  2. America            6. Atlantic Ocean  10. Pacific Ocean
  3. US time zones      7. Australia       11. System V style time zones
  4. Canada time zones  8. Europe          12. None of the above
What area do you live in? US

Cities represent the time zone in which they are located, so you may choose any
city in your time zone.

  1. Alaska    4. Central       7. Hawaii          10. Mountain
  2. Aleutian  5. East-Indiana  8. Indiana-Starke  11. Pacific
  3. Arizona   6. Eastern       9. Michigan        12. Samoa
Select a city or time zone: eastern

Time zone selected.


 Local time is now:          Sun Jun 10 17:22:34 PDT 2001
 Universal Time is now:      Mon Jun 11 00:22:34 UTC 2001
 You selected the time zone: US/Pacific
root@silk:/home/joey/debian/packages/base-config>

If you want to try it, you should probably install debconf 0.9.63 from
Incoming. It tickles an obscure debconf bug fixed by that version.

I have not figured out where this program should live. It'd be sorta cool
if it could replace the current tzconfig, though libc6 would need to
suggest/reccommend debconf then. Or I can stick it in base-config for the
time being.

-- 
see shy jo
#! /bin/sh

. /usr/share/debconf/confmodule

DIRS="Africa America US Canada Asia Atlantic Australia Europe Indian Pacific SystemV Etc"

# Set up debconf.
db_capb backup
db_title "Time Zone Configuration"

# Feed current timezone in to question.
if [ -f /etc/timezone ]; then
	db_subst tzconfig/change_timezone timezone `cat /etc/timezone`
elif [ -L /etc/localtime ]; then
	db_subst tzconfig/change_timezone timezone \
		$(readlink /etc/localtime | sed 's%^/usr/share/zoneinfo/%%')	
fi

# Instantiate zone selection questions for each geographic area. The names
# of the questions will be the same as the names of the relevant directories
# in /usr/share/zoneinfo/, and the choices will be each file in the directory.
for dir in $DIRS; do
	db_register tzconfig/select_zone tzconfig/select_zone/$dir || true
	db_subst tzconfig/select_zone/$dir choices \
		$(find /usr/share/zoneinfo/$dir -type f -printf "%f, \n" | \
		  sort | xargs echo | sed 's/,$//')
done

# Let's use a state machine to let the user jump back to earlier questions.
STATE=1
while [ "$STATE" != 0 -a "$STATE" != 5 ]; do
	case "$STATE" in
	1)
		# Give current time zone and ask if it should be changed.
		db_fset tzconfig/change_timezone seen false
		db_input medium tzconfig/change_timezone || true
	;;
	2)
		# Exit if the user doesn't want the time zone changed.
		db_get tzconfig/change_timezone
		if [ "$RET" = false ]; then
			exit
		fi

		# Show top level divisions (mainly by continent).
		db_fset tzconfig/geographic_area seen false
		db_input high tzconfig/geographic_area || true
	;;
	3)
		# Prompt with a list of zones in the selected area.
		# Suckily, we have to map some of the values that were
		# prompted with to the directory names themselves.
		db_get tzconfig/geographic_area
		DIR="$RET"
		case "$DIR" in
		"Atlantic Ocean")		DIR=Atlantic	;;
		"Indian Ocean")			DIR=Indian	;;
		"Pacific Ocean")		DIR=Pacific	;;
		"System V style time zones")	DIR=SystemV	;;
		"None of the above")		DIR=Etc		;;
		esac
		if [ ! -d /usr/share/zoneinfo/$DIR ]; then
			echo "$0 internal error: /usr/share/zoneinfo/$DIR does not exist" >&2
			exit 1
		fi

		db_fset tzconfig/select_zone/$DIR seen false
		db_input high tzconfig/select_zone/$DIR || true
	;;
	4)
		# Display a final message giving the selected zone
		# and showing the time in that zone (and UTC for
		# comparison).
		db_get tzconfig/select_zone/$DIR
		timezone="$DIR/$RET"
		utdate=$(LANG=C TZ=UTC0 date)
		tzdate=$(LANG=C TZ="$timezone" date -d "$utdate")
		db_subst tzconfig/settings timezone $timezone
		db_subst tzconfig/settings tzdate "$tzdate"
		db_subst tzconfig/settings utdate $utdate
		db_fset tzconfig/settings seen false
		db_input medium tzconfig/settings || true
	;;
	esac

	if db_go; then
		STATE=$(($STATE + 1))
	else
		STATE=$(($STATE - 1))
	fi
done

# Unregister some of the things that were set up, as there is no reason to
# keep them in the debconf db.
for dir in $DIRS; do
	#db_unregister tzconfig/select_zone/$dir || true
done

db_get tzconfig/change_timezone
if [ "$RET" = true ]; then
	echo $timezone > /etc/timezone 
	rm -f /etc/localtime && \
		ln -sf /usr/share/zoneinfo/$timezone /etc/localtime
fi
Template: tzconfig/change_timezone
Type: boolean
Default: false
Description: Do you want to change your current time zone?
 Your current time zone is set to ${timezone}.

Template: tzconfig/geographic_area
Type: select
Choices: Africa, America, US, Canada, Asia, Atlantic Ocean, Australia, Europe, Indian Ocean, Pacific Ocean, System V style time zones, None of the above
Description: What area do you live in?
 Pick the geographic area in which you live.

Template: tzconfig/select_zone
Type: select
Choices: ${choices}
Description: Select a city or time zone:
 Cities represent the time zone in which they are located, so you may choose
 any city in your time zone.

Template: tzconfig/settings
Type: note
Description: Time zone selected.
  Local time is now:          ${tzdate}
  Universal Time is now:      ${utdate}
  You selected the time zone: ${timezone}

Reply to: