File: 10clock-setup

package info (click to toggle)
clock-setup 0.123
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 688 kB
  • ctags: 19
  • sloc: sh: 190; makefile: 36; ansic: 28
file content (154 lines) | stat: -rwxr-xr-x 3,255 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
#!/bin/sh
set -e

. /usr/share/debconf/confmodule

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

arch_has_os_needing_local_clock () {
	# keep in sync with arches that can run OSs matched by
	# os_needs_local_clock
	case "$(udpkg --print-architecture)" in
	*i386*|*amd64*|*ia64*)
		return 0
	;;
	esac
	return 1
}

os_needs_local_clock () {
	while read line; do
		shortname=$(echo "$line" | cut -d : -f 3)
		case $shortname in
		MS-DOS*|Windows*|FreeDOS*) # keep in sync with os-prober
			return 0
		;;
		Solaris*)
			case "$(udpkg --print-architecture)" in
			*i386*|*amd64*)
				return 0
			;;
			esac
		;;
		esac
	done
	return 1
}

hwclock_prepare () {
	anna-install rtc-modules || true

	# This may not be necessary on all hardware; hwclock can do direct IO
	# if the rtc module is not loaded.
	log-output -t hw-detect modprobe -v rtc || log "rtc module not loaded"
	log-output -t hw-detect modprobe -v rtc-dev || log "rtc-dev module not loaded"
	update-dev --settle
}

hwclock_stop () {
	kill $pid || return
	sleep 1
	if [ -e /proc/$pid ]; then
		kill -9 $pid || return
	fi
}

pri=high

if db_fget clock-setup/utc seen && [ "$RET" = true ]; then
	# keep preseeded value
	:
else
	probed=""

	if arch_has_os_needing_local_clock; then
		# os-prober may not yet be installed...
		anna-install os-prober-udeb || true
	
		probed=$(os-prober) || true
	
		if echo "$probed" | os_needs_local_clock; then
			# default to localtime for some OSes
			db_set clock-setup/utc false
			pri=low
		fi
	fi

	if [ -z "$probed" ]; then
		# installing the only OS, so use UTC
		db_set clock-setup/utc true
		pri=low
	fi
fi

db_input $pri clock-setup/utc || true
if ! db_go; then
	exit 10 # back to main menu
fi

# Update target system configuration for utc/localtime selection
utcfile=/target/etc/default/rcS

db_get clock-setup/utc
if [ "$RET" = true ]; then
	sed -i -e 's:^UTC="no":UTC="yes":' -e 's:^UTC=no:UTC=yes:' $utcfile
	if [ -e /target/etc/adjtime ]; then
		sed -i -e 's:^LOCAL$:UTC:' /target/etc/adjtime
	fi
	OPT="--utc"
else
	sed -i -e 's:^UTC="yes":UTC="no":' -e 's:^UTC=yes:UTC=no:' $utcfile
	if [ -e /target/etc/adjtime ]; then
		sed -i -e 's:^UTC$:LOCAL:' /target/etc/adjtime
	fi
	if [ "$(udpkg --print-os)" = linux ]; then
		cat >/target/etc/e2fsck.conf <<EOF
[options]
# This setting is needed when the RTC is set to local time and e2fsck
# is used in the initramfs (see Debian bug #767040).
broken_system_clock=1
EOF
	fi
	OPT="--localtime"
fi

[ "$(udpkg --print-os)" != hurd ] || OPT="$OPT --directisa"

# Only update the hardware clock if the system clock was updated using rdate
db_get clock-setup/system-time-changed
if [ "$RET" = true ]; then
	hwclock_prepare

	db_progress INFO clock-setup/progress/hwclock
	log-output -t clock-setup chroot /target hwclock $OPT --systohc --debug &
	pid="$!"
	count=0

	while sleep 1; do
		if [ ! -e /proc/$pid ]; then
			break
		fi
		count=$(($count + 1))
		if [ $count -eq 30 ]; then
			count=0
			db_input critical clock-setup/hwclock-wait || true
			if ! db_go; then
				hwclock_stop
				cleanup
				exit 10 # back to main menu
			fi
			db_get clock-setup/hwclock-wait
			if [ "$RET" = false ]; then
				hwclock_stop
				break
			fi
		fi
	done
else
	log "not setting hardware clock"
fi