Debian Codegraph @

pbuilder-apt-config

raw
1 #!/bin/sh
2 # apt-config outputs APT configuration data
3 # Copyright (C) 2010 Loïc Minier <[email protected]>
4 #
5 # Permission is hereby granted, free of charge, to any person obtaining a
6 # copy of this software and associated documentation files (the "Software"),
7 # to deal in the Software without restriction, including without limitation
8 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 # and/or sell copies of the Software, and to permit persons to whom the
10 # Software is furnished to do so, subject to the following conditions:
11 #
12 # The above copyright notice and this permission notice shall be included in
13 # all copies or substantial portions of the Software.
14 #
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 # SOFTWARE IN THE PUBLIC INTEREST, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 # DEALINGS IN THE SOFTWARE.
22 #
23 # Except as contained in this notice, the name of the author shall not be used
24 # in advertising or otherwise to promote the sale, use or other dealings in
25 # this Software without prior written authorization from the author.
26 #
27 # TODO figure a way to integrate PPA support in profile mode
28
29 set -e
30
31 self="$(basename "$0")"
32
33 log() {
34 echo "$@" >&2
35 }
36
37 usage() {
38 log "$self [<options>] [--archive=<archive>] [--mirror=<mirror>] [--suite=<suite>] [--pockets=<pocket1>,<pocket2>] <action>"
39 log "$self [--profile=<profile>] <action>"
40 log " where <action> is one of apt-sources, debootstrap-mirror, or debootstrap-suite"
41 log
42 log "Common options:"
43 log " --with-sources, --with-sources=[yes|no|disabled]"
44 log " --mirror-map=<mirror-map>"
45 log " --arch=<arch>"
46 log " --components=<comp1>,<comp2>"
47 }
48
49 die() {
50 log "$@"
51 exit 1
52 }
53
54 guess_dist_arch_archive() {
55 local dist="$1"
56 local arch="$2"
57
58 case "$dist" in
59 etch|lenny|squeeze|sid|oldstable|stable|testing|unstable|experimental)
60 echo "debian"
61 ;;
62 buzz|rex|bo|hamm|slink|potato|woody|sarge|etch|lenny|squeeze|wheezy|jessie|stretch|buster)
63 echo "debian-archive"
64 ;;
65 precise|trusty|xenial|yakkety|zesty|artful)
66 case "$arch" in
67 amd64|i386)
68 echo "ubuntu"
69 ;;
70 arm64|armel|armhf|hppa|ia64|lpia|powerpc|ppc64el|s390x|sparc)
71 echo "ubuntu-ports"
72 ;;
73 *)
74 die "Unknown Ubuntu archive for arch=$arch"
75 ;;
76 esac
77 ;;
78 warty|hoary|breezy|edgy|feisty|gutsy|dapper|hardy|intrepid|jaunty|karmic|lucid|maverick|natty|oneiric|quantal|raring|saucy|utopic|vivid|wily)
79 echo "ubuntu-old"
80 ;;
81 *)
82 die "Unknown archive for dist=$dist"
83 ;;
84 esac
85 }
86
87 get_archive_url() {
88 local mirror_map="$1"
89 local archive="$2"
90 local url
91
92 if [ -z "$archive" ]; then
93 die "Need an archive in get_archive_url()"
94 fi
95
96 if [ -n "$mirror_map" ]; then
97 while read a url; do
98 case "$a" in
99 "$archive")
100 if [ -n "$url" ]; then
101 echo "$url"
102 return
103 fi
104 ;;
105 \#*|""|*)
106 :
107 ;;
108 esac
109 done <"$mirror_map"
110 fi
111 builtin_mirror_map "$archive"
112 }
113
114 builtin_mirror_map() {
115 local archive="$1"
116 local people_ppa
117
118 case "$archive" in
119 backports.org)
120 echo "http://www.backports.org/backports.org/"
121 ;;
122 debian)
123 echo "http://deb.debian.org/debian/"
124 ;;
125 debian-archive)
126 echo "http://archive.debian.org/debian/"
127 ;;
128 debian-security)
129 echo "http://security.debian.org/"
130 ;;
131 debian-volatile)
132 echo "http://volatile.debian.org/debian-volatile/"
133 ;;
134 ppa:*)
135 people_ppa="${archive#ppa:}"
136 case "$people_ppa" in
137 */*)
138 :
139 ;;
140 *)
141 people_ppa="$people_ppa/ppa"
142 esac
143 echo "http://ppa.launchpad.net/$people_ppa/ubuntu/"
144 ;;
145 ubuntu)
146 echo "http://archive.ubuntu.com/ubuntu/"
147 ;;
148 ubuntu-old)
149 echo "http://old-releases.ubuntu.com/ubuntu/"
150 ;;
151 ubuntu-ports)
152 echo "http://ports.ubuntu.com/ubuntu-ports/"
153 ;;
154 ubuntu-security)
155 echo "http://security.ubuntu.com/ubuntu/"
156 ;;
157 *)
158 die "Unknown mirror for archive=$archive"
159 ;;
160 esac
161 }
162
163 output_sources() {
164 local with_sources="$1"
165 local mirror="$2"
166 local dist="$3"
167 local components="$4"
168
169 case "$with_sources" in
170 yes)
171 echo "deb $mirror $dist $components"
172 echo "deb-src $mirror $dist $components"
173 ;;
174 disabled)
175 echo "deb $mirror $dist $components"
176 echo "#deb-src $mirror $dist $components"
177 ;;
178 no)
179 echo "deb $mirror $dist $components"
180 ;;
181 *)
182 die 'with_sources must be either "yes", "disabled", or "no"'
183 ;;
184 esac
185 }
186
187 sources=""
188 debootstrap_suite=""
189 debootstrap_mirror=""
190
191 add_output_sources() {
192 local output="$(output_sources "$@")"
193
194 sources="$sources${sources:+
195 }$output"
196 }
197
198 set_debootstrap_suite() {
199 local archive="$1"
200 local suite="$2"
201
202 case "$archive" in
203 debian)
204 case "$suite" in
205 unstable)
206 debootstrap_suite="sid"
207 ;;
208 testing)
209 debootstrap_suite="squeeze"
210 ;;
211 stable)
212 debootstrap_suite="lenny"
213 ;;
214 oldstable)
215 debootstrap_suite="etch"
216 ;;
217 *)
218 debootstrap_suite="$suite"
219 ;;
220 esac
221 ;;
222 *)
223 debootstrap_suite="$suite"
224 ;;
225 esac
226 }
227
228 getopt_output="$(getopt -o "" -l help,with-sources::,arch:,components:,archive:,mirror:,mirror-map:,suite:,pockets:,profile: -n "$self" -s sh -- "$@")"
229
230 eval set -- "$getopt_output"
231
232 with_sources="disabled"
233 arch="$(dpkg --print-architecture)"
234 components="main"
235 archive=""
236 mirror=""
237 mirror_map=""
238 suite=""
239 pockets=""
240 archive=""
241 profile=""
242
243 while :; do
244 case "$1" in
245 --help)
246 usage
247 exit 0
248 ;;
249 --with-sources)
250 case "$2" in
251 "")
252 with_sources="yes"
253 ;;
254 yes|no|disabled)
255 with_sources="$2"
256 ;;
257 *)
258 die '--with-sources must be either "yes", "disabled", or "no"'
259 ;;
260 esac
261 shift 2
262 ;;
263 --arch)
264 arch="$2"
265 shift 2
266 ;;
267 --components)
268 components="$2"
269 shift 2
270 ;;
271 --archive)
272 archive="$2"
273 shift 2
274 ;;
275 --mirror)
276 mirror="$2"
277 shift 2
278 ;;
279 --mirror-map)
280 mirror_map="$2"
281 shift 2
282 ;;
283 --suite)
284 if [ -z "$2" ]; then
285 die "Need a suite for --suite"
286 fi
287 if [ -n "$profile" ]; then
288 die "Can't set --suite after --profile"
289 fi
290 suite="$2"
291 shift 2
292 ;;
293 --pockets)
294 pockets="$2"
295 shift 2
296 ;;
297 --profile)
298 if [ -z "$2" ]; then
299 die "Need a profile for --profile"
300 fi
301 if [ -n "$suite" ]; then
302 die "Can't set --profile after --suite"
303 fi
304 profile="$2"
305 shift 2
306 ;;
307 --)
308 shift
309 break
310 ;;
311 *)
312 die "Unhandled arg=$1"
313 ;;
314 esac
315 done
316
317 if [ -z "$suite" ] && [ -z "$profile" ]; then
318 die "Please pass --suite or --profile"
319 fi
320
321 components="$(echo "$components" | tr , " ")"
322 pockets="$(echo "$pockets" | tr , " ")"
323
324 if [ -n "$profile" ]; then
325 base_dist="${profile%%/*}"
326 base_dist="${base_dist%%-*}"
327 base_archive="$(guess_dist_arch_archive "$base_dist" "$arch")"
328 base_mirror="$(get_archive_url "$mirror_map" "$base_archive")"
329 case "$base_archive" in
330 debian|debian-archive)
331 case "$profile" in
332 experimental)
333 base_dist="unstable"
334 add_output_sources "$with_sources" "$base_mirror" "$base_dist" "$components"
335 add_output_sources "$with_sources" "$base_mirror" "$profile" "$components"
336 ;;
337 *-proposed-updates/volatile)
338 archive="debian-volatile"
339 mirror="$(get_archive_url "$mirror_map" "$archive")"
340 volatile_dist="$base_dist/volatile"
341 add_output_sources "$with_sources" "$base_mirror" "$base_dist" "$components"
342 add_output_sources "$with_sources" "$mirror" "$volatile_dist" "$components"
343 add_output_sources "$with_sources" "$mirror" "$profile" "$components"
344 ;;
345 */volatile|*/volatile-sloppy)
346 if [ "$base_dist" != "${profile%%/*}" ]; then
347 die "Unknown Debian Volatile based profile=$profile"
348 fi
349 archive="debian-volatile"
350 mirror="$(get_archive_url "$mirror_map" "$archive")"
351 volatile_dist=${profile%-sloppy}
352 add_output_sources "$with_sources" "$base_mirror" "$base_dist" "$components"
353 add_output_sources "$with_sources" "$mirror" "$volatile_dist" "$components"
354 if [ "$volatile_dist" != "$profile" ]; then
355 add_output_sources "$with_sources" "$mirror" "$profile" "$components"
356 fi
357 ;;
358 *-backports)
359 if [ "$base_dist" != "${profile%%-*}" ]; then
360 die "Unknown Backports.org based profile=$profile"
361 fi
362 archive="backports.org"
363 mirror="$(get_archive_url "$mirror_map" "$archive")"
364 add_output_sources "$with_sources" "$base_mirror" "$base_dist" "$components"
365 add_output_sources "$with_sources" "$mirror" "$profile" "$components"
366 ;;
367 */updates)
368 if [ "$base_dist" != "${profile%%/*}" ]; then
369 die "Unknown Debian Security based profile=$profile"
370 fi
371 archive="debian-security"
372 mirror="$(get_archive_url "$mirror_map" "$archive")"
373 add_output_sources "$with_sources" "$base_mirror" "$base_dist" "$components"
374 add_output_sources "$with_sources" "$mirror" "$profile" "$components"
375 ;;
376 *-proposed-updates)
377 if [ "$base_dist" != "${profile%%-*}" ]; then
378 die "Unknown Debian Updates based profile=$profile"
379 fi
380 add_output_sources "$with_sources" "$base_mirror" "$base_dist" "$components"
381 add_output_sources "$with_sources" "$base_mirror" "$profile" "$components"
382 ;;
383 *)
384 if [ "$base_dist" != "$profile" ]; then
385 die "Unknown Debian based profile=$profile"
386 fi
387 add_output_sources "$with_sources" "$base_mirror" "$base_dist" "$components"
388 ;;
389 esac
390 ;;
391 ubuntu|ubuntu-old|ubuntu-ports)
392 if [ "$base_dist" != "${profile%%-*}" ]; then
393 die "Unknown Ubuntu based profile=$profile"
394 fi
395 pockets=""
396 # whether to include the security mirror
397 has_security="yes"
398 case "$profile" in
399 *-security)
400 pockets="security"
401 ;;
402 *-updates)
403 pockets="security updates"
404 ;;
405 *-backports)
406 pockets="security updates backports"
407 ;;
408 *-proposed)
409 pockets="security updates proposed"
410 ;;
411 *)
412 if [ "$base_dist" != "$profile" ]; then
413 die "Unknown Ubuntu pocket based profile=$profile"
414 fi
415 has_security="no"
416 ;;
417 esac
418 add_output_sources "$with_sources" "$base_mirror" "$base_dist" "$components"
419 for pocket in $pockets; do
420 add_output_sources "$with_sources" "$base_mirror" "$base_dist-$pocket" "$components"
421 done
422 if [ "$has_security" = "yes" ]; then
423 archive="ubuntu-security"
424 mirror="$(get_archive_url "$mirror_map" "$archive")"
425 if [ "$mirror" != "$base_mirror" ]; then
426 add_output_sources "$with_sources" "$mirror" "$base_dist-security" "$components"
427 fi
428 fi
429 ;;
430 *)
431 die "Unknown profile for base_archive=$base_archive"
432 ;;
433 esac
434 set_debootstrap_suite "$base_archive" "$base_dist"
435 debootstrap_mirror="$base_mirror"
436 fi
437
438 if [ -n "$suite" ]; then
439 if [ -z "$mirror" ]; then
440 if [ -z "$archive" ]; then
441 archive="$(guess_dist_arch_archive "$suite" "$arch")"
442 fi
443 mirror="$(get_archive_url "$mirror_map" "$archive")"
444 fi
445 add_output_sources "$with_sources" "$mirror" "$suite" "$components"
446 for pocket in $pockets; do
447 add_output_sources "$with_sources" "$mirror" "$suite-$pocket" "$components"
448 done
449 # NB: archive might be empty; best effort to try to guess it
450 if [ -z "$archive" ]; then
451 archive="$(guess_dist_arch_archive "$suite" "$arch")" 2>/dev/null || true
452 fi
453 set_debootstrap_suite "$archive" "$suite"
454 debootstrap_mirror="$mirror"
455 fi
456
457 case $1 in
458 apt-sources)
459 echo "$sources"
460 ;;
461 debootstrap-mirror)
462 echo "$debootstrap_mirror"
463 ;;
464 debootstrap-suite)
465 echo "$debootstrap_suite"
466 ;;
467 *)
468 usage
469 exit 1
470 ;;
471 esac
472