File: 50mirror

package info (click to toggle)
apt-setup 1%3A0.198
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,272 kB
  • sloc: sh: 1,247; makefile: 25
file content (301 lines) | stat: -rwxr-xr-x 7,128 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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
#!/bin/sh
set -e

. /usr/share/debconf/confmodule
. /usr/lib/base-installer/library.sh

file="$1"

NL="
"

logoutput=""
if [ "$CATCHLOG" ]; then
	logoutput="log-output -t apt-setup"
fi

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

ask_no_mirror() {
	db_input critical apt-setup/no_mirror
	db_go || exit 10

	db_get apt-setup/no_mirror
	if [ "$RET" = true ]; then
		exit 1
	fi
}

# For architectures in the Debian-Ports archive, sources.list has to include
# an additional entry for the "unreleased" suite.
unset use_unreleased
if is_ports_architecture "$(chroot /target /usr/bin/dpkg --print-architecture)"; then
	log "Debian-Ports architecture detected"
	use_unreleased=yes
fi

# Ask if a mirror should be used if the base system can be installed from CD
# Default value and priority vary with the CD type used and number of CDs
# that has been scanned in 41cdset
if [ -e /cdrom/.disk/base_installable ]; then
	if ! search-path choose-mirror; then
		warning "choose-mirror is not available; cannot offer network mirror"
		exit 1
	fi

	cd_type=unknown
	if [ -e /cdrom/.disk/cd_type ]; then
		cd_type=$(cat /cdrom/.disk/cd_type)
	fi
	cd_count=$(grep "^deb cdrom:" $ROOT/etc/apt/sources.list.new | wc -l)

	no_network=
	if db_get netcfg/dhcp_options && \
	   [ "$RET" = "Do not configure the network at this time" ]; then
		no_network=1
	fi

	case "$cd_type" in
	    not_complete)
		use_mirror=true
		if [ "$no_network" ]; then
			ask_no_mirror
			exit 0
		else
			use_prio=medium
		fi
		db_metaget apt-setup/use/netinst description
		db_subst apt-setup/use_mirror EXPLANATION "$RET"
		;;
	    full_cd*)
		use_mirror=true
		use_prio=high
		if [ $cd_count -le 8 ]; then
			if [ $cd_count -eq 1 ]; then
				db_metaget apt-setup/use/cd description
			elif [ $cd_count -le 3 ]; then
				db_metaget apt-setup/use/cd-set1 description
				RET="$(printf "$RET" "$cd_count")"
			else
				use_mirror=false
				db_metaget apt-setup/use/cd-set2 description
				RET="$(printf "$RET" "$cd_count")"
			fi
			explanation="$RET"
			if [ $cd_count -le 3 ]; then
				db_metaget apt-setup/use/inet1 description
				explanation="$explanation $RET"
				db_metaget apt-setup/use/cd-note description
				explanation="$explanation$NL$NL$RET"
			else
				db_metaget apt-setup/use/inet2 description
				explanation="$explanation $RET"
			fi
			db_subst apt-setup/use_mirror EXPLANATION "$explanation"
		else
			use_mirror=false
			use_prio=low
		fi
		;;
	    dvd*)
		use_mirror=false
		use_prio=high
		if [ $cd_count -eq 1 ]; then
			db_metaget apt-setup/use/dvd description
			explanation="$RET"
			db_metaget apt-setup/use/inet2 description
			explanation="$explanation $RET"
			db_subst apt-setup/use_mirror EXPLANATION "$explanation"
		else
			use_prio=low
		fi
		;;
	    bluray*)
		use_mirror=false
		use_prio=low
		;;
	    *)
		use_mirror=true
		use_prio=high
		;;
	esac

	if [ "$no_network" ]; then
		use_mirror=false
	fi

	# Only set default if not preseeded or already asked
	# Hack alert: for this to work no default is set in template
	db_get apt-setup/use_mirror
	[ "$RET" ] || db_set apt-setup/use_mirror $use_mirror

	db_input $use_prio apt-setup/use_mirror || [ $? -eq 30 ]
	db_go || exit 10

	db_get apt-setup/use_mirror
	if [ "$RET" = false ]; then
		exit 1
	fi

	# Default suite to codename; choose-mirror will determine actual suite
	if db_get cdrom/codename && [ "$RET" ]; then
		db_set mirror/suite $RET
	fi

	while true; do
		CODE=0
		choose-mirror -n || CODE=$?	# no progress bar
		db_capb backup progresscancel
		if [ $CODE -eq 0 ]; then
			break
		elif [ $CODE -eq 10 ]; then
			# User backed out of choose-mirror
			ask_no_mirror
		else
			logger -t apt-setup "choose-mirror failed with error code $CODE"
			exit $CODE
		fi
	done
