File: clock-setup.postinst

package info (click to toggle)
clock-setup 0.97lenny1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 588 kB
  • ctags: 9
  • sloc: sh: 155; makefile: 32; ansic: 28
file content (72 lines) | stat: -rwxr-xr-x 1,426 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
#!/bin/sh
set -e

. /usr/share/debconf/confmodule

log() {
	logger -t clock-setup "$@"
}

db_input medium clock-setup/ntp || true
if ! db_go; then
	exit 10 # back to main menu
fi
db_get clock-setup/ntp
if [ "$RET" = true ]; then
	db_get netcfg/dhcp_ntp_servers
	if [ -n "$RET" ]; then
		# If DHCP provides multiple servers, ignore all but the first
		dhcp_ntp=`echo "$RET" | cut -d' ' -f1`
		db_set clock-setup/ntp-server "$dhcp_ntp"
	fi
	db_input low clock-setup/ntp-server || true
	if ! db_go; then
		exit 10
	fi
	db_get clock-setup/ntp-server
	server="$RET"

	# Workaround for rdate failing if current date is before
	# the epoch (1-1-1970); see #502336
	case "$(archdetect)" in
	    kfreebsd*) : ;;
	    *) log-output -t clock-setup set-date-epoch ;;
	esac

	db_capb progresscancel
	db_progress START 0 30 clock-setup/progress/title
	db_progress INFO clock-setup/progress/ntp
	i=0
	exec 4>&0
	rdate -o 123 -nvv "$server" 2>&1 |
	while read line; do
		if ! db_progress set $i <&4; then
			log "rdate canceled."
			break
		fi
		case "$line" in
		    '.')
			i=$(($i + 1))
			;;
		    *:*:*)
			# new date
			log "$line"
			;;
		    'rdate: adjust'*)
			log "$line"
			# success
			db_progress set 30 <&4 || true
			;;
		    *)
			log "$line"
			# After an error rdate might exit or skip to the next
			# server.  In both case, let's reset the progress bar.
			i=0
			;;
		esac
	done
	exec 0>&4
	db_progress stop
fi

tzsetup