[go: up one dir, main page]

File: ntzconfig

package info (click to toggle)
glibc 2.1.3-20
  • links: PTS
  • area: main
  • in suites: potato
  • size: 7,512 kB
  • ctags: 161
  • sloc: sh: 8,850; makefile: 288
file content (199 lines) | stat: -rw-r--r-- 5,069 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#! /bin/sh
set -e

show_continents() {

cat <<EOF

Please enter the number of the geographic area in which you live:


	1) Africa			7) Australia

	2) America			8) Europe

	3) US time zones		9) Indian Ocean

	4) Canada time zones		10) Pacific Ocean

	5) Asia				11) Use System V style time zones

	6) Atlantic Ocean		12) None of the above


Then you will be shown a list of cities which represent the time zone
in which they are located. You should choose a city in your time zone.

EOF

until [ have_continent = yes ]
do
    echo -n "Number: " ; read area
    case $area in
	1) continent=Africa    ; have_continent=yes ;;
	2) continent=America   ; have_continent=yes ;;
	3) continent=US        ; have_continent=yes ;;
	4) continent=Canada    ; have_continent=yes ;;
	5) continent=Asia      ; have_continent=yes ;;
	6) continent=Atlantic  ; have_continent=yes ;;
	7) continent=Australia ; have_continent=yes ;;
	8) continent=Europe    ; have_continent=yes ;;
	9) continent=Indian    ; have_continent=yes ;;
       10) continent=Pacific   ; have_continent=yes ;;
       11) continent=SystemV   ; have_continent=yes ;;
       12) continent=Etc       ; have_continent=yes ;;
    esac
}

zone_info()
{
    extra_info=
    for i in 1 2 3 4 5 6 7 8
    do
	TZdate=$(LANG=C TZ="$timezone" date)
	UTdate=$(LANG=C TZ=UTC0 date)
	TZsec=$(expr "$TZdate" : '.*:\([0-5][0-9]\)')
	UTsec=$(expr "$UTdate" : '.*:\([0-5][0-9]\)')
	case $TZsec in
	    $UTsec)
		    extra_info="
Local time is now:      $TZdate.
Universal Time is now:  $UTdate."
		    break
	    esac
	done
}

show_usage() {
cat <<EOF
Usage: tzconfig [OPTION]

    -c, --check       Verify current timezone setting.
    -s, --set         Set timezone, ignoring current setting (if any).
    -h, --help        Give this help message.
EOF
}
valid_timezone() {
    if [ -f /usr/share/zoneinfo/$1 ] && [ $1 != "Factory" ]
}

update_localtime() {
    if valid_timezone $timezone
    then
	rm -f /etc/localtime
	cp /usr/share/zoneinfo/$timezone /etc/localtime
    fi
    # Handle problem caused by lame old tzconfig.
    elif [ "$timezone" = "US/Pacific-New" ]
    then
	echo "US/Pacific" > /etc/timezone
	rm -f /etc/localtime
	cp /usr/share/zoneinfo/US/Pacific /etc/localtime
    fi
}

set_timezone() {
    until valid_timezone $timezone
    do
	query_timezone
    done
}
if [ "$(id -u)" != "0" ]; then
    non_root=1
fi

if [ $# -eq 0 ] || [ $1 = "--help" ]; then
    show_help
fi

case "$1" in
    -c|--check)
	check_timezone
    ;;
    -s|--set)
	set_timezone
    ;;
    -u|--update)
	check_timezone
	update_localtime
    ;;
    -h|--help|*)
	show_usage
    ;;

TIMEZONES=$(tempfile -p time) || TIMEZONES=/etc/timezone.$$

if [ -f /etc/timezone ]; then
	echo "Your current time zone is set to `cat /etc/timezone`"
	echo -n "Do you want to change that? [n]: "
	read ans
	if [ "x$ans" = "x" -o "$ans" = "n" -o "$ans" = "no" ]; then
		echo "Your time zone will not be changed"
		exit 0
	fi
fi

query_timezone() {
    ( cd /usr/share/zoneinfo ; find . -type f | sed -e 's/^.\///' | sort > $TIMEZONES )
    valid=no
    while [ $have_zone = no ]; do
	    show_continents
	    echo -n "Number: " ; read area
	    case $area in
		    1) continent=Africa ; have_continent=yes ;;
		    2) continent=America ; have_continent=yes ;;
		    3) continent=US ; have_continent=yes ;;
		    4) continent=Canada ; have_continent=yes ;;
		    5) continent=Asia ; have_continent=yes ;;
		    6) continent=Atlantic ; have_continent=yes ;;
		    7) continent=Australia ; have_continent=yes ;;
		    8) continent=Europe ; have_continent=yes ;;
		    9) continent=Indian ; have_continent=yes ;;
		    10) continent=Pacific ; have_continent=yes ;;
		    11) continent=SystemV ; have_continent=yes ;;
		    12) continent=Etc ; have_continent=yes ;;
	    esac
    done

if [ -x /usr/bin/fmt ]; then fmt_bin=/usr/bin/fmt
else fmt_bin=/bin/more ; fi

valid=no
zone=""

while [ $valid = no ]; do
	if [ -n "$zone" ]; then
		number=`grep -i -c "^$continent/$zone" $TIMEZONES`
		if [ $number -eq 1 ]; then
			timezone=`grep -i "^$continent/$zone" $TIMEZONES`
			zone_info
			echo "Your default time zone is set to '$timezone'.$extra_info"
			valid=yes
			break
		fi
	fi
	echo
	grep -i "^$continent/$zone" $TIMEZONES | cut -d/ -f2- | $fmt_bin
	echo
	echo "Please enter the name of one of these cities or zones"
	echo "You just need to type enough letters to resolve ambiguities"
	echo "Press Enter to view all of them again"
	echo -n "Name: [$zone] " ; read zone
done

if [ "$non_root" -ne 1 ]; then
    echo $timezone > /etc/timezone
    test -d /etc/default || mkdir -m 755 /etc/default
    echo $timezone > /etc/default/timezone
    rm -f /etc/localtime
    cp /usr/share/zoneinfo/$timezone /etc/localtime
    #ln -sf $timezone /usr/share/zoneinfo/localtime
else
    export TZ=$timezone
    echo "You need to place the following in your shell's"
    echo "startup file (which one, depends on the shell):"
    echo "'export TZ=$timezone' (sh-style shells) or"
    echo "'setenv TZ $timezone' (csh-style shells)."
fi

trap 'rm -f $TIMEZONES' 0 1 2 3 13 15