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.
6 # BUILD_ROOT here the packages will be installed/deleted
7 # BUILD_RPMS here we get our packages to install
8 # BUILD_ARCH path of the architectures we try
10 # (c) 1997-2005 SuSE GmbH Nuernberg, Germany
13 # needed globals variables
16 export YAST_IS_RUNNING="instsys"
17 export DEBIAN_FRONTEND=noninteractive
18 export DEBIAN_PRIORITY=critical
19 export BUILD_DIR=${BUILD_DIR:-/usr/lib/build}
20 # need to restore build root owner for non-root builds
25 . $BUILD_DIR/common_functions || exit 1
27 # should RPMs be installed with --force ?
30 BUILD_IS_RUNNING=$BUILD_ROOT/not-ready
31 TMPFILE=$BUILD_ROOT/tmpfile
32 #buildhost removed so that id can be generated from repo files
33 #RPMIDFMT="%{NAME}-%{VERSION}-%{RELEASE} %{BUILDHOST}-%{BUILDTIME}\n"
34 RPMIDFMT="%{NAME}-%{VERSION}-%{RELEASE} %{BUILDTIME}\n"
41 CREATE_BUILD_BINARIES=
43 while test -n "$1" ; do
49 --create-build-binaries)
51 CREATE_BUILD_BINARIES=true
55 USEUSEDFORBUILD=--useusedforbuild
66 --define|--with|--without)
67 definesnstuff[${#definesnstuff[@]}]="$1";
68 definesnstuff[${#definesnstuff[@]}]="$2";
72 repos[${#repos[@]}]="$2";
90 function cleanup_and_exit {
92 [ "$BUILD_ROOT" != / ] || chown $browner $BUILD_ROOT
93 # umount so init_buildsystem can be used standalone
94 # XXX: use stat -f /dev/pts/ -c %T to check whether it's mounted and not suppress errors then?
95 umount -n $BUILD_ROOT/proc/sys/fs/binfmt_misc 2> /dev/null || true
96 umount -n $BUILD_ROOT/proc 2> /dev/null || true
97 umount -n $BUILD_ROOT/dev/pts 2> /dev/null || true
98 umount -n $BUILD_ROOT/mnt 2> /dev/null || true
102 function clean_build_root () {
103 test -n "$BUILD_ROOT" && {
104 umount -n $BUILD_ROOT/proc/sys/fs/binfmt_misc 2> /dev/null || true
105 umount -n $BUILD_ROOT/proc 2> /dev/null || true
106 umount -n $BUILD_ROOT/dev/pts 2> /dev/null || true
107 umount -n $BUILD_ROOT/mnt 2> /dev/null || true
108 rm -rf -- $BUILD_ROOT/*
109 rm -rf -- $BUILD_ROOT/.build
110 rm -rf -- $BUILD_ROOT/.root
111 rm -rf -- $BUILD_ROOT/.init_b_cache
112 mkdir -p $BUILD_ROOT/proc
113 mkdir -p $BUILD_ROOT/dev/pts
114 if [ "$UID" = '0' ]; then
115 mount -n -tproc none $BUILD_ROOT/proc
116 mount -n -tdevpts none $BUILD_ROOT/dev/pts
121 function preinstall {
123 if test -n "$1" ; then
124 echo "preinstalling $1..."
125 cd $BUILD_ROOT || cleanup_and_exit 1
126 CPIO="cpio --extract --unconditional --preserve-modification-time --make-directories --no-absolute-filenames --quiet"
127 if test -e "$BUILD_ROOT/.init_b_cache/rpms/$1.rpm" ; then
128 PAYLOADDECOMPRESS=cat
129 case `rpm -qp --nodigest --nosignature --qf "%{PAYLOADCOMPRESSOR}\n" "$BUILD_ROOT/.init_b_cache/rpms/$1.rpm"` in
130 lzma) rpm --showrc | grep PayloadIsLzma > /dev/null || PAYLOADDECOMPRESS="lzma -d" ;;
131 xz) rpm --showrc | grep PayloadIsXz > /dev/null || PAYLOADDECOMPRESS="xz -d" ;;
133 if test "$PAYLOADDECOMPRESS" = "lzma -d" ; then
134 if ! lzma </dev/null >/dev/null 2>&1 ; then
135 test -f "$BUILD_DIR/lzmadec.sh" && PAYLOADDECOMPRESS="bash $BUILD_DIR/lzmadec.sh"
138 if test "$PAYLOADDECOMPRESS" = cat ; then
139 rpm2cpio "$BUILD_ROOT/.init_b_cache/rpms/$1.rpm" | $CPIO
141 rpm2cpio "$BUILD_ROOT/.init_b_cache/rpms/$1.rpm" | $PAYLOADDECOMPRESS | $CPIO
143 if test -e .init_b_cache/scripts/$1.run ; then
144 rpm -qp --nodigest --nosignature --qf "%{PREIN}" "$BUILD_ROOT/.init_b_cache/rpms/$1.rpm" > .init_b_cache/scripts/$1.pre
145 rpm -qp --nodigest --nosignature --qf "%{POSTIN}" "$BUILD_ROOT/.init_b_cache/rpms/$1.rpm" > .init_b_cache/scripts/$1.post
146 echo -n '(none)' > .init_b_cache/scripts/.none
147 cmp -s .init_b_cache/scripts/$1.pre .init_b_cache/scripts/.none && rm -f .init_b_cache/scripts/$1.pre
148 cmp -s .init_b_cache/scripts/$1.post .init_b_cache/scripts/.none && rm -f .init_b_cache/scripts/$1.post
149 rm -f .init_b_cache/scripts/.none
151 elif test -e "$BUILD_ROOT/.init_b_cache/rpms/$1.deb" ; then
152 ar x "$BUILD_ROOT/.init_b_cache/rpms/$1.deb" control.tar.gz data.tar.gz
153 mkdir -p .init_b_cache/scripts/control
154 tar -C .init_b_cache/scripts/control -xzf control.tar.gz
156 if test -e .init_b_cache/scripts/$1.run ; then
157 test -e .init_b_cache/scripts/control/preinst && mv .init_b_cache/scripts/control/preinst .init_b_cache/scripts/$1.pre
158 test -e .init_b_cache/scripts/control/postinst && mv .init_b_cache/scripts/control/postinst .init_b_cache/scripts/$1.post
160 rm -rf .init_b_cache/scripts/control control.tar.gz data.tar.gz
162 echo "warning: package $1 does not exist"
165 if test -n "$2" ; then
166 chroot $BUILD_ROOT /sbin/ldconfig 2>/dev/null
167 for PKG in $PACKAGES_TO_RUNSCRIPTS ; do
168 if test -e "$BUILD_ROOT/.init_b_cache/scripts/$PKG.pre" ; then
169 echo "running $PKG preinstall script"
170 if test -e "$BUILD_ROOT/.init_b_cache/rpms/$PKG.rpm" ; then
171 chroot $BUILD_ROOT sh ".init_b_cache/scripts/$PKG.pre" 0
173 chroot $BUILD_ROOT ".init_b_cache/scripts/$PKG.pre" install < /dev/null
175 rm -f "$BUILD_ROOT/.init_b_cache/scripts/$PKG.pre"
177 if test -e "$BUILD_ROOT/.init_b_cache/scripts/$PKG.post" ; then
178 echo "running $PKG postinstall script"
179 if test -e "$BUILD_ROOT/.init_b_cache/rpms/$PKG.rpm" ; then
180 chroot $BUILD_ROOT sh ".init_b_cache/scripts/$PKG.post" 1
182 chroot $BUILD_ROOT ".init_b_cache/scripts/$PKG.post" configure '' < /dev/null
184 rm -f "$BUILD_ROOT/.init_b_cache/scripts/$PKG.post"
191 if test $PSUF = rpm ; then
192 echo initializing rpm db...
193 chroot $BUILD_ROOT rpm --initdb || cleanup_and_exit 1
194 # hack: add nofsync to db config to speed up install
195 mkdir -p $BUILD_ROOT/root
196 echo '%__dbi_perms perms=0644 nofsync' > $BUILD_ROOT/.rpmmacros
197 echo '%__dbi_perms perms=0644 nofsync' > $BUILD_ROOT/root/.rpmmacros
199 # force dpkg into database to make epoch test work
200 if ! test "$BUILD_ROOT/.init_b_cache/rpms/dpkg.deb" -ef "$BUILD_ROOT/.init_b_cache/dpkg.deb" ; then
201 rm -f $BUILD_ROOT/.init_b_cache/dpkg.deb
202 cp $BUILD_ROOT/.init_b_cache/rpms/dpkg.deb $BUILD_ROOT/.init_b_cache/dpkg.deb || cleanup_and_exit 1
204 chroot $BUILD_ROOT dpkg -i --force all .init_b_cache/dpkg.deb >/dev/null 2>&1
209 test -z "$*" && return
210 rm -f $BUILD_ROOT/.init_b_cache/order.manifest
212 echo "$PKG" >> $BUILD_ROOT/.init_b_cache/order.manifest
214 $BUILD_DIR/order --dist "$BUILD_DIST" --archpath "$BUILD_ARCH" --configdir $BUILD_DIR/configs --manifest $BUILD_ROOT/.init_b_cache/order.manifest $BUILD_ROOT/.init_b_cache/rpms
215 rm -f $BUILD_ROOT/.init_b_cache/order.manifest
218 function create_devs {
219 local com file mode arg
221 mkdir -m 755 -p $BUILD_ROOT/dev/pts
222 test -f $BUILD_ROOT/dev/shm && rm -f $BUILD_ROOT/dev/shm
223 mkdir -m 755 -p $BUILD_ROOT/dev/shm
224 while read com file mode arg ; do
225 rm -f $BUILD_ROOT/dev/$file
226 if test $com = ln ; then
227 ln -s $arg $BUILD_ROOT/dev/$file
230 $com -m $mode $BUILD_ROOT/dev/$file $arg
235 mknod random 666 c 1 8
236 mknod urandom 644 c 1 9
239 mknod loop0 640 b 7 0
240 mknod loop1 640 b 7 1
241 mknod loop2 640 b 7 2
242 mknod loop3 640 b 7 3
243 ln fd 777 /proc/self/fd
250 # check whether the repo list contains a plain "zypp://". Add all
251 # enabled zypp repos in this case
252 maybe_add_all_zypp_repos()
256 for i in "${repos[@]}"; do
257 if [ "$i" = "zypp://" ]; then
258 for j in `grep -l enabled=1 /etc/zypp/repos.d/*.repo`; do
259 j="${j#/etc/zypp/repos.d/}"
260 r=("${r[@]}" "zypp://${j%.repo}")
269 function validate_cache_file {
271 maybe_add_all_zypp_repos
272 test "${repos[*]} ${BUILD_RPMS//:/ /}" != "$(cat $CACHE_FILE.id 2>/dev/null)" && rm -f $CACHE_FILE.id
273 test -f $CACHE_FILE || rm -f $CACHE_FILE.id
274 for SRC in "${repos[@]}" ${BUILD_RPMS//:/ /}; do
275 test -z "$SRC" && SRC=.
276 test "$SRC" -nt $CACHE_FILE && rm -f $CACHE_FILE.id
278 if ! test -f $CACHE_FILE.id ; then
279 test -z "$LIST_STATE" && echo initializing $CACHE_FILE ...
280 for SRC in "${repos[@]}" -- ${BUILD_RPMS//:/ /}; do
281 if test "$SRC" = '--' ; then
285 test -z "$SRC" && SRC=`pwd`
286 if [ "${SRC#zypp://}" != "$SRC" ]; then
287 set -- $BUILD_DIR/createrepomddeps "$SRC"
288 elif [ ! -e "$SRC" ]; then
289 echo "*** $SRC does not exist" >&2
291 elif [ -z "$findonly" -a -e "$SRC"/suse/setup/descr/packages -o -e "$SRC"/suse/setup/descr/packages.gz ]; then
292 set -- $BUILD_DIR/createyastdeps "$SRC"
293 elif [ -z "$findonly" -a -e "$SRC"/repodata/repomd.xml ]; then
294 set -- $BUILD_DIR/createrepomddeps "$SRC"
296 set -- $BUILD_DIR/createrpmdeps "$SRC"
299 "$@" || cleanup_and_exit 1
300 done > $CACHE_FILE.new
302 mv $CACHE_FILE.new $CACHE_FILE
303 echo "${repos[*]} ${BUILD_RPMS//:/ /}" > $CACHE_FILE.id
307 function register_qemu_user {
309 # Detect cross-build (fixed code) and copy qemus for cross-build emulation mode
310 # And copy also a static host binary shell to run the init scripts in the target chroot
312 if [ x"$BUILD_ARCH" == xarmv4l -o x"$BUILD_ARCH" == xarmv5el -o x"$BUILD_ARCH" == xarmv7el -o x"$BUILD_ARCH" == xsh4 -o x"$BUILD_ARCH" == xppc -o x"$BUILD_ARCH" == xppc64 -o x"$BUILD_ARCH" == xmips -o x"$BUILD_ARCH" == xmipsel ]; then
313 if [ -n "$(uname -m | grep '[x3-6]86')" ]; then
314 if [ -e /usr/sbin/qemu-binfmt-conf.sh ]; then
315 (mkdir -p $BUILD_ROOT/usr/bin $BUILD_ROOT/usr/sbin && set -x && cp /usr/bin/qemu-* $BUILD_ROOT/usr/bin && cp /usr/sbin/qemu-binfmt-conf.sh $BUILD_ROOT/usr/sbin)
317 # To initially run the init script, there needs to be also a static bash to register qemu in this chroot and though to start up /.build/build
318 if [ -e /bin/bash-static -a -e /bin/mount-static ]; then
319 (mkdir -p $BUILD_ROOT/bin && set -x && cp /bin/bash-static $BUILD_ROOT/bin && cp /bin/mount-static $BUILD_ROOT/bin && chmod a+x $BUILD_ROOT/bin/*-static )
321 if [ -e /proc/sys/fs/binfmt_misc/arm -o -e /proc/sys/fs/binfmt_misc/armeb -o -e /proc/sys/fs/binfmt_misc/sh4 -o -e /proc/sys/fs/binfmt_misc/mips -o -e /proc/sys/fs/binfmt_misc/ppc -o -e /proc/sys/fs/binfmt_misc/ppc64 ]; then
322 echo "qemu-* already registered"
324 if [ -e /usr/sbin/qemu-binfmt-conf.sh ]; then
325 echo "qemu-* will be registered"
326 (set -x && /usr/sbin/qemu-binfmt-conf.sh)
342 local zd="/var/cache/zypp/packages/"
343 SRC=$zd${url#zypp://}
344 if [ ! -e "$SRC" ]; then
345 local destdir="$zd/tmp"
347 echo "downloading $url ... ";
348 $BUILD_DIR/download "$destdir" "$url" || cleanup_and_exit 1
349 local destfile="$destdir/${url##*/}"
350 if [ ! -e "$destfile" ]; then
351 echo "expected $destfile after download but it's missing" >&2
354 rpm -K "$destfile" > $destfile.v || { echo "rpm verify failed" >&2; rm -rf "$destdir"; cleanup_and_exit 1; }
355 if grep "NOT OK" $destfile.v; then
360 mv "$destfile" "$SRC" || cleanup_and_exit 1
368 if [ "$BUILD_ROOT" = / ]; then
369 read dummy dummy browner dummy < <(ls -ld /)
372 if [ -n "$CLEAN_BUILD" ]; then
377 # now test if there was an incomplete run
379 if test -e $BUILD_IS_RUNNING ; then
380 echo It seems that there was an incomplete setup of $BUILD_ROOT.
381 echo To be sure, we will build it again completely...
382 umount -n $BUILD_ROOT/proc/sys/fs/binfmt_misc 2> /dev/null || true
383 umount -n $BUILD_ROOT/proc 2> /dev/null
384 umount -n $BUILD_ROOT/dev/pts 2> /dev/null
385 umount -n $BUILD_ROOT/mnt 2> /dev/null
386 echo "Your build system is broken!! Shall I execute"
388 echo " rm -rf -- $BUILD_ROOT/*"
390 echo "y - yes, cleanup the build root"
391 echo "N - No, abort build (default on enter)"
392 echo "c - Continue anyway with this build root"
396 c|C) rm -f $BUILD_IS_RUNNING ;;
397 y|Y) clean_build_root ;;
398 *) cleanup_and_exit 1 ;;
403 # register the QEMU emulator
404 # reset mmap_min_addr for QEMU
409 # store that we start to build system
412 touch $BUILD_IS_RUNNING
414 if test -n "$PREPARE_VM" ; then
415 rm -f $BUILD_ROOT/.build/init_buildsystem.data
417 if test -e $BUILD_ROOT/.build/init_buildsystem.data ; then
419 . $BUILD_ROOT/.build/init_buildsystem.data
420 if ! test -e $BUILD_ROOT/.init_b_cache/preinstall_finished ; then
424 touch $BUILD_ROOT/.init_b_cache/preinstall_finished
428 # now make sure that all the packages are installed.
430 rm -rf $BUILD_ROOT/.init_b_cache
431 mkdir -p $BUILD_ROOT/.init_b_cache/scripts
433 if test -z "$RPMLIST" ; then
435 # create rpmdeps file
437 CACHE_FILE=$BUILD_ROOT/.srcfiles.cache
441 # select and expand packages
443 RPMLIST=$BUILD_ROOT/.init_b_cache/rpmlist
444 test -z "$LIST_STATE" && echo "expanding package dependencies..."
445 if ! $BUILD_DIR/expanddeps $USEUSEDFORBUILD "${definesnstuff[@]}" --dist "$BUILD_DIST" --depfile "$CACHE_FILE" --archpath "$BUILD_ARCH" --configdir $BUILD_DIR/configs "${PKGS[@]}" > $RPMLIST ; then
446 rm -f $BUILD_IS_RUNNING
451 if test -n "$LIST_STATE" ; then
452 rm -f $BUILD_IS_RUNNING
453 while read PKG SRC ; do
454 test "$PKG" = "preinstall:" && continue
455 test "$PKG" = "runscripts:" && continue
456 test "$PKG" = "vminstall:" && continue
457 test "$PKG" = "dist:" && continue
458 test "$PKG" = "rpmid:" && continue
460 done < $BUILD_ROOT/.init_b_cache/rpmlist
461 rm -rf $BUILD_ROOT/.init_b_cache
466 PACKAGES_TO_PREINSTALL=
467 PACKAGES_TO_RUNSCRIPTS=
468 PACKAGES_TO_VMINSTALL=
471 mkdir -p $BUILD_ROOT/.init_b_cache/rpms
472 while read PKG SRC ; do
473 if test "$PKG" = "preinstall:" ; then
474 PACKAGES_TO_PREINSTALL=$SRC
477 if test "$PKG" = "vminstall:" ; then
478 PACKAGES_TO_VMINSTALL=$SRC
481 if test "$PKG" = "runscripts:" ; then
483 PACKAGES_TO_RUNSCRIPTS=$SRC
486 if test "$PKG" = "dist:" ; then
490 if test "$PKG" = "rpmid:" ; then
491 echo "${SRC#*:}" > $BUILD_ROOT/.init_b_cache/rpms/${SRC%%:*}.id
494 if [ "${SRC#/}" = "$SRC" ]; then
501 echo "unsupported url: $url" >&2
506 ln -s "$SRC" "$BUILD_ROOT/.init_b_cache/rpms/$PKG.${SRC##*.}"
507 PACKAGES_TO_INSTALL="$PACKAGES_TO_INSTALL $PKG"
511 test -z "$RUNSCRIPTS_SEEN" && PACKAGES_TO_RUNSCRIPTS="$PACKAGES_TO_PREINSTALL"
513 echo "$GUESSED_DIST" > $BUILD_ROOT/.guessed_dist
515 test -L $BUILD_ROOT/.init_b_cache/rpms/rpm.rpm || PSUF=deb
519 # now test if there is already a build dir.
521 if test ! -f $BUILD_ROOT/var/lib/rpm/packages.rpm -a ! -f $BUILD_ROOT/var/lib/rpm/Packages ; then
522 mkdir -p $BUILD_ROOT/var/lib/rpm || cleanup_and_exit 1
523 mkdir -p $BUILD_ROOT/usr/src/packages/SOURCES || cleanup_and_exit 1
524 mkdir -p $BUILD_ROOT/etc || cleanup_and_exit 1
525 mkdir -p $BUILD_ROOT/proc || cleanup_and_exit 1
526 test -f $BUILD_ROOT/etc/HOSTNAME || hostname -f > $BUILD_ROOT/etc/HOSTNAME
527 if test $PSUF = deb ; then
528 mkdir -p $BUILD_ROOT/var/lib/dpkg
529 mkdir -p $BUILD_ROOT/var/log
530 mkdir -p $BUILD_ROOT/etc/default
531 :> $BUILD_ROOT/var/lib/dpkg/status
532 :> $BUILD_ROOT/var/lib/dpkg/available
533 :> $BUILD_ROOT/var/log/dpkg.log
534 :> $BUILD_ROOT/etc/ld.so.conf
535 :> $BUILD_ROOT/etc/default/rcS
537 for PKG in $PACKAGES_TO_RUNSCRIPTS ; do
538 : > $BUILD_ROOT/.init_b_cache/scripts/$PKG.run
540 for PKG in $PACKAGES_TO_PREINSTALL ; do
541 preinstall ${PKG##*/}
543 if test -n "$PREPARE_VM" ; then
544 for PKG in $PACKAGES_TO_VMINSTALL ; do
545 preinstall ${PKG##*/}
548 if [ -w /root ]; then
549 test -c $BUILD_ROOT/dev/null || create_devs
551 test -e $BUILD_ROOT/etc/fstab || touch $BUILD_ROOT/etc/fstab
552 test -e $BUILD_ROOT/etc/ld.so.conf || cp $BUILD_ROOT/etc/ld.so.conf.in $BUILD_ROOT/etc/ld.so.conf
553 if test -z "$PREPARE_VM" ; then
556 touch $BUILD_ROOT/.init_b_cache/preinstall_finished
560 if test -n "$PREPARE_VM" ; then
561 mkdir -p $BUILD_ROOT/.build
562 echo "copying packages..."
563 for PKG in $PACKAGES_TO_INSTALL ; do
564 rm -f $BUILD_ROOT/.init_b_cache/$PKG.$PSUF
565 cp $BUILD_ROOT/.init_b_cache/rpms/$PKG.$PSUF $BUILD_ROOT/.init_b_cache/$PKG.$PSUF || cleanup_and_exit 1
566 ln -s -f ../$PKG.$PSUF $BUILD_ROOT/.init_b_cache/rpms/$PKG.$PSUF
569 # alreadyinstalled check will not work, but we have to live with
571 echo -n 'reordering...'
572 PACKAGES_TO_INSTALL=`reorder $PACKAGES_TO_INSTALL`
575 echo "PACKAGES_TO_INSTALL='${PACKAGES_TO_INSTALL//"'"/$Q}'" > $BUILD_ROOT/.build/init_buildsystem.data
576 echo "PACKAGES_TO_RUNSCRIPTS='${PACKAGES_TO_RUNSCRIPTS//"'"/$Q}'" >> $BUILD_ROOT/.build/init_buildsystem.data
577 echo "PSUF='$PSUF'" >> $BUILD_ROOT/.build/init_buildsystem.data
578 rm -f $BUILD_IS_RUNNING
582 mkdir -p $BUILD_ROOT/proc
583 mkdir -p $BUILD_ROOT/dev/pts
584 mount -n -tproc none $BUILD_ROOT/proc 2>/dev/null || true
585 mount -n -tdevpts none $BUILD_ROOT/dev/pts 2>/dev/null || true
588 # create .build.binaries directory if requested
590 rm -rf $BUILD_ROOT/.build.binaries
591 if test -n "$CREATE_BUILD_BINARIES" ; then
592 echo "creating .build.binaries directory..."
593 mkdir -p "$BUILD_ROOT/.build.binaries"
594 for PKG in $PACKAGES_TO_INSTALL ; do
595 test -L "$BUILD_ROOT/.init_b_cache/rpms/$PKG.$PSUF" || continue
596 LPKG=`readlink -f "$BUILD_ROOT/.init_b_cache/rpms/$PKG.$PSUF"`
597 ln "$LPKG" "$BUILD_ROOT/.build.binaries/$PKG.$PSUF" 2>/dev/null
598 test -f "$BUILD_ROOT/.build.binaries/$PKG.$PSUF" && continue
599 cp "$LPKG" "$BUILD_ROOT/.build.binaries/$PKG.$PSUF"
605 # get list and ids of already installed rpms
607 mkdir -p $BUILD_ROOT/.init_b_cache/alreadyinstalled
608 if test -f $BUILD_ROOT/var/lib/rpm/packages.rpm -o -f $BUILD_ROOT/var/lib/rpm/Packages ; then
609 chroot $BUILD_ROOT rpm -qa --qf "%{NAME} $RPMIDFMT" | (
611 echo "$ii" > "$BUILD_ROOT/.init_b_cache/alreadyinstalled/$pp"
617 # reorder packages (already done in vm continuation)
619 if ! test -e $BUILD_ROOT/.build/init_buildsystem.data ; then
620 echo -n 'reordering...'
621 PACKAGES_TO_INSTALL_FIRST=`reorder $PACKAGES_TO_INSTALL_FIRST`
622 PACKAGES_TO_INSTALL=`reorder $PACKAGES_TO_INSTALL`
628 chroot $BUILD_ROOT rpm --nodeps -e $PKG 2>&1 | \
632 r*failed:\ No\ such\ file\ or\ directory) ;;
633 error:\ failed\ to\ stat\ *:\ No\ such\ file\ or\ directory) ;;
634 error:\ *scriptlet\ failed*)
636 echo "re-try deleting $PKG using --noscripts"
637 chroot $BUILD_ROOT rpm --nodeps --noscripts -e $PKG || true
645 # delete all packages we don't want
647 mkdir -p $BUILD_ROOT/.init_b_cache/todelete
648 for PKG in $BUILD_ROOT/.init_b_cache/alreadyinstalled/* ; do
650 test "$PKG" = "*" && continue
651 ln $BUILD_ROOT/.init_b_cache/alreadyinstalled/$PKG $BUILD_ROOT/.init_b_cache/todelete/$PKG
653 for PKG in $PACKAGES_TO_INSTALL_FIRST $PACKAGES_TO_INSTALL ; do
654 rm -f $BUILD_ROOT/.init_b_cache/todelete/$PKG
656 for PKG in $BUILD_ROOT/.init_b_cache/todelete/* ; do
658 test "$PKG" = "*" && continue
663 rm -rf $BUILD_ROOT/.init_b_cache/todelete
665 rm -rf $BUILD_ROOT/.init_b_cache/preinstalls
666 mkdir -p $BUILD_ROOT/.init_b_cache/preinstalls
667 for PKG in $PACKAGES_TO_PREINSTALL ; do
668 touch "$BUILD_ROOT/.init_b_cache/preinstalls/$PKG"
671 rm -rf $BUILD_ROOT/installed-pkg
672 mkdir -p $BUILD_ROOT/installed-pkg
676 # on Fedora 10 rpmbuild is in a separate package so we need something else to
678 test -x $BUILD_ROOT/usr/bin/rpmsign && RPMCHECKOPTS="--nodigest --nosignature"
679 test -x /usr/bin/rpmsign && RPMCHECKOPTS_HOST="--nodigest --nosignature"
681 for PKG in $PACKAGES_TO_INSTALL_FIRST RUN_LDCONFIG $PACKAGES_TO_INSTALL ; do
685 test -x $BUILD_ROOT/sbin/ldconfig && chroot $BUILD_ROOT /sbin/ldconfig 2>&1
690 test -f $BUILD_ROOT/installed-pkg/$PKG && continue
692 if test $PSUF = deb ; then
693 # debian world, install deb files
694 test -L $BUILD_ROOT/.init_b_cache/rpms/$PKG.deb || continue
695 if ! test "$BUILD_ROOT/.init_b_cache/rpms/$PKG.deb" -ef "$BUILD_ROOT/.init_b_cache/$PKG.deb" ; then
696 rm -f $BUILD_ROOT/.init_b_cache/$PKG.deb
697 cp $BUILD_ROOT/.init_b_cache/rpms/$PKG.deb $BUILD_ROOT/.init_b_cache/$PKG.deb || cleanup_and_exit 1
699 PKGID=`readlink $BUILD_ROOT/.init_b_cache/rpms/$PKG.deb`
701 PKGID="${PKGID%.deb}"
702 echo "installing ${PKGID%_*}"
703 ( chroot $BUILD_ROOT dpkg --install --force all .init_b_cache/$PKG.deb 2>&1 || touch $BUILD_ROOT/exit ) | \
704 perl -ne '$|=1;/^(Configuration file|Installing new config file|Selecting previously deselected|\(Reading database|Unpacking |Setting up|Creating config file|Preparing to replace dpkg)/||/^$/||print'
706 echo "$PKGID debian" > $BUILD_ROOT/installed-pkg/$PKG
710 test -L $BUILD_ROOT/.init_b_cache/rpms/$PKG.rpm || continue
712 if test -f $BUILD_ROOT/.init_b_cache/rpms/$PKG.id -a -f $BUILD_ROOT/.init_b_cache/alreadyinstalled/$PKG ; then
713 read PKGID < $BUILD_ROOT/.init_b_cache/rpms/$PKG.id
714 read OLDPKGID < $BUILD_ROOT/.init_b_cache/alreadyinstalled/$PKG
715 if test "$PKGID" = "$OLDPKGID" ; then
716 #echo "keeping ${PKGID%% *}"
717 echo "$PKGID" > $BUILD_ROOT/installed-pkg/$PKG
722 PKGID=`rpm -qp --qf "$RPMIDFMT" $RPMCHECKOPTS_HOST $BUILD_ROOT/.init_b_cache/rpms/$PKG.rpm`
724 if test -f $BUILD_ROOT/.init_b_cache/alreadyinstalled/$PKG ; then
725 read OLDPKGID < $BUILD_ROOT/.init_b_cache/alreadyinstalled/$PKG
726 if test "$PKGID" != "$OLDPKGID" ; then
727 echo deleting unwanted ${OLDPKGID%% *}
729 elif test "$VERIFY_BUILD_SYSTEM" = true ; then
730 chroot $BUILD_ROOT rpm --verify $PKG 2>&1 | tee $TMPFILE
731 if grep ^missing $TMPFILE > /dev/null ; then
732 echo deleting incomplete ${PKGID%% *}
735 #echo "keeping ${PKGID%% *}"
736 echo "$PKGID" > $BUILD_ROOT/installed-pkg/$PKG
740 #echo "keeping ${PKGID%% *}"
741 echo "$PKGID" > $BUILD_ROOT/installed-pkg/$PKG
744 if test -e "$BUILD_ROOT/.init_b_cache/preinstalls/$PKG" ; then
746 test rpm = "$PKG" && chroot $BUILD_ROOT rpm --rebuilddb
749 export ADDITIONAL_PARAMS=
750 if test "$USE_FORCE" = true ; then
751 export ADDITIONAL_PARAMS="$ADDITIONAL_PARAMS --force"
753 echo "installing ${PKGID%% *}"
754 if ! test "$BUILD_ROOT/.init_b_cache/rpms/$PKG.rpm" -ef "$BUILD_ROOT/.init_b_cache/$PKG.rpm" ; then
755 rm -f $BUILD_ROOT/.init_b_cache/$PKG.rpm
756 cp $BUILD_ROOT/.init_b_cache/rpms/$PKG.rpm $BUILD_ROOT/.init_b_cache/$PKG.rpm || cleanup_and_exit 1
758 ( chroot $BUILD_ROOT rpm --ignorearch --nodeps -U --oldpackage --ignoresize $RPMCHECKOPTS \
759 $ADDITIONAL_PARAMS .init_b_cache/$PKG.rpm 2>&1 || \
760 touch $BUILD_ROOT/exit ) | \
761 grep -v "^warning:.*saved as.*rpmorig$"
762 # delete link so package is only installed once
763 rm -f $BUILD_ROOT/.init_b_cache/$PKG.rpm
765 echo "$PKGID" > $BUILD_ROOT/installed-pkg/$PKG
769 if test $PSUF = deb ; then
770 echo "configure all installed packages..."
771 # configure all packages after complete installation, not for each package like rpm does
772 # We need to run this twice, because of cyclic dependencies as it does not succeed on most
773 # debian based distros in the first attempt.
774 if ! chroot $BUILD_ROOT dpkg --configure --pending 2>&1; then
775 echo "first configure attempt failed, trying again..."
776 chroot $BUILD_ROOT dpkg --configure --pending 2>&1 || touch $BUILD_ROOT/exit
780 # devices can vanish if devs got uninstalled
781 test -c $BUILD_ROOT/dev/null || create_devs
783 cd $BUILD_ROOT || cleanup_and_exit 1
788 rm -f $BUILD_ROOT/etc/mtab
789 cp /proc/mounts $BUILD_ROOT/etc/mtab
790 chmod 644 $BUILD_ROOT/etc/mtab
793 # to be sure, path is set correctly, we have to source /etc/profile before
797 #rm -f $BUILD_ROOT/bin/rpm.sh
798 #cp $BUILD_LIBDIR/lib/rpm.sh $BUILD_ROOT/bin/rpm.sh
799 #chmod 755 $BUILD_ROOT/bin/rpm.sh
800 #test -f $BUILD_ROOT/bin/rpm -a ! -L $BUILD_ROOT/bin/rpm && \
801 # mv $BUILD_ROOT/bin/rpm $BUILD_ROOT/bin/rpm.bin
802 #rm -f $BUILD_ROOT/bin/rpm
803 #ln -s rpm.sh $BUILD_ROOT/bin/rpm
806 # some packages use uname -r to decide which kernel is used to build for.
807 # this does not work in autobuild always. Here is a wrapper script, that
808 # gets Version from kernel sources.
811 #rm -f $BUILD_ROOT/bin/uname.sh
812 #cp -v $BUILD_LIBDIR/lib/uname.sh $BUILD_ROOT/bin/uname.sh
813 #chmod 755 $BUILD_ROOT/bin/uname.sh
814 #test -f $BUILD_ROOT/bin/uname -a ! -L $BUILD_ROOT/bin/uname && \
815 # mv $BUILD_ROOT/bin/uname $BUILD_ROOT/bin/uname.bin
816 #rm -f $BUILD_ROOT/bin/uname
817 #ln -s uname.sh $BUILD_ROOT/bin/uname
820 # some distributions have a /etc/rpmrc or /etc/rpm/macros and some not.
821 # make sure, that it is setup correctly.
824 #rm -f $BUILD_ROOT/etc/rpmrc
825 #if test -e $BUILD_LIBDIR/lib/rpmrc.$BUILD_BASENAME ; then
826 # cp -v $BUILD_LIBDIR/lib/rpmrc.$BUILD_BASENAME $BUILD_ROOT/etc/rpmrc
827 #elif test -e $BUILD_LIBDIR/lib/rpmrc ; then
828 # cp -v $BUILD_LIBDIR/lib/rpmrc $BUILD_ROOT/etc/rpmrc
832 #rm -f $BUILD_ROOT/etc/rpm/macros $BUILD_ROOT/etc/rpm/suse_macros
833 #mkdir -p $BUILD_ROOT/etc/rpm
834 #if test -e $BUILD_LIBDIR/lib/macros.$BUILD_BASENAME ; then
835 # cp -v $BUILD_LIBDIR/lib/macros.$BUILD_BASENAME $BUILD_ROOT/etc/rpm/macros
836 # cp -v $BUILD_LIBDIR/lib/macros.$BUILD_BASENAME $BUILD_ROOT/etc/rpm/suse_macros
837 #elif test -e $BUILD_LIBDIR/lib/macros ; then
838 # cp -v $BUILD_LIBDIR/lib/macros $BUILD_ROOT/etc/rpm/macros
839 # cp -v $BUILD_LIBDIR/lib/macros $BUILD_ROOT/etc/rpm/suse_macros
843 # make sure, that our nis is not present in the chroot system
845 test -e $BUILD_ROOT/etc/nsswitch.conf && {
846 echo removing nis flags from $BUILD_ROOT/etc/nsswitch.conf...
847 cat $BUILD_ROOT/etc/nsswitch.conf | sed -e"s:nis::g" > \
848 $BUILD_ROOT/etc/nsswitch.conf.tmp
849 mv $BUILD_ROOT/etc/nsswitch.conf.tmp $BUILD_ROOT/etc/nsswitch.conf
853 # creating some default directories
854 for DIR in /usr/share/doc/packages \
855 /usr/X11R6/include/X11/pixmaps \
856 /usr/X11R6/include/X11/bitmaps ; do
857 mkdir -p $BUILD_ROOT/$DIR
860 for FILE in /var/run/utmp /var/log/wtmp /etc/fstab ; do
861 touch $BUILD_ROOT/$FILE
864 echo now finalizing build dir...
865 CHROOT_RETURN="`chroot $BUILD_ROOT /sbin/ldconfig 2>&1`"
866 case "$CHROOT_RETURN" in
868 chroot $BUILD_ROOT /sbin/ldconfig
870 echo chroot $BUILD_ROOT /sbin/ldconfig
872 echo "$CHROOT_RETURN"
874 echo "Problem with ldconfig. It's better to reinit the build system..."
879 test -x $BUILD_ROOT/usr/sbin/Check && chroot $BUILD_ROOT /usr/sbin/Check
881 mkdir -p $BUILD_ROOT/var/adm/packages
882 touch $BUILD_ROOT/var/adm/packages
883 if test -x $BUILD_ROOT/sbin/SuSEconfig ; then
884 if grep norestarts $BUILD_ROOT/sbin/SuSEconfig > /dev/null ; then
885 chroot $BUILD_ROOT /sbin/SuSEconfig --norestarts --force
887 chroot $BUILD_ROOT /sbin/SuSEconfig --force
891 if test -x $BUILD_ROOT/usr/X11R6/bin/switch2mesasoft ; then
892 chroot $BUILD_ROOT /usr/X11R6/bin/switch2mesasoft
895 for PROG in /usr/bin/TeX/texhash /usr/bin/texhash ; do
896 test -x $BUILD_ROOT/$PROG && \
897 chroot $BUILD_ROOT bash -c ". /etc/profile ; $PROG"
900 if test -e $BUILD_ROOT/usr/share/zoneinfo/UTC ; then
901 chroot $BUILD_ROOT zic -l UTC
904 test -e $BUILD_ROOT/.build/init_buildsystem.data || HOST=`hostname`
905 test -e $BUILD_ROOT/etc/hosts || echo "127.0.0.1 localhost" > $BUILD_ROOT/etc/hosts
906 if ! grep -F "127.0.0.1 $HOST" $BUILD_ROOT/etc/hosts > /dev/null ; then
907 # this makes a reverse lookup on 127.0.0.1 return the host name,
908 # which is bad, but 127.0.0.2 does not work on all unix systems
909 echo "127.0.0.1 $HOST" > $BUILD_ROOT/etc/hosts.new
910 test -f $BUILD_ROOT/etc/hosts && cat $BUILD_ROOT/etc/hosts >> $BUILD_ROOT/etc/hosts.new
911 mv $BUILD_ROOT/etc/hosts.new $BUILD_ROOT/etc/hosts
914 if test -x $BUILD_ROOT/bin/rpm -a ! -f $BUILD_ROOT/var/lib/rpm/packages.rpm -a ! -f $BUILD_ROOT/var/lib/rpm/Packages ; then
915 echo "initializing rpm db..."
916 chroot $BUILD_ROOT rpm --initdb || cleanup_and_exit 1
917 # create provides index
918 chroot $BUILD_ROOT rpm -q --whatprovides rpm >/dev/null 2>&1
921 # create modules.dep in kvm/xen
922 # This can not work, until we use the native repository kernel
923 #if [ $BUILD_ROOT = "/" -a -x /sbin/depmod ]; then
927 rm -f $BUILD_ROOT/.rpmmacros $BUILD_ROOT/root/.rpmmacros
928 rm -rf $BUILD_ROOT/.init_b_cache
929 rm -f $BUILD_IS_RUNNING