Debian Codegraph @

init_buildsystem

raw ◀ ▶
Source reconstructed at patch state 1 of 2 — not the installed (fully patched) source.
2 Debian patches touch this file
1 #!/bin/bash
2 # Script to create a complete system to build packages in a chroot
3 # environment. This script ensures, that all packages given as
4 # parameter are installed. All other packges will be deleted.
5 #
6 # BUILD_ROOT here the packages will be installed/deleted
7 # BUILD_RPMS here we get our packages to install (obsolete)
8 # BUILD_ARCH path of the architectures we try
9 # BUILD_DIST distribution to build for (will be guessed if not set)
10 #
11 ################################################################
12 #
13 # Copyright (c) 1997-2014 SUSE Linux Products GmbH
14 #
15 # This program is free software; you can redistribute it and/or modify
16 # it under the terms of the GNU General Public License version 2 or 3 as
17 # published by the Free Software Foundation.
18 #
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
23 #
24 # You should have received a copy of the GNU General Public License
25 # along with this program (see the file COPYING); if not, write to the
26 # Free Software Foundation, Inc.,
27 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
28 #
29 ################################################################
30
31 #
32 # needed globals variables
33 #
34 export SRC
35 export BUILD_DIR=${BUILD_DIR:-/usr/lib/build}
36 PATH="$BUILD_DIR:$PATH"
37
38 export YAST_IS_RUNNING=instsys
39 # https://github.com/systemd/systemd/blob/master/docs/ENVIRONMENT.md
40 export SYSTEMD_OFFLINE=1
41
42 # slurp in package binary support
43 . "$BUILD_DIR/build-pkg"
44
45 # need to restore build root owner for non-root builds
46 browner=0
47 definesnstuff=()
48 repos=()
49
50 . $BUILD_DIR/common_functions || exit 1
51
52 # should RPMs be installed with --force ?
53 USE_FORCE=false
54 PREPARE_VM=
55 USEUSEDFORBUILD=
56 LIST_STATE=
57 RPMLIST=
58 CLEAN_BUILD=
59 CREATE_BUILD_BINARIES=
60 DLNOSIGNATURE=
61 CACHE_DIR=/var/cache/build
62 test -z "$CONFIG_DIR" && CONFIG_DIR="$BUILD_DIR/configs"
63
64 while test -n "$1" ; do
65 case "$1" in
66 --prepare)
67 shift
68 PREPARE_VM=true
69 ;;
70 --create-build-binaries)
71 shift
72 CREATE_BUILD_BINARIES=true
73 ;;
74 --useusedforbuild)
75 shift
76 USEUSEDFORBUILD=--useusedforbuild
77 ;;
78 --list-state)
79 shift
80 LIST_STATE=true
81 ;;
82 --rpmlist)
83 shift
84 RPMLIST=$1
85 shift
86 ;;
87 --define|--with|--without|--buildflavor|--obspackage)
88 definesnstuff[${#definesnstuff[@]}]="$1";
89 definesnstuff[${#definesnstuff[@]}]="$2";
90 shift 2
91 ;;
92 --repository|--repo)
93 repos[${#repos[@]}]="$2";
94 shift 2
95 ;;
96 --clean)
97 CLEAN_BUILD="$1"
98 shift
99 ;;
100 --cachedir)
101 CACHE_DIR="$2"
102 shift 2
103 ;;
104 --configdir)
105 CONFIG_DIR="$2"
106 shift 2
107 ;;
108 --nosignature)
109 shift
110 DLNOSIGNATURE="--nosignature"
111 ;;
112 --root)
113 BUILD_ROOT="$2"
114 shift 2
115 ;;
116 --arch)
117 BUILD_ARCH="$2"
118 shift 2
119 ;;
120 --dist)
121 BUILD_DIST="$2"
122 shift 2
123 ;;
124 *)
125 break
126 ;;
127 esac
128 done
129 PKGS=("$@")
130
131 if test -z "$BUILD_ROOT" ; then
132 echo "Please specify a build root!"
133 exit 1
134 fi
135
136 BUILD_IS_RUNNING=$BUILD_ROOT/not-ready
137 TMPFILE=$BUILD_ROOT/tmpfile
138 BUILD_INIT_CACHE="$BUILD_ROOT/.init_b_cache"
139
140 #
141 # needed functions
142 #
143
144 mount_stuff() {
145 if test "$UID" = 0 -a -n "$BUILD_ROOT" -a "$BUILD_ROOT" != / ; then
146 mount -n -tproc none "$BUILD_ROOT/proc"
147 test -e "$BUILD_ROOT/proc/self" || cleanup_and_exit 1 "Could not mount /proc, is this a container with missing capabilities?"
148 mount -n -tdevpts -omode=0620,gid=5 none "$BUILD_ROOT/dev/pts"
149 fi
150 }
151
152 umount_stuff() {
153 if test -n "$BUILD_ROOT" -a "$BUILD_ROOT" != / ; then
154 buildroot_umount "/proc/sys/fs/binfmt_misc"
155 buildroot_umount "/proc"
156 buildroot_umount "/sys"
157 buildroot_umount "/dev/pts"
158 buildroot_umount "/dev/shm"
159 buildroot_umount "/mnt"
160 fi
161 }
162
163 cleanup_and_exit() {
164 trap EXIT
165 test -z "$1" && set 0
166 if test -n "$2" ; then
167 if test "$1" -ne 0 ; then
168 echo "$2" >&2
169 else
170 echo "$2"
171 fi
172 fi
173 test "$BUILD_ROOT" = / -a -n "$browner" && chown "$browner" "$BUILD_ROOT"
174 # umount so init_buildsystem can be used standalone
175 umount_stuff
176 exit $1
177 }
178
179 clean_build_root() {
180 if test -n "$BUILD_ROOT" -a "$BUILD_ROOT" != / ; then
181 umount_stuff
182 rm -rf -- "$BUILD_ROOT"/* 2> /dev/null || true
183 chattr -a -A -i -R -- "$BUILD_ROOT" 2> /dev/null || true # does not follow symlinks
184 rm -rf -- "$BUILD_ROOT"/*
185 rm -rf -- "$BUILD_ROOT/.build"
186 rm -rf -- "$BUILD_ROOT"/.build.kernel.*
187 rm -rf -- "$BUILD_ROOT"/.build.initrd.*
188 rm -rf -- "$BUILD_ROOT/.root"
189 rm -rf -- "$BUILD_ROOT/.init_b_cache"
190 test -L "$BUILD_ROOT/.preinstall_image" && rm -f -- "$BUILD_ROOT/.preinstall_image"
191 rm -rf -- "$BUILD_ROOT"/.preinstall_image/*
192 rm -rf -- "$BUILD_ROOT"/.preinstallimage*
193 fi
194 }
195
196 unsafe_preinstall_check() {
197 # cpio isn't safe so we require bsdtar for VMs. chroot is
198 # unsafe anyways so it's ok for that.
199 if test -n "$PREPARE_VM" ; then
200 echo "Error: setting up a VM requires bsdtar for security reasons."
201 echo "Please install bsdtar."
202 cleanup_and_exit 1
203 fi
204 }
205
206 preinstall_image_filter() {
207 for PKG in "$@" ; do
208 test -e "$BUILD_ROOT/.preinstall_image/$PKG" && continue
209 echo $PKG
210 done
211 }
212
213 preinstall_setup() {
214 cd "$BUILD_ROOT" || cleanup_and_exit 1
215 rm -rf build-preinstall
216 mkdir build-preinstall || cleanup_and_exit 1
217 for i in * .* ; do
218 # please keep in sync with recipe_build_preinstallimage
219 case "$i" in
220 .|..|build-preinstall) continue ;;
221 .build.kernel.*|.build.hostarch.*|.build.initrd.*|.build.console.*) ;;
222 .build*|.init_b_cache|.preinstallimage*|.srcfiles*|.pkgs|.rpm-cache|installed-pkg|proc|sys) continue ;;
223 esac
224 mv "./$i" build-preinstall || cleanup_and_exit 1
225 done
226 cd build-preinstall || cleanup_and_exit 1
227 }
228
229 preinstall_integrate() {
230 cd "$BUILD_ROOT/build-preinstall" || cleanup_and_exit 1
231 for i in * .* ; do
232 case "$i" in
233 .|..|build-preinstall) continue ;;
234 .build.kernel.*|.build.hostarch.*|.build.initrd.*|.build.console.*) ;;
235 .build*|.init_b_cache|.preinstallimage*|.srcfiles*|.pkgs|.rpm-cache|installed-pkg|proc|sys) continue ;;
236 esac
237 mv "./$i" .. || cleanup_and_exit 1
238 done
239 cd "$BUILD_ROOT" || cleanup_and_exit 1
240 assert_dirs
241 }
242
243 preinstall_image() {
244 check_exit
245 echo "unpacking preinstall image${2:+ $2}"
246 preinstall_setup
247 if test -x /usr/bin/bsdtar ; then
248 TAR="/usr/bin/bsdtar --exclude .build --exclude .init_b_cache -P --chroot --numeric-owner -x"
249 else
250 unsafe_preinstall_check
251 TAR="tar --exclude .build --exclude .init_b_cache -x"
252 fi
253 # pipe output through perl to print a dot every 1000 lines
254 if ! $TAR -z -f "$BUILD_INIT_CACHE/rpms/$1" -v > >(tee "$BUILD_INIT_CACHE/.preinstallimage.unpack" | perl -e '$|=1; my $done=0; $done++ % 1000 or print "." while <STDIN>; print "\n";') 2>&1 ; then
255 echo "unpack failed."
256 test -f "$BUILD_INIT_CACHE/.preinstallimage.unpack" && cat "$BUILD_INIT_CACHE/.preinstallimage.unpack"
257 cleanup_and_exit 1
258 fi
259 rm -rf "$BUILD_INIT_CACHE/.preinstallimage.unpack"
260 preinstall_integrate
261 }
262
263 preinstall() {
264 local PKG="$1"
265 check_exit
266 echo "preinstalling $PKG..."
267 preinstall_setup
268 if test -x /usr/bin/bsdtar ; then
269 CPIO="/usr/bin/bsdtar --exclude .build --exclude .init_b_cache -P --chroot -o --numeric-owner -x -f-"
270 TAR="/usr/bin/bsdtar --exclude .build --exclude .init_b_cache -P --chroot -o --numeric-owner -x"
271 else
272 unsafe_preinstall_check
273 CPIO="cpio --extract --unconditional --preserve-modification-time --make-directories --no-absolute-filenames --quiet"
274 TAR="tar --exclude .build --exclude .init_b_cache -x"
275 fi
276 pkg_preinstall
277 preinstall_integrate
278 }
279
280 run_pkg_scripts() {
281 chroot $BUILD_ROOT /sbin/ldconfig 2>/dev/null
282 for PKG in $PACKAGES_TO_RUNSCRIPTS ; do
283 pkg_runscripts
284 check_exit
285 done
286 }
287
288 reorder() {
289 test -z "$*" && return
290 rm -f $BUILD_ROOT/.init_b_cache/order.manifest
291 for PKG in "$@" ; do
292 echo "$PKG" >> $BUILD_ROOT/.init_b_cache/order.manifest
293 done
294 $BUILD_DIR/order --dist "$BUILD_DIST" --archpath "$BUILD_ARCH" --configdir $CONFIG_DIR --manifest $BUILD_ROOT/.init_b_cache/order.manifest $BUILD_ROOT/.init_b_cache/rpms || touch $BUILD_ROOT/exit
295 rm -f $BUILD_ROOT/.init_b_cache/order.manifest
296 }
297
298 create_devs() {
299 local com file mode arg
300
301 test -d $BUILD_ROOT/dev/pts -a ! -L $BUILD_ROOT/dev/pts || rm -f $BUILD_ROOT/dev/pts
302 test -d $BUILD_ROOT/dev/shm -a ! -L $BUILD_ROOT/dev/shm || rm -f $BUILD_ROOT/dev/shm
303 mkdir -m 755 -p $BUILD_ROOT/dev/pts
304 mkdir -m 755 -p $BUILD_ROOT/dev/shm
305 while read com file mode arg ; do
306 rm -f $BUILD_ROOT/dev/$file
307 if test $com = ln ; then
308 ln -s $arg $BUILD_ROOT/dev/$file
309 elif test $com = mknod ; then
310 mknod -m $mode $BUILD_ROOT/dev/$file $arg
311 fi
312 done << DEVLIST
313 mknod null 666 c 1 3
314 mknod zero 666 c 1 5
315 mknod full 666 c 1 7
316 mknod random 666 c 1 8
317 mknod urandom 644 c 1 9
318 mknod tty 666 c 5 0
319 mknod ptmx 666 c 5 2
320 mknod loop-control 600 c 10 237
321 mknod loop0 640 b 7 0
322 mknod loop1 640 b 7 1
323 mknod loop2 640 b 7 2
324 mknod loop3 640 b 7 3
325 mknod fuse 666 c 10 229
326 ln fd 777 /proc/self/fd
327 ln stdin 777 fd/0
328 ln stdout 777 fd/1
329 ln stderr 777 fd/2
330 DEVLIST
331 }
332
333 # check whether the repo list contains a plain "zypp://". Add all
334 # enabled zypp repos in this case
335 expand_plain_zypp_repo() {
336 local i j
337 r=()
338 for i in "${repos[@]}"; do
339 if test "$i" = "zypp://" ; then
340 for j in $($BUILD_DIR/createzyppdeps --listrepos) ; do
341 r=("${r[@]}" "zypp://$j")
342 done
343 else
344 r=("${r[@]}" "$i")
345 fi
346 done
347 repos=("${r[@]}")
348 }
349
350 create_cache_file() {
351 local findonly=
352 expand_plain_zypp_repo
353
354 # check if we can reuse the old cache file
355 if ! test -f $CACHE_FILE || ! test -f $CACHE_FILE.id || \
356 test "${repos[*]} ${BUILD_RPMS//:/ /}" != "$(cat $CACHE_FILE.id 2>/dev/null)"; then
357 rm -f $CACHE_FILE.id
358 else
359 for SRC in "${repos[@]}" ${BUILD_RPMS//:/ /}; do
360 test -n "$SRC" || SRC=.
361 if test "${SRC#zypp://}" != "$SRC" ; then
362 SRC="/var/cache/zypp/raw/${SRC#zypp://}"
363 fi
364 if test "$SRC" -nt $CACHE_FILE; then
365 rm -f $CACHE_FILE.id
366 break
367 fi
368 # always rebuild if we have remote repositories and --clean is given
369 if test -n "$CLEAN_BUILD" -a "$SRC" != "${SRC#*://}" -a "${SRC#zypp://}" = "$SRC" ; then
370 rm -f $CACHE_FILE.id
371 break
372 fi
373 done
374 fi
375 if test -f $CACHE_FILE.id ; then
376 return
377 fi
378
379 # nope, generate a new cache file
380 test -z "$LIST_STATE" && echo initializing $CACHE_FILE ...
381
382 # figure out a repository type default
383 REPOTYPE=
384 if test -n "$BUILD_DIST" ; then
385 for i in `queryconfig repotype --dist "$BUILD_DIST" --configdir "$CONFIG_DIR" --archpath "$BUILD_ARCH"` ; do
386 case $i in
387 arch|debian|hdlist2|rpm-md) REPOTYPE=$i ;;
388 esac
389 test -n "$REPOTYPE" && break
390 done
391 if test -z "$REPOTYPE"; then
392 BINTYPE=`queryconfig binarytype --dist "$BUILD_DIST" --configdir "$CONFIG_DIR" --archpath "$BUILD_ARCH"`
393 case "$BINTYPE" in
394 arch) REPOTYPE=arch ;;
395 deb) REPOTYPE=debian ;;
396 esac
397 fi
398 fi
399 if test -z "$REPOTYPE" ; then
400 # check the first init_buildsystem arg, maybe it is a recipe
401 case ${PKGS[0]} in
402 *.spec)
403 REPOTYPE=rpm-md ;;
404 *.dsc)
405 REPOTYPE=debian ;;
406 */PKGBUILD|PKGBUILD|*/_service:*:PKGBUILD|_service:*:PKGBUILD)
407 REPOTYPE=arch ;;
408 esac
409 fi
410 for SRC in "${repos[@]}" -- ${BUILD_RPMS//:/ /}; do
411 if test "$SRC" = '--' ; then
412 findonly=1
413 continue
414 fi
415 SRCREPOTYPE=$REPOTYPE
416 case $SRC in
417 arch@* | debian@* | hdlist2@* | rpmmd@* | rpm-md@* | suse@*)
418 SRCREPOTYPE=${SRC%%@*}
419 SRC=${SRC#*@}
420 ;;
421 esac
422 test -z "$SRC" && SRC=`pwd`
423 if test "${SRC#http://}" != "$SRC" -o "${SRC#https://}" != "$SRC" -o "${SRC#ftp://}" != "$SRC" -o "${SRC#ftps://}" != "$SRC" ; then
424 # remote repo, cache binary packages
425 mkdir -p "$(getcachedir "$SRC")"
426 if test "$SRCREPOTYPE" = arch ; then
427 set -- $BUILD_DIR/createarchdeps --cachedir="$CACHE_DIR" "$SRC"
428 elif test "$SRCREPOTYPE" = debian ; then
429 set -- $BUILD_DIR/createdebdeps --cachedir="$CACHE_DIR" --archpath "$BUILD_ARCH" "$SRC"
430 elif test "$SRCREPOTYPE" = suse ; then
431 set -- $BUILD_DIR/createyastdeps --cachedir="$CACHE_DIR" "$SRC"
432 elif test "$SRCREPOTYPE" = hdlist2 ; then
433 set -- $BUILD_DIR/createmdkdeps --cachedir="$CACHE_DIR" "$SRC"
434 else
435 set -- $BUILD_DIR/createrepomddeps --cachedir="$CACHE_DIR" "$SRC"
436 fi
437 elif test "${SRC#zypp://}" != "$SRC" ; then
438 # special zypp repo
439 set -- $BUILD_DIR/createzyppdeps --cachedir="$CACHE_DIR" "$SRC"
440 elif test ! -e "$SRC" ; then
441 cleanup_and_exit 1 "*** $SRC does not exist"
442 elif test -z "$findonly" -a \( -e "$SRC"/suse/setup/descr/packages -o -e "$SRC"/suse/setup/descr/packages.gz \) ; then
443 set -- $BUILD_DIR/createyastdeps "$SRC"
444 elif test -z "$findonly" -a -e "$SRC"/repodata/repomd.xml ; then
445 set -- $BUILD_DIR/createrepomddeps "$SRC"
446 else
447 set -- $BUILD_DIR/createdirdeps --oldfile "$CACHE_FILE" "$SRC"
448 fi
449 echo "$@" >&2
450 "$@" || cleanup_and_exit 1
451 echo D:
452 done > $CACHE_FILE.new
453
454 mv $CACHE_FILE.new $CACHE_FILE
455 echo "${repos[*]} ${BUILD_RPMS//:/ /}" > $CACHE_FILE.id
456 }
457
458 fail_exit() {
459 cleanup_and_exit 1
460 }
461
462 # modifies $SRC
463 downloadpkg() {
464 local url="$1"
465
466 case $url in
467 zypp://* | http://* | https://* | ftp://* | ftps://*) ;;
468 *) cleanup_and_exit 1 "Invalid url: $url" ;;
469 esac
470
471 local cachedir="$(getcachedir "$url")"
472 local name="$(basename "$url")"
473 name=${name/%.pkg.tar.zst/.arch}
474 name=${name/%.pkg.tar.?z/.arch}
475 SRC="$cachedir/$name"
476 local destdir="$cachedir/tmp"
477 mkdir -p "$destdir"
478 echo "downloading $url ... ";
479 $BUILD_DIR/download "$destdir" "$url" || cleanup_and_exit 1
480 local destfile="$destdir/${url##*/}"
481 if test ! -e "$destfile" ; then
482 cleanup_and_exit 1 "expected $destfile after download but it's missing"
483 fi
484 # for rpm check integrity and the signature
485 case $destfile in
486 *.rpm)
487 rpm -K $DLNOSIGNATURE "$destfile" > $destfile.v || { echo "rpm verify failed" >&2; rm -rf "$destdir"; cleanup_and_exit 1; }
488 if grep "NOT OK" $destfile.v; then
489 rm -rf "$destdir"
490 cleanup_and_exit 1
491 fi
492 rm -f "$destfile.v"
493 ;;
494 esac
495 mv "$destfile" "$SRC" || cleanup_and_exit 1
496 }
497
498 getcachedir() {
499 local url=$1
500 for repo in "${repos[@]}" ; do
501 case $repo in
502 arch@* | debian@* | hdlist2@* | rpmmd@* | rpm-md@* | suse@*) repo=${repo#*@} ;;
503 esac
504 if test "${url:0:${#repo}}" == "$repo" ; then
505 read repoid dummy < <(echo -n "$repo" | md5sum)
506 echo "$CACHE_DIR/$repoid"
507 break
508 fi
509 done
510 }
511
512 echo "init_buildsystem version: $BUILD_VERSION"
513
514 set_build_arch
515
516 trap fail_exit EXIT
517
518 if test "$BUILD_ROOT" = / ; then
519 browner="$(stat -c %u /)"
520 fi
521
522 if test -n "$CLEAN_BUILD" ; then
523 clean_build_root
524 fi
525
526 #
527 # now test if there was an incomplete run
528 #
529 if test -e "$BUILD_IS_RUNNING" ; then
530 echo "It seems that there was an incomplete setup of $BUILD_ROOT."
531 if test -z "$BUILD_ROOT" -o "$BUILD_ROOT" = / ; then
532 cleanup_and_exit 1
533 fi
534 echo "To be sure, we will build it again completely..."
535 umount_stuff
536 echo "Your build system is broken!! Shall I execute"
537 echo
538 echo " rm -rf -- $BUILD_ROOT/*"
539 echo
540 echo "y - yes, cleanup the build root"
541 echo "N - No, abort build (default on enter)"
542 echo "c - Continue anyway with this build root"
543 echo -n "[y/N/c] "
544 read ANSWER
545 case "$ANSWER" in
546 c|C)
547 rm -f $BUILD_IS_RUNNING $BUILD_ROOT/exit ;;
548 y|Y)
549 clean_build_root ;;
550 *)
551 cleanup_and_exit 1 ;;
552 esac
553 fi
554
555 # check for surprises
556 if test -z "$CLEAN_BUILD" -a -n "$BUILD_ROOT" -a "$BUILD_ROOT" != / ; then
557 assert_dirs
558 fi
559 # umount stuff if mounted
560 if test -n "$BUILD_ROOT" -a "$BUILD_ROOT" != / -a -e "$BUILD_ROOT/proc/self" ; then
561 umount_stuff
562 fi
563
564 #
565 # store that we start to build the system
566 #
567 mkdir -p "$BUILD_ROOT"
568 mkdir -p "$BUILD_ROOT/.build"
569 mkdir -p "$BUILD_ROOT/proc"
570 mkdir -p "$BUILD_ROOT/dev/pts"
571 touch $BUILD_IS_RUNNING
572
573 if test -n "$PREPARE_VM" ; then
574 rm -rf $BUILD_ROOT/.build/init_buildsystem.data
575 fi
576
577 if test -e $BUILD_ROOT/.build/init_buildsystem.data ; then
578 # vm continuation, read old config
579 . $BUILD_ROOT/.build/init_buildsystem.data
580 else
581 #
582 # now make sure that all the packages are installed.
583 #
584 rm -rf "$BUILD_ROOT/.init_b_cache"
585 mkdir -p "$BUILD_ROOT/.init_b_cache/scripts"
586
587 if test -z "$RPMLIST" ; then
588 #
589 # create rpmdeps file
590 #
591 CACHE_FILE=$BUILD_ROOT/.srcfiles.cache
592 create_cache_file
593
594 #
595 # select and expand packages
596 #
597 RPMLIST=$BUILD_ROOT/.init_b_cache/rpmlist
598 test -z "$LIST_STATE" && echo "expanding package dependencies..."
599 VMOPT=
600 test -z "$PREPARE_VM" || VMOPT=--vm
601 if ! $BUILD_DIR/expanddeps $USEUSEDFORBUILD $VMOPT "${definesnstuff[@]}" --dist "$BUILD_DIST" --depfile "$CACHE_FILE" --archpath "$BUILD_ARCH" --configdir $CONFIG_DIR "${PKGS[@]}" > $RPMLIST ; then
602 rm -f $BUILD_IS_RUNNING
603 cleanup_and_exit 1
604 fi
605 fi
606
607 if test -n "$LIST_STATE" ; then
608 rm -f $BUILD_IS_RUNNING
609 while read PKG SRC ; do
610 test "$PKG" = "preinstall:" && continue
611 test "$PKG" = "runscripts:" && continue
612 test "$PKG" = "cbpreinstall:" && continue
613 test "$PKG" = "vminstall:" && continue
614 test "$PKG" = "dist:" && continue
615 test "$PKG" = "rpmid:" && continue
616 echo "${SRC##*/}"
617 done < $BUILD_ROOT/.init_b_cache/rpmlist
618 rm -rf "$BUILD_ROOT/.init_b_cache"
619 cleanup_and_exit 0
620 fi
621
622 #
623 # register the QEMU emulator if needed
624 # (we do not need this for the prepare step, as we do not run scripts in this case)
625 #
626 if test -z "$PREPARE_VM" ; then
627 if check_use_emulator ; then
628 echo "registering binfmt handlers for cross build"
629 "$BUILD_DIR/$INITVM_NAME"
630 echo 0 > /proc/sys/vm/mmap_min_addr
631 read mmap_min_addr < /proc/sys/vm/mmap_min_addr
632 if test "$mmap_min_addr" != 0 ; then
633 echo "Warning: mmap_min_addr is != 0. If programs fail at mmap this could be the reason."
634 fi
635 fi
636 fi
637
638 #
639 # extract the data from the (generated) rpm list
640 #
641 PACKAGES_TO_INSTALL=
642 PACKAGES_TO_PREINSTALL=
643 PACKAGES_TO_RUNSCRIPTS=
644 PACKAGES_TO_VMINSTALL=
645 PACKAGES_TO_INSTALLONLY=
646 PACKAGES_TO_NOINSTALL=
647 PREINSTALL_IMAGE=
648 PREINSTALL_IMAGE_SOURCE=
649 RUNSCRIPTS_SEEN=
650 PACKAGES_FROM_PREINSTALLIMAGE=
651 GUESSED_DIST=unknown
652 mkdir -p $BUILD_ROOT/.init_b_cache/rpms
653 rm -f $BUILD_ROOT/.init_b_cache/rpmlist.download
654 while read PKG SRC ; do
655 if test "$PKG" = "preinstall:" ; then
656 PACKAGES_TO_PREINSTALL=$SRC
657 continue
658 fi
659 if test "$PKG" = "vminstall:" ; then
660 PACKAGES_TO_VMINSTALL=$SRC
661 continue
662 fi
663 if test "$PKG" = "installonly:" ; then
664 PACKAGES_TO_INSTALLONLY=$SRC
665 continue
666 fi
667 if test "$PKG" = "noinstall:" ; then
668 PACKAGES_TO_NOINSTALL=$SRC
669 continue
670 fi
671 if test "$PKG" = "preinstallimage:" ; then
672 PREINSTALL_IMAGE=${SRC##*/}
673 ln -s "$SRC" "$BUILD_ROOT/.init_b_cache/rpms/${SRC##*/}"
674 continue
675 fi
676 if test "$PKG" = "preinstallimagesource:" ; then
677 PREINSTALL_IMAGE_SOURCE="$SRC"
678 continue
679 fi
680 if test "$PKG" = "runscripts:" ; then
681 RUNSCRIPTS_SEEN=true
682 PACKAGES_TO_RUNSCRIPTS=$SRC
683 continue
684 fi
685 if test "$PKG" = "dist:" ; then
686 GUESSED_DIST=$SRC
687 continue
688 fi
689 if test "$PKG" = "rpmid:" ; then
690 echo "${SRC#*:}" > $BUILD_ROOT/.init_b_cache/rpms/${SRC%%:*}.id
691 continue
692 fi
693 if test "$PKG" != "${PKG%:}"; then
694 echo "Warning: ignoring unsupported tag '$PKG'" >&2
695 continue
696 fi
697 if test "$SRC" = "preinstallimage" ; then
698 PACKAGES_FROM_PREINSTALLIMAGE="$PACKAGES_FROM_PREINSTALLIMAGE $PKG"
699 PACKAGES_TO_INSTALL="$PACKAGES_TO_INSTALL $PKG"
700 continue
701 fi
702 PACKAGES_TO_INSTALL="$PACKAGES_TO_INSTALL $PKG"
703 if test "${SRC#/}" = "$SRC" ; then
704 case "$SRC" in
705 zypp://* | http://* | https://* | ftp://* | ftps://*)
706 echo "$PKG $SRC" >>$BUILD_ROOT/.init_b_cache/rpmlist.download
707 continue
708 ;;
709 *)
710 cleanup_and_exit 1 "unsupported url for '$PKG': $SRC"
711 ;;
712 esac
713 fi
714 SRCSUF=${SRC/%.pkg.tar.zst/.arch}
715 SRCSUF=${SRCSUF/%.pkg.tar.?z/.arch}
716 ln -s "$SRC" "$BUILD_ROOT/.init_b_cache/rpms/$PKG.${SRCSUF##*.}"
717 done < $RPMLIST
718
719 PACKAGES_TO_ALL="$PACKAGES_TO_INSTALL"
720 PACKAGES_TO_AVAILABLE="$PACKAGES_TO_INSTALL"
721
722 # subtract noinstall packages from PACKAGES_TO_INSTALL
723 if test -n "$PACKAGES_TO_NOINSTALL" ; then
724 settest=" $PACKAGES_TO_NOINSTALL "
725 PACKAGES_TO_INSTALL=
726 for PKG in $PACKAGES_TO_ALL ; do
727 test "$settest" = "${settest/ $PKG /}" && PACKAGES_TO_INSTALL="$PACKAGES_TO_INSTALL $PKG"
728 done
729 fi
730 # subtract installonly packages from PACKAGES_TO_AVAILABLE
731 if test -n "$PACKAGES_TO_INSTALLONLY" ; then
732 settest=" $PACKAGES_TO_INSTALLONLY "
733 PACKAGES_TO_AVAILABLE=
734 for PKG in $PACKAGES_TO_ALL ; do
735 test "$settest" = "${settest/ $PKG /}" && PACKAGES_TO_AVAILABLE="$PACKAGES_TO_AVAILABLE $PKG"
736 done
737 fi
738
739 # use cached packages where possible
740 if test -s $BUILD_ROOT/.init_b_cache/rpmlist.download ; then
741 echo "calculating packages to download..."
742 while read PKG SRC ; do
743 SRCSUF=${SRC/%.pkg.tar.zst/.arch}
744 SRCSUF=${SRCSUF/%.pkg.tar.?z/.arch}
745 if test -s "$BUILD_ROOT/.init_b_cache/rpms/$PKG.id" ; then
746 read cachepkgid < $BUILD_ROOT/.init_b_cache/rpms/$PKG.id
747 echo "PKG $PKG $cachepkgid"
748 else
749 echo "PKG $PKG"
750 fi
751 echo "DST $BUILD_ROOT/.init_b_cache/rpms/$PKG.${SRCSUF##*.}"
752 if test "$SRC" != "${SRC#zypp://}" ; then
753 # for zypp packages also look in the zypp cache
754 cachedir="/var/cache/zypp/packages/${SRC#zypp://}"
755 echo "CACHE ${cachedir%/*}/${SRC##*/}"
756 fi
757 cachedir="$(getcachedir "$SRC")"
758 echo "CACHE $cachedir/${SRCSUF##*/}"
759 done < $BUILD_ROOT/.init_b_cache/rpmlist.download | "$BUILD_DIR/getbuildids" cachecheck
760 # remove found packages from download list
761 rm -f $BUILD_ROOT/.init_b_cache/rpmlist.download2
762 while read PKG SRC ; do
763 SRCSUF=${SRC/%.pkg.tar.zst/.arch}
764 SRCSUF=${SRCSUF/%.pkg.tar.?z/.arch}
765 test -L "$BUILD_ROOT/.init_b_cache/rpms/$PKG.${SRCSUF##*.}" || echo "$PKG $SRC" >>$BUILD_ROOT/.init_b_cache/rpmlist.download2
766 done < $BUILD_ROOT/.init_b_cache/rpmlist.download
767 rm -f $BUILD_ROOT/.init_b_cache/rpmlist.download
768 test -s $BUILD_ROOT/.init_b_cache/rpmlist.download2 && mv $BUILD_ROOT/.init_b_cache/rpmlist.download2 $BUILD_ROOT/.init_b_cache/rpmlist.download
769 fi
770
771 # now do the download of missing packages
772 if test -s $BUILD_ROOT/.init_b_cache/rpmlist.download ; then
773 PACKAGES_TO_DOWNLOAD=`awk '{print $2}' < "$BUILD_ROOT/.init_b_cache/rpmlist.download"`
774 progress_setup PACKAGES_TO_DOWNLOAD
775 while read PKG SRC ; do
776 progress_step PACKAGES_TO_DOWNLOAD
777 downloadpkg "$SRC"
778 # downloadpkg modified $SRC, so it has a right name for use
779 SRCSUF=${SRC/%.pkg.tar.zst/.arch}
780 SRCSUF=${SRCSUF/%.pkg.tar.?z/.arch}
781 ln -s "$SRC" "$BUILD_ROOT/.init_b_cache/rpms/$PKG.${SRCSUF##*.}"
782 done < $BUILD_ROOT/.init_b_cache/rpmlist.download
783 rm -f $BUILD_ROOT/.init_b_cache/rpmlist.download
784 echo
785 fi
786
787 # compatibility...
788 test -z "$RUNSCRIPTS_SEEN" && PACKAGES_TO_RUNSCRIPTS="$PACKAGES_TO_PREINSTALL"
789
790 buildroot_rm .guessed_dist
791 echo "$GUESSED_DIST" > $BUILD_ROOT/.guessed_dist
792 test -n "$BUILD_DIST" || BUILD_DIST="$GUESSED_DIST"
793
794 pkg_set_type
795
796 if test -n "$PREINSTALL_IMAGE" ; then
797 for PKG in $PACKAGES_FROM_PREINSTALLIMAGE ; do
798 # touch the file so that the copying works
799 touch $BUILD_ROOT/.init_b_cache/rpms/"$PKG.$PSUF"
800 done
801 fi
802
803 fi
804
805 # XXX: should use an option instead of looking at the recipe?
806 CREATE_PREINSTALL_DATA=
807 case ${PKGS[0]} in
808 _preinstallimage | */_preinstallimage | _service:*:_preinstallimage | */_service:*:_preinstallimage)
809 mkdir -p $BUILD_ROOT/.preinstall_image
810 CREATE_PREINSTALL_DATA=true
811 echo "saving package data for preinstallimage generation"
812 ;;
813 esac
814
815 #
816 # test if we need to preinstall
817 #
818 if test ! -e $BUILD_ROOT/installed-pkg -a ! -e $BUILD_ROOT/.build/init_buildsystem.data ; then
819 mkdir -p $BUILD_ROOT/.init_b_cache/rpms || cleanup_and_exit 1
820 mkdir -p $BUILD_ROOT/etc || cleanup_and_exit 1
821 mkdir -p $BUILD_ROOT/proc || cleanup_and_exit 1
822 test -L $BUILD_ROOT/etc/HOSTNAME && buildroot_rm etc/HOSTNAME
823 test -f $BUILD_ROOT/etc/HOSTNAME || hostname -f > $BUILD_ROOT/etc/HOSTNAME
824 for PKG in $PACKAGES_TO_RUNSCRIPTS ; do
825 : > $BUILD_ROOT/.init_b_cache/scripts/$PKG.run
826 done
827 PACKAGES_TO_PREINSTALL_FILTERED="$PACKAGES_TO_PREINSTALL"
828 PACKAGES_TO_VMINSTALL_FILTERED="$PACKAGES_TO_VMINSTALL"
829 rm -f "$BUILD_ROOT/.preinstall_image"/*
830 if test -n "$PREINSTALL_IMAGE" ; then
831 preinstall_image "$PREINSTALL_IMAGE" "$PREINSTALL_IMAGE_SOURCE"
832 PACKAGES_TO_PREINSTALL_FILTERED=`preinstall_image_filter $PACKAGES_TO_PREINSTALL_FILTERED`
833 PACKAGES_TO_VMINSTALL_FILTERED=`preinstall_image_filter $PACKAGES_TO_VMINSTALL_FILTERED`
834 fi
835 PACKAGES_TO_PREINSTALL_FILTERED=`reorder $PACKAGES_TO_PREINSTALL_FILTERED`
836 if test -n "$PREPARE_VM" ; then
837 PACKAGES_TO_VMINSTALL_FILTERED=`reorder $PACKAGES_TO_VMINSTALL_FILTERED`
838 fi
839 progress_setup PACKAGES_TO_PREINSTALL_FILTERED
840 for PKG in $PACKAGES_TO_PREINSTALL_FILTERED ; do
841 progress_step PACKAGES_TO_PREINSTALL_FILTERED
842 preinstall ${PKG##*/}
843 done
844 if test -n "$PREPARE_VM" ; then
845 echo
846 progress_setup PACKAGES_TO_VMINSTALL_FILTERED
847 for PKG in $PACKAGES_TO_VMINSTALL_FILTERED ; do
848 progress_step PACKAGES_TO_VMINSTALL_FILTERED
849 preinstall ${PKG##*/}
850 done
851 fi
852 # for reorder
853 check_exit
854 if test -w /root ; then
855 test -c $BUILD_ROOT/dev/null || create_devs
856 fi
857 if ! test -e $BUILD_ROOT/etc/fstab ; then
858 rm -rf $BUILD_ROOT/etc/fstab
859 touch $BUILD_ROOT/etc/fstab
860 fi
861 if test ! -e $BUILD_ROOT/etc/ld.so.conf -a -f $BUILD_ROOT/etc/ld.so.conf.in -a ! -L $BUILD_ROOT/etc/ld.so.conf.in ; then
862 rm -rf $BUILD_ROOT/etc/ld.so.conf
863 cp $BUILD_ROOT/etc/ld.so.conf.in $BUILD_ROOT/etc/ld.so.conf
864 fi
865 if test -z "$PREPARE_VM" ; then
866 mount_stuff
867 run_pkg_scripts
868 pkg_initdb
869 touch $BUILD_ROOT/.init_b_cache/preinstall_finished
870 fi
871 # mark as preinstalled no longer needed
872 rm -rf "$BUILD_ROOT/installed-pkg"
873 mkdir -p "$BUILD_ROOT/installed-pkg"
874 else
875 # preinstall was already done
876 if test -z "$PREPARE_VM" ; then
877 mount_stuff
878 fi
879 fi
880
881 if test -n "$PREPARE_VM" ; then
882 echo "copying packages..."
883 for PKG in $PACKAGES_TO_ALL ; do
884 rm -rf $BUILD_ROOT/.init_b_cache/$PKG.$PSUF
885 cp $BUILD_ROOT/.init_b_cache/rpms/$PKG.$PSUF $BUILD_ROOT/.init_b_cache/$PKG.$PSUF || cleanup_and_exit 1
886 ln -s -f ../$PKG.$PSUF $BUILD_ROOT/.init_b_cache/rpms/$PKG.$PSUF
887 check_exit
888 done
889 # alreadyinstalled check will not work, but we have to live with that...
890 echo -n 'reordering...'
891 PACKAGES_TO_INSTALL=`reorder $PACKAGES_TO_INSTALL`
892 check_exit
893 echo 'done'
894 Q="'\''"
895 rm -rf "$BUILD_ROOT/.build/init_buildsystem.data"
896 echo "PACKAGES_TO_INSTALL='${PACKAGES_TO_INSTALL//"'"/$Q}'" > $BUILD_ROOT/.build/init_buildsystem.data
897 echo "PACKAGES_TO_RUNSCRIPTS='${PACKAGES_TO_RUNSCRIPTS//"'"/$Q}'" >> $BUILD_ROOT/.build/init_buildsystem.data
898 # needed for continuation in xen/kvm with rpm-x86
899 echo "PACKAGES_TO_PREINSTALL='${PACKAGES_TO_PREINSTALL//"'"/$Q}'" >> $BUILD_ROOT/.build/init_buildsystem.data
900 echo "PACKAGES_TO_AVAILABLE='${PACKAGES_TO_AVAILABLE//"'"/$Q}'" >> $BUILD_ROOT/.build/init_buildsystem.data
901 echo "PSUF='$PSUF'" >> $BUILD_ROOT/.build/init_buildsystem.data
902 rm -f $BUILD_IS_RUNNING
903 cleanup_and_exit 0
904 fi
905
906 #
907 # finish preinstall if this is a vm continuation
908 #
909 if test -e "$BUILD_ROOT/.build/init_buildsystem.data" -a ! -e "$BUILD_ROOT/.init_b_cache/preinstall_finished" ; then
910 run_pkg_scripts
911 pkg_initdb
912 touch "$BUILD_ROOT/.init_b_cache/preinstall_finished"
913 fi
914
915 #
916 # create .build.binaries directory if requested
917 #
918 rm -rf "$BUILD_ROOT/.build.binaries"
919 if test -n "$CREATE_BUILD_BINARIES" ; then
920 echo "creating .build.binaries directory..."
921 mkdir -p "$BUILD_ROOT/.build.binaries"
922 for PKG in $PACKAGES_TO_AVAILABLE ; do
923 test -L "$BUILD_ROOT/.init_b_cache/rpms/$PKG.$PSUF" || continue
924 LPKG=`readlink -f "$BUILD_ROOT/.init_b_cache/rpms/$PKG.$PSUF"`
925 ln "$LPKG" "$BUILD_ROOT/.build.binaries/$PKG.$PSUF" 2>/dev/null
926 test -f "$BUILD_ROOT/.build.binaries/$PKG.$PSUF" && continue
927 cp "$LPKG" "$BUILD_ROOT/.build.binaries/$PKG.$PSUF"
928 check_exit
929 done
930 fi
931
932 #
933 # Save some package build environment preparation time on Debian-like systems
934 # Note: for OS image builds we probably want the man-db constructed properly
935 #
936 if test -x "$BUILD_ROOT/usr/bin/debconf-set-selections" && test "$BUILDTYPE" = dsc ; then
937 echo "Preseed man-db/auto-update to false for a DSC package build..."
938 chroot "$BUILD_ROOT" /usr/bin/debconf-set-selections <<EOF
939 man-db man-db/auto-update boolean false
940 EOF
941 fi
942
943 #
944 # reorder packages (already done in vm continuation)
945 #
946 if ! test -e $BUILD_ROOT/.build/init_buildsystem.data ; then
947 echo -n 'reordering...'
948 PACKAGES_TO_INSTALL=`reorder $PACKAGES_TO_INSTALL`
949 check_exit
950 echo 'done'
951 fi
952
953 echo "querying package ids..."
954 for PKG in $PACKAGES_TO_INSTALL ; do
955 test -s "$BUILD_ROOT/.init_b_cache/rpms/$PKG.$PSUF" || continue
956 test -L "$BUILD_ROOT/.init_b_cache/rpms/$PKG.$PSUF" || continue
957 echo "$BUILD_ROOT/.init_b_cache/rpms/$PKG.$PSUF"
958 done | "$BUILD_DIR/getbuildids"
959
960 #
961 # get list and ids of already installed packages
962 #
963 mkdir -p $BUILD_ROOT/.init_b_cache/alreadyinstalled
964 listinstalled --root "$BUILD_ROOT" --type "$PSUF" --extraname | (
965 while read id name buildid; do
966 echo "$buildid" > "$BUILD_ROOT/.init_b_cache/alreadyinstalled/$name"
967 done
968 )
969
970 # do pre-installation work
971 pkg_prepare
972
973 #
974 # delete all packages we don't want
975 #
976 mkdir -p $BUILD_ROOT/.init_b_cache/todelete
977 for PKG in $BUILD_ROOT/.init_b_cache/alreadyinstalled/* ; do
978 PKG=${PKG##*/}
979 test "$PKG" = "*" && continue
980 ln $BUILD_ROOT/.init_b_cache/alreadyinstalled/$PKG $BUILD_ROOT/.init_b_cache/todelete/$PKG
981 done
982 for PKG in $PACKAGES_TO_INSTALL; do
983 rm -f $BUILD_ROOT/.init_b_cache/todelete/$PKG
984 done
985 for PKG in $BUILD_ROOT/.init_b_cache/todelete/* ; do
986 PKG=${PKG##*/}
987 test "$PKG" = "*" && continue
988 echo "deleting $PKG"
989 pkg_erase
990 check_exit
991 done
992 rm -rf "$BUILD_ROOT/.init_b_cache/todelete"
993
994 rm -rf "$BUILD_ROOT/.init_b_cache/preinstalls"
995 mkdir -p "$BUILD_ROOT/.init_b_cache/preinstalls"
996 for PKG in $PACKAGES_TO_PREINSTALL; do
997 touch "$BUILD_ROOT/.init_b_cache/preinstalls/$PKG"
998 done
999
1000 rm -rf "$BUILD_ROOT/installed-pkg"
1001 mkdir -p "$BUILD_ROOT/installed-pkg"
1002
1003 test -x $BUILD_ROOT/sbin/ldconfig && chroot $BUILD_ROOT /sbin/ldconfig 2>&1
1004
1005 MAIN_LIST="$PACKAGES_TO_INSTALL"
1006 progress_setup MAIN_LIST
1007 for PKG in $MAIN_LIST ; do
1008 test -f $BUILD_ROOT/installed-pkg/$PKG && continue
1009 progress_step MAIN_LIST
1010
1011 if test -e "$BUILD_ROOT/.init_b_cache/rpms/$PKG.$PSUF" -a ! -s "$BUILD_ROOT/.init_b_cache/rpms/$PKG.$PSUF" ; then
1012 # preinstallimage package, make sure it's in the image
1013 if ! test -e $BUILD_ROOT/.preinstall_image/$PKG ; then
1014 cleanup_and_exit 1 "Package $PKG is missing from the preinstall image"
1015 fi
1016 read PKG_HDRMD5 PKGID < $BUILD_ROOT/.preinstall_image/$PKG
1017 echo "preinstalled ${PKGID%% *}"
1018 echo "$PKGID" > $BUILD_ROOT/installed-pkg/$PKG
1019 continue
1020 fi
1021
1022 # get the hdrmd5 if we want to create a preinstall image
1023 PKG_HDRMD5=
1024 if test -n "$CREATE_PREINSTALL_DATA" -a ! -e $BUILD_ROOT/.preinstall_image/$PKG ; then
1025 PKG_HDRMD5=`perl -I$BUILD_DIR -MBuild -e 'print Build::queryhdrmd5($ARGV[0])' $BUILD_ROOT/.init_b_cache/rpms/$PKG.$PSUF`
1026 test -n "$PKG_HDRMD5" || cleanup_and_exit 1
1027 fi
1028
1029 test -L $BUILD_ROOT/.init_b_cache/rpms/$PKG.$PSUF || continue
1030
1031 if test -s "$BUILD_ROOT/.init_b_cache/rpms/$PKG.$PSUF.buildid" ; then
1032 read PKGID < "$BUILD_ROOT/.init_b_cache/rpms/$PKG.$PSUF.buildid"
1033 else
1034 PKGID=$(perl -I$BUILD_DIR -MBuild -e Build::showquery "$BUILD_ROOT/.init_b_cache/rpms/$PKG.$PSUF" buildid)
1035 fi
1036
1037 if test -f "$BUILD_ROOT/.init_b_cache/alreadyinstalled/$PKG" ; then
1038 read OLDPKGID < "$BUILD_ROOT/.init_b_cache/alreadyinstalled/$PKG"
1039 if test "$PKGID" != "$OLDPKGID" && ! test -e "$BUILD_ROOT/.init_b_cache/preinstalls/$PKG" ; then
1040 echo "deleting unwanted ${OLDPKGID%% *}"
1041 pkg_erase
1042 else
1043 if test "$VERIFY_BUILD_SYSTEM" != true || pkg_verify_installed ; then
1044 echo "keeping ${PKGID%% *}"
1045 echo "$PKGID" > $BUILD_ROOT/installed-pkg/$PKG
1046 test -n "$PKG_HDRMD5" && echo "$PKG_HDRMD5 $PKGID" > $BUILD_ROOT/.preinstall_image/$PKG
1047 continue
1048 fi
1049 echo "deleting incomplete ${OLDPKGID%% *}"
1050 pkg_erase
1051 fi
1052 if test -e "$BUILD_ROOT/.init_b_cache/preinstalls/$PKG" ; then
1053 preinstall "$PKG"
1054 fi
1055 check_exit
1056 fi
1057
1058 if pkg_cumulate ; then
1059 echo "cumulate ${PKGID%% *}"
1060 continue
1061 fi
1062
1063 # install the package
1064 echo "installing ${PKGID%% *}"
1065 if ! test "$BUILD_ROOT/.init_b_cache/rpms/$PKG.$PSUF" -ef "$BUILD_ROOT/.init_b_cache/$PKG.$PSUF" ; then
1066 rm -f $BUILD_ROOT/.init_b_cache/$PKG.$PSUF
1067 cp $BUILD_ROOT/.init_b_cache/rpms/$PKG.$PSUF $BUILD_ROOT/.init_b_cache/$PKG.$PSUF || cleanup_and_exit 1
1068 fi
1069 pkg_install
1070 check_exit
1071 rm -f $BUILD_ROOT/.init_b_cache/$PKG.$PSUF
1072 echo "$PKGID" > $BUILD_ROOT/installed-pkg/$PKG
1073 test -n "$PKG_HDRMD5" && echo "$PKG_HDRMD5 $PKGID" > $BUILD_ROOT/.preinstall_image/$PKG
1074
1075 done
1076
1077 # do post-installation work
1078 pkg_finalize
1079
1080 # devices can vanish if devs got uninstalled
1081 test -c $BUILD_ROOT/dev/null || create_devs
1082
1083 cd $BUILD_ROOT || cleanup_and_exit 1
1084
1085 #
1086 # setup /etc/mtab
1087 #
1088 rm -f $BUILD_ROOT/etc/mtab
1089 cp /proc/mounts $BUILD_ROOT/etc/mtab
1090 chmod 644 $BUILD_ROOT/etc/mtab
1091
1092 #
1093 # make sure that our nis is not present in the chroot system
1094 #
1095 if test -e $BUILD_ROOT/etc/nsswitch.conf ; then
1096 sed -e "s:nis::g" < $BUILD_ROOT/etc/nsswitch.conf > $BUILD_ROOT/etc/nsswitch.conf.tmp
1097 mv $BUILD_ROOT/etc/nsswitch.conf.tmp $BUILD_ROOT/etc/nsswitch.conf
1098 fi
1099
1100 #
1101 # create some default directories and files
1102 #
1103 for DIR in /usr/share/doc/packages \
1104 /usr/X11R6/include/X11/pixmaps \
1105 /usr/X11R6/include/X11/bitmaps ; do
1106 mkdir -p $BUILD_ROOT/$DIR
1107 done
1108 for FILE in /var/run/utmp /var/log/wtmp /etc/fstab ; do
1109 mkdir -p $BUILD_ROOT/${FILE%/*}
1110 touch $BUILD_ROOT/$FILE
1111 done
1112
1113 echo now finalizing build dir...
1114 if test -x $BUILD_ROOT/sbin/ldconfig ; then
1115 CHROOT_RETURN="`chroot $BUILD_ROOT /sbin/ldconfig 2>&1`"
1116 case "$CHROOT_RETURN" in
1117 *warning:*)
1118 chroot $BUILD_ROOT /sbin/ldconfig
1119 echo
1120 echo chroot $BUILD_ROOT /sbin/ldconfig
1121 echo
1122 echo "$CHROOT_RETURN"
1123 echo
1124 echo "Problem with ldconfig. It's better to reinit the build system..."
1125 echo
1126 cleanup_and_exit 1
1127 ;;
1128 esac
1129 fi
1130
1131 if test -x $BUILD_ROOT/usr/sbin/Check && ! grep -q "/usr/sbin/Check is obsolete" $BUILD_ROOT/usr/sbin/Check ; then
1132 chroot $BUILD_ROOT /usr/sbin/Check
1133 fi
1134
1135 mkdir -p $BUILD_ROOT/var/adm/packages
1136 touch $BUILD_ROOT/var/adm/packages
1137
1138 if test -x $BUILD_ROOT/sbin/SuSEconfig ; then
1139 if grep norestarts $BUILD_ROOT/sbin/SuSEconfig > /dev/null ; then
1140 chroot $BUILD_ROOT /sbin/SuSEconfig --norestarts --force
1141 else
1142 chroot $BUILD_ROOT /sbin/SuSEconfig --force
1143 fi
1144 fi
1145
1146 if test -x $BUILD_ROOT/usr/X11R6/bin/switch2mesasoft ; then
1147 chroot $BUILD_ROOT /usr/X11R6/bin/switch2mesasoft
1148 fi
1149
1150 for PROG in /usr/bin/TeX/texhash /usr/bin/texhash ; do
1151 test -x $BUILD_ROOT/$PROG && \
1152 chroot $BUILD_ROOT bash -c ". /etc/profile ; $PROG"
1153 done
1154
1155 if test -e $BUILD_ROOT/usr/share/zoneinfo/UTC ; then
1156 for PROG in /usr/sbin/zic /usr/bin/zic /bin/zic /sbin/zic ; do
1157 test -x $BUILD_ROOT/$PROG && chroot $BUILD_ROOT bash -c "$PROG -l \$(readlink -f /usr/share/zoneinfo/UTC)"
1158 done
1159 fi
1160
1161 if test -d $BUILD_ROOT/usr/lib/build/finalize-system ; then
1162 for PROG in $BUILD_ROOT/usr/lib/build/finalize-system/* ; do
1163 test -e "$PROG" || continue
1164 echo "... running ${PROG##*/}"
1165 chroot $BUILD_ROOT "/usr/lib/build/finalize-system/${PROG##*/}" || cleanup_and_exit 1
1166 done
1167 fi
1168
1169 test -e $BUILD_ROOT/.build/init_buildsystem.data || HOST=`hostname`
1170 test -e $BUILD_ROOT/etc/hosts || echo "127.0.0.1 localhost" > $BUILD_ROOT/etc/hosts
1171 if ! grep -F "127.0.0.1 $HOST" $BUILD_ROOT/etc/hosts > /dev/null ; then
1172 # this makes a reverse lookup on 127.0.0.1 return the host name,
1173 # which is bad, but 127.0.0.2 does not work on all unix systems
1174 echo "127.0.0.1 $HOST" > $BUILD_ROOT/etc/hosts.new
1175 test -f $BUILD_ROOT/etc/hosts && cat $BUILD_ROOT/etc/hosts >> $BUILD_ROOT/etc/hosts.new
1176 mv $BUILD_ROOT/etc/hosts.new $BUILD_ROOT/etc/hosts
1177 fi
1178
1179 rm -f $BUILD_ROOT/.rpmmacros $BUILD_ROOT/root/.rpmmacros
1180 rm -rf "$BUILD_ROOT/.init_b_cache"
1181 rm -f $BUILD_IS_RUNNING
1182 rm -f $TMPFILE
1183
1184 cleanup_and_exit 0
1185
1186 # vim: set tabstop=8 softtabstop=4 shiftwidth=4 noexpandtab: