home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / sbin / tzconfig < prev    next >
Encoding:
Text File  |  2007-04-04  |  3.0 KB  |  122 lines

  1. #! /bin/sh
  2.  
  3. # Copyright (C) 2001 Software in the Public Interest
  4. #
  5. # Licensed under the GPL v2
  6. #
  7.  
  8. show_continents() {
  9.  
  10. cat <<EOF
  11.  
  12. Please enter the number of the geographic area in which you live:
  13.  
  14.  
  15.     1) Africa            7) Australia
  16.  
  17.     2) America            8) Europe
  18.  
  19.     3) US time zones        9) Indian Ocean
  20.  
  21.     4) Canada time zones        10) Pacific Ocean
  22.  
  23.     5) Asia                11) Use System V style time zones
  24.  
  25.     6) Atlantic Ocean        12) None of the above
  26.  
  27.  
  28. Then you will be shown a list of cities which represent the time zone
  29. in which they are located. You should choose a city in your time zone.
  30.  
  31. EOF
  32.  
  33. }
  34.  
  35. zone_info()
  36. {
  37.     TZBase=$(LC_ALL=C TZ=UTC0 date)
  38.     UTdate=$(TZ=UTC0 date -d "$TZBase")
  39.     TZdate=$(TZ="$timezone" date -d "$TZBase")
  40.     extra_info="
  41. Local time is now:      $TZdate.
  42. Universal Time is now:  $UTdate."
  43. }
  44.  
  45. TIMEZONES=$(tempfile -p time) || TIMEZONES=/etc/timezone.$$
  46.  
  47. if [ -f /etc/timezone ] || [ -f /etc/localtime ] ; then
  48.         current_timezone="Unknown"
  49.     if [ -L /etc/localtime ] ; then
  50.         current_timezone=$(readlink /etc/localtime | sed 's%^/usr/share/zoneinfo/%%')
  51.     elif [ -f /etc/timezone ] && [ -f /etc/localtime ]; then
  52.         current_timezone=$(cat /etc/timezone)
  53.     fi
  54.     
  55.     echo "Your current time zone is set to $current_timezone"
  56.     echo -n "Do you want to change that? [n]: "
  57.     read ans
  58.     if [ "x$ans" = "x" ] || [ "$ans" = "n" ] || [ "$ans" = "no" ]; then
  59.         echo "Your time zone will not be changed"
  60.         exit 0
  61.     fi
  62. fi
  63.  
  64. ( cd /usr/share/zoneinfo ; find . -type f | sed -e 's/^.\///' | sort > $TIMEZONES )
  65. valid=no
  66. while [ $valid = no ]; do
  67.     show_continents
  68.     echo -n "Number: " ; read area
  69.     case $area in
  70.         1) continent=Africa ; valid=yes ;;
  71.         2) continent=America ; valid=yes ;;
  72.         3) continent=US ; valid=yes ;;
  73.         4) continent=Canada ; valid=yes ;;
  74.         5) continent=Asia ; valid=yes ;;
  75.         6) continent=Atlantic ; valid=yes ;;
  76.         7) continent=Australia ; valid=yes ;;
  77.         8) continent=Europe ; valid=yes ;;
  78.         9) continent=Indian ; valid=yes ;;
  79.         10) continent=Pacific ; valid=yes ;;
  80.         11) continent=SystemV ; valid=yes ;;
  81.         12) continent=Etc ; valid=yes ;;
  82.     esac
  83. done
  84.  
  85. if [ -x /usr/bin/fmt ]; then fmt_bin=/usr/bin/fmt
  86. else fmt_bin=/bin/more ; fi
  87.  
  88. valid=no
  89. zone=""
  90.  
  91. while [ $valid = no ]; do
  92.     if [ -n "$zone" ]; then
  93.         # We accept the zone if either it is an unambiguous prefix, or
  94.         # it is a complete zone name.
  95.         number=`grep -i -c "^$continent/$zone" $TIMEZONES`
  96.         if [ $number -eq 1 ]; then
  97.             timezone=`grep -i "^$continent/$zone" $TIMEZONES`
  98.         else
  99.             timezone=`grep -i -s "^$continent/$zone"'$' $TIMEZONES`
  100.         fi
  101.  
  102.         if [ -n "$timezone" ]; then
  103.             zone_info
  104.             echo "Your default time zone is set to '$timezone'.$extra_info"
  105.             valid=yes
  106.             break
  107.         fi
  108.     fi
  109.     echo
  110.     grep -i "^$continent/$zone" $TIMEZONES | cut -d/ -f2- | $fmt_bin
  111.     echo
  112.     echo "Please enter the name of one of these cities or zones"
  113.     echo "You just need to type enough letters to resolve ambiguities"
  114.     echo "Press Enter to view all of them again"
  115.     echo -n "Name: [$zone] " ; read zone
  116. done
  117.  
  118. umask 022
  119. echo $timezone > /etc/timezone 
  120. rm -f /etc/localtime && cp -f /usr/share/zoneinfo/$timezone /etc/localtime
  121. trap 'rm -f $TIMEZONES' 0 1 2 3 13 15
  122.