Debian Codegraph @

pbuilder-checkparams

raw
1 #! /bin/bash
2 # pbuilder -- personal Debian package builder
3 # Copyright © 2001-2007 Junichi Uekawa <[email protected]>
4 # 2015-2016 Mattia Rizzolo <[email protected]>
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 ###############################################################################
20
21
22 # This code is called for pbuilder and pbuilder inside pbuilder-uml;
23 # pbuilder-uml calls uml-checkparams.
24
25 export PBUILDER_PKGLIBDIR="${PBUILDER_PKGLIBDIR:-$PBUILDER_ROOT/usr/lib/pbuilder}"
26 CMDLINE="$@"
27
28 . "$PBUILDER_PKGLIBDIR"/pbuilder-loadconfig
29 . "$PBUILDER_PKGLIBDIR"/pbuilder-modules
30
31 #default value for this option is !empty!
32 INTERNAL_BUILD_UML=""
33 TWICE=""
34 CHROOTEXEC=""
35 OVERRIDE_APTLINES="no"
36 OVERRIDE_APTLINES_WARN="" # set this if --override-config option should be set.
37 BINARY_ARCH="any" # can be one of 'any', 'all', 'binary'
38 BIN_NMU="no"
39 PBUILDER_BUILD_LOGFILE=
40 PRESERVE_BUILDPLACE="no"
41 unset EXTRA_CONFIGFILE || true
42 PBUILDER_DEBUGMODE=
43 SAVE_AFTER_LOGIN=
44 #option for user-mode-linux only.
45 IGNORE_UMOUNT=""
46
47 while [ -n "$1" ]; do
48 case "$1" in
49 --basetgz)
50 if [ "$PBUILDER_OPERATION" = create ]; then
51 touch "$2"
52 fi
53 if [ ! -f "$2" ]; then
54 log.e "File $2 does not exist"
55 exit 1
56 fi
57 BASETGZ=$(readlink -f "$2");
58 shift; shift;
59 ;;
60 --buildplace)
61 if [ ! -d "$2" ] ; then
62 log.e "Directory $2 does not exist"
63 exit 1
64 fi
65 BUILDPLACE=$(readlink -f "$2");
66 shift; shift;
67 ;;
68 --mirror)
69 MIRRORSITE="$2";
70 OVERRIDE_APTLINES_WARN=yes
71 shift; shift;
72 ;;
73 --othermirror)
74 OTHERMIRROR="$2";
75 OVERRIDE_APTLINES_WARN=yes
76 shift; shift;
77 ;;
78 --http-proxy)
79 export http_proxy="$2";
80 shift; shift;
81 ;;
82 --use-network)
83 USENETWORK="$2"
84 shift 2
85 ;;
86 --use-cgroup)
87 USECGROUP="$2"
88 shift 2
89 ;;
90 --distribution)
91 DISTRIBUTION="$2";
92 OVERRIDE_APTLINES_WARN=yes
93 shift; shift;
94 ;;
95 --architecture)
96 ARCHITECTURE="$2";
97 shift; shift;
98 ;;
99 --host-arch)
100 HOST_ARCH="$2"
101 shift 2
102 ;;
103 --no-auto-cross)
104 if [ "$NO_AUTO_CROSS" = "yes" ]; then
105 NO_AUTO_CROSS="really-dont-mess-with-me"
106 else
107 NO_AUTO_CROSS=yes
108 fi
109 shift
110 ;;
111 --components)
112 COMPONENTS="$2";
113 OVERRIDE_APTLINES_WARN=yes
114 shift; shift;
115 ;;
116 --buildresult)
117 if [ -n "$2" ]; then
118 if [ -d "$2" ]; then
119 BUILDRESULT=$(readlink -f "$2");
120 else
121 BUILDRESULT="$2"
122 log.w "Build-result Directory $2 does not exist"
123 # warn, but make it progress.
124 fi
125 else
126 BUILDRESULT=
127 fi
128 shift; shift;
129 ;;
130 --compressprog)
131 if [ -n "$2" ]; then
132 COMPRESSPROG="$2"
133 fi
134 shift; shift;
135 ;;
136 --aptcache)
137 if [ -n "$2" ]; then
138 if [ -d "$2" ]; then
139 APTCACHE=$(readlink -f "$2");
140 else
141 log.e "Directory $2 does not exist"
142 exit 1
143 fi
144 else
145 APTCACHE=
146 fi
147 shift; shift;
148 ;;
149 --autocleanaptcache)
150 AUTOCLEANAPTCACHE=yes
151 shift;
152 ;;
153 --removepackages)
154 REMOVEPACKAGES="$2";
155 shift; shift;
156 ;;
157 --loglevel)
158 LOGLEVEL="$2"
159 shift; shift;
160 ;;
161 --configfile)
162 if [ ! -f "$2" ]; then
163 log.e "Config file $2 does not exist"
164 exit 1
165 fi
166 . "$2";
167 # deprecated in v0.216
168 if [ -n "$PKGNAME_LOGFILE_EXTENTION" ] ; then
169 echo "W: The configuration option PKGNAME_LOGFILE_EXTENTION is deprecated in favour of PKGNAME_LOGFILE_EXTENSION. Though, while you have the former set it'll take precedence over the latter."
170 echo "W: PKGNAME_LOGFILE_EXTENTION will be removed at some point, please update your config!"
171 PKGNAME_LOGFILE_EXTENSION="$PKGNAME_LOGFILE_EXTENTION"
172 fi
173 EXTRA_CONFIGFILE[${#EXTRA_CONFIGFILE[@]}]="$2";
174 shift; shift;
175 ;;
176 --extrapackages)
177 EXTRAPACKAGES="${EXTRAPACKAGES:+$EXTRAPACKAGES }$2";
178 shift; shift;
179 ;;
180 --hookdir)
181 HOOKDIR="$2";
182 shift; shift;
183 ;;
184 --debemail)
185 DEBEMAIL="$2";
186 shift; shift;
187 # deprecated in v0.222
188 if [ -n "$DEBEMAIL" ]; then
189 echo "W: The configuration option DEBEMAIL is deprecated. Please pass the required options to DEBBUILDOPTS (--debbuildopts command line flag) instead."
190 echo "W: DEBEMAIL='$DEBEMAIL' is ignored!"
191 fi
192 ;;
193 --debbuildopts)
194 # append to DEBBUILDOPTS or reset to empty if $2 isn't set
195 DEBBUILDOPTS="${2:+${DEBBUILDOPTS:+$DEBBUILDOPTS }$2}";
196 shift; shift;
197 ;;
198 --profiles)
199 export DEB_BUILD_PROFILES="${2//,/ }"
200 shift 2
201 ;;
202 --logfile)
203 log.i "Logging to $2"
204 exec > >(tee "$2") 2>&1
205 PBUILDER_BUILD_LOGFILE=$(readlink -f "$2")
206 shift; shift;
207 ;;
208 --pkgname-logfile)
209 PKGNAME_LOGFILE="yes"
210 shift;
211 ;;
212 --aptconfdir)
213 APTCONFDIR="$2";
214 shift; shift;
215 ;;
216 --timeout)
217 TIMEOUT_TIME="$2"
218 shift; shift;
219 ;;
220 --help)
221 showhelp
222 exit 0
223 ;;
224 --override-config)
225 OVERRIDE_APTLINES="yes"
226 shift;
227 ;;
228 --binary-arch)
229 BINARY_ARCH="binary"
230 # XXX this might be overwriten by --debbuildopts ""
231 DEBBUILDOPTS="${DEBBUILDOPTS} -B"
232 shift;
233 ;;
234 --binary-indep)
235 BINARY_ARCH="all"
236 # XXX this might be overwritten by --debbuildopts ""
237 DEBBUILDOPTS="${DEBBUILDOPTS} -A"
238 shift
239 ;;
240 --source-only-changes)
241 SOURCE_ONLY_CHANGES="yes"
242 shift;
243 ;;
244 --no-source-only-changes)
245 SOURCE_ONLY_CHANGES="no"
246 shift
247 ;;
248 --bin-nmu)
249 BIN_NMU="yes"
250 BINARY_ARCH="binary"
251 # XXX this might be overwriten by --debbuildopts ""
252 DEBBUILDOPTS="${DEBBUILDOPTS} -B"
253 BINNMU_MESSAGE="$2"
254 shift; shift;
255 ;;
256 --bin-nmu-maintainer)
257 BINNMU_MAINTAINER="$2"
258 shift; shift;
259 ;;
260 --bin-nmu-version)
261 BINNMU_VERSION="$2"
262 shift; shift;
263 ;;
264 --bin-nmu-timestamp)
265 BINNMU_TIMESTAMP="$2"
266 shift 2
267 ;;
268 --preserve-buildplace)
269 PRESERVE_BUILDPLACE="yes"
270 shift;
271 ;;
272 --bindmounts)
273 BINDMOUNTS="${BINDMOUNTS} $2"
274 shift; shift;
275 ;;
276 --debootstrapopts)
277 # specify this option to set --variant=buildd value to debootstrap
278 DEBOOTSTRAPOPTS[${#DEBOOTSTRAPOPTS[@]}]="$2";
279 shift; shift;
280 ;;
281 --debootstrap)
282 # Use this option to specify debootstrap/cdebootstrap
283 DEBOOTSTRAP="$2";
284 shift; shift;
285 ;;
286 --allow-untrusted)
287 ALLOWUNTRUSTED=yes;
288 shift;
289 ;;
290 --debdelta)
291 DEBDELTA=yes;
292 shift;
293 ;;
294 --keyring)
295 APTKEYRINGS[${#APTKEYRINGS[@]}]="$2";
296 shift; shift;
297 ;;
298 --save-after-login|--save-after-exec)
299 SAVE_AFTER_LOGIN=yes;
300 shift;
301 ;;
302 --inputfile)
303 if [ ! -f "$2" ]; then
304 log.e "Input file $2 does not exist"
305 exit 1
306 fi
307 INPUTFILE[${#INPUTFILE[@]}]="$2";
308 shift; shift;
309 ;;
310 --outputfile)
311 OUTPUTFILE[${#OUTPUTFILE[@]}]="$2";
312 shift; shift;
313 ;;
314
315 ## internal options.
316 --internal-chrootexec)
317 # specify custom chrootexec function -- this is internal debugging function
318 CHROOTEXEC="$2"
319 shift; shift;
320 ;;
321 --debug)
322 PBUILDER_DEBUGMODE=yes
323 set -x
324 shift;
325 ;;
326 --no-targz)
327 # specify this option if I am running in no-targz mode
328 log.i "Running in no-targz mode"
329 INTERNAL_BUILD_UML="yes"
330 shift;
331 ;;
332 --internal-build-uml)
333 # specify this option if I am running inside UML.
334 log.i "Running in pbuilder-user-mode-linux mode"
335 INTERNAL_BUILD_UML="yes"
336 IGNORE_UMOUNT="no"
337 shift;
338 ;;
339 --twice)
340 TWICE="yes"
341 shift;
342 ;;
343 --) # end of processing for this
344 shift;
345 break;
346 ;;
347 --*)
348 log.e "Unknown option [$1] was specified "
349 exit 1;
350 ;;
351 *)
352 break;
353 ;;
354 esac
355 done
356
357 log.d "cmdline: ${PBUILDER_OPERATION} ${CMDLINE}"
358
359 BUILDPLACE=${BUILDPLACE?"Build root directory is not defined"}
360
361 # the default is to add a PID in the buildplace specified in the config file.
362 BASEBUILDPLACE="$BUILDPLACE"
363 if [ "${INTERNAL_BUILD_UML}" != "yes" -a "${PRESERVE_BUILDPLACE}" != "yes" ]; then
364 BUILDPLACE="$BUILDPLACE/$$"
365 fi
366
367 # sanity check of LOGLEVEL
368 case "$LOGLEVEL" in
369 D|I|W|E) ;;
370 *) # use log() instead of log.e() to override the buggy LOGLEVEL
371 log "E: A non-valid LOGLEVEL has been specified: '${LOGLEVEL}'."
372 log "E: Valid values are D, I, W, E"
373 exit 1
374 ;;
375 esac
376
377 # set up CHROOTEXEC
378 if [ -z "${CHROOTEXEC}" ]; then
379 CHROOTEXEC="chroot $BUILDPLACE "
380 if [ "$EATMYDATA" = "yes" ]; then
381 if /sbin/ldconfig -p | grep libeatmydata >/dev/null 2>&1 ; then
382 if ! which eatmydata > /dev/null 2>&1 ; then
383 log.w "the eatmydata binary is not installed on the host, not using it."
384 EATMYDATA=not-available
385 fi
386 else
387 log.w "libeatmydata is not installed on the host, not using it."
388 EATMYDATA=not-available
389 fi
390 fi
391 if [ "$USECGROUP" = "yes" ]; then
392 # v215 is required for systemd-escape
393 if systemctl is-system-running --quiet >/dev/null 2>&1 && \
394 dpkg --compare-versions "$(dpkg-query -W --showformat='${Version}' systemd)" gt 215; then
395 # --description uses that no-spaces string because the quoting sucks
396 # right now, and it would end up trying to execute $PBUILDER_OPERATION…
397 # long-term solution is to turn $CHROOTEXEC into a command and properly
398 # use arrays instead of plain strings.
399 SYSTEMD_SLICE="system-pbuilder-${PBUILDER_OPERATION}${1:+-"$(systemd-escape "$(basename "$1" .dsc)")"}-$$.slice"
400 systemctl_run=(
401 systemd-run
402 --quiet
403 --scope
404 --description="pbuilder_${PBUILDER_OPERATION}${1:+_"$(basename "$1")"}"
405 --slice="$SYSTEMD_SLICE"
406 )
407 # Allow dpkg-query --showformat='${Version}' etc to not need the
408 # dollar signs to be escaped as $$ when using systemd-run. Option
409 # available since v254, defaulted to no for --scope until v258.
410 if dpkg --compare-versions "$(dpkg-query -W --showformat='${Version}' systemd)" gt 254; then
411 systemctl_run+=("--expand-environment=no")
412 fi
413 CHROOTEXEC="${systemctl_run[*]} $CHROOTEXEC"
414 else
415 log.w "cgroups are not available on the host, not using them."
416 USECGROUP=not-available
417 fi
418 fi
419 fi
420
421 # handle 'experimental' specially. -- required for raw pbuilder (create/update) only.
422 case "$PBUILDER_OPERATION" in
423 update|create)
424 if [ "$DISTRIBUTION" = "experimental" ]; then
425 DISTRIBUTION="sid"
426 EXPERIMENTAL="true"
427 else
428 EXPERIMENTAL=""
429 fi
430 ;;
431 *) EXPERIMENTAL="" ;;
432 esac
433
434
435 case "$PBUILDER_OPERATION" in
436 login|execute|pdebuild)
437 # don't do anything if it is "login", or pdebuild
438 ;;
439 *)
440 # line from [email protected]
441 if [ "$DEBIAN_FRONTEND" = "noninteractive" -o "$DEBIAN_FRONTEND" = "Noninteractive" ]; then
442 exec < /dev/null
443 # set variables used in the upgrade option.
444 FORCE_CONFNEW[0]='-o'
445 FORCE_CONFNEW[1]='DPkg::Options::=--force-confnew'
446 else
447 unset FORCE_CONFNEW || true
448 fi
449 ;;
450 esac
451
452 if [ -n "$CCACHEDIR" ]; then
453 if [ -d "$CCACHEDIR" ]; then
454 BINDMOUNTS="$BINDMOUNTS $CCACHEDIR"
455 fi
456 export PATH="/usr/lib/ccache:$PATH"
457 fi
458
459 # sort BINDMOUNTS to ensure that deeper directories are mounted last
460 BINDMOUNTS="$(for i in $BINDMOUNTS; do echo $i; done | sort -u)"
461
462 if [ "$ALLOWUNTRUSTED" = "yes" ]; then
463 PBUILDERSATISFYDEPENDSOPT[${#PBUILDERSATISFYDEPENDSOPT[@]}]='--allow-untrusted'
464 # Also duplicated in pbuilder-satisfydepends-checkparams!
465 # apt flag to accept untrusted packages
466 APTGETOPT[${#APTGETOPT[@]}]='--force-yes'
467 # aptitude flag to accept untrusted packages
468 APTITUDEOPT[${#APTITUDEOPT[@]}]='-o'
469 APTITUDEOPT[${#APTITUDEOPT[@]}]='Aptitude::CmdLine::Ignore-Trust-Violations=true'
470 fi