fi

# Abort if no mirror is configured.
db_get mirror/protocol
protocol="$RET"
db_get mirror/codename
codename="$RET"
db_get mirror/$protocol/hostname
hostname="$RET"
db_get mirror/$protocol/directory
directory="/${RET#/}"
if [ -z "$hostname" ] || [ -z "$directory" ]; then
	exit 1
fi

STATE=1
while true; do
	case "$STATE" in
	    1)
		# non-free-firmware is independent from non-free and contrib:
		db_input low apt-setup/non-free-firmware || true
		;;
	    2)
		db_input low apt-setup/non-free || true
		;;
	    3)
		# If they chose not to use non-free, ask about
		# contrib, with a default of no. If they chose to
		# use non-free, they get contrib too..
		db_get apt-setup/non-free
		if [ "$RET" = false ]; then
			db_fget apt-setup/contrib seen
			if [ "$RET" = false ]; then
				db_set apt-setup/contrib false
			fi
			db_input low apt-setup/contrib || true
		else
			db_fget apt-setup/contrib seen
			if [ "$RET" = false ]; then
				db_set apt-setup/contrib true
			fi
		fi
		;;
	    4)
		db_input low apt-setup/enable-source-repositories || true
		;;
	    *)
		break
		;;
	esac

	if db_go; then
		STATE=$(($STATE + 1))
	else
		STATE=$(($STATE - 1))
	fi
done
if [ $STATE -eq 0 ]; then
	exit 10
fi

components="main"
for component in contrib non-free non-free-firmware; do
	db_get apt-setup/$component
	if [ "$RET" = true ]; then
		components="$components $component"
	fi
done

done=""
while [ ! "$done" ]; do
	db_get mirror/codename
	codename="$RET"
	db_get mirror/protocol
	protocol="$RET"
	db_get mirror/$protocol/hostname
	hostname="$RET"
	db_get mirror/$protocol/directory
	directory="/${RET#/}"

	if [ "$protocol" = "https" ]; then
		# Ensure that ca-certificates is installed, so apt can verify the https certificate
		$logoutput apt-install ca-certificates
	fi

	case $protocol in
	    http|https)
		db_get mirror/$protocol/proxy
		proxy="$RET"
		if [ -n "$proxy" ]; then
			if ! grep -iq "Acquire::$protocol::Proxy" $ROOT/etc/apt/apt.conf.new; then
				echo "Acquire::$protocol::Proxy \"$proxy\";" >> $ROOT/etc/apt/apt.conf.new
			fi
		fi
		;;
	esac

	trusted=""
	if [ -n "${use_unreleased}" -a "$hostname" = snapshot.debian.org ]; then
		# debian-ports' and snapshot's signatures do not last long, cannot use gpg :/
		trusted="[check-valid-until=no trusted=yes] "
	fi

	echo "deb $trusted$protocol://$hostname$directory $codename $components" > $file
	if [ -n "${use_unreleased}" ]; then
		echo "deb $trusted$protocol://$hostname$directory unreleased main" >> $file
	fi
	
	if apt-setup-verify --from $PROGRESS_FROM --to $PROGRESS_TO $file; then
		done=1
	else
		db_set apt-setup/mirror/error Retry
		db_input critical apt-setup/mirror/error || true
		db_go || exit 10
		db_get apt-setup/mirror/error
		if [ "$RET" = "Change mirror" ]; then
			choose-mirror -n || true
			db_capb backup progresscancel
		elif [ "$RET" = Ignore ]; then
			exit 1
		fi
	fi
done

deb_src="deb-src"
db_get apt-setup/enable-source-repositories
if [ "$RET" = false ]; then
	deb_src="# deb-src"
fi

echo "$deb_src $trusted$protocol://$hostname$directory $codename $components" >> $file
if [ -n "${use_unreleased}" ]; then
	echo "# 'unreleased' does not support sources yet" >> $file
	echo "# $deb_src $trusted$protocol://$hostname$directory unreleased main" >> $file
fi

# Remember components so that other generators don't have to grep:
echo $components > /tmp/apt-setup.components