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";
97 [ "$BUILD_ROOT" != / ] || chown $browner $BUILD_ROOT
98 # umount so init_buildsystem can be used standalone
99 # XXX: use stat -f /dev/pts/ -c %T to check whether it's mounted and not suppress errors then?
100 umount -n $BUILD_ROOT/proc/sys/fs/binfmt_misc 2> /dev/null || true
101 umount -n $BUILD_ROOT/proc 2> /dev/null || true
102 umount -n $BUILD_ROOT/dev/pts 2> /dev/null || true
103 umount -n $BUILD_ROOT/mnt 2> /dev/null || true
109 test -n "$BUILD_ROOT" && {
110 umount -n $BUILD_ROOT/proc/sys/fs/binfmt_misc 2> /dev/null || true
111 umount -n $BUILD_ROOT/proc 2> /dev/null || true
112 umount -n $BUILD_ROOT/dev/pts 2> /dev/null || true
113 umount -n $BUILD_ROOT/mnt 2> /dev/null || true
114 rm -rf -- $BUILD_ROOT/*
115 rm -rf -- $BUILD_ROOT/.build
116 rm -rf -- $BUILD_ROOT/.root
117 rm -rf -- $BUILD_ROOT/.init_b_cache
118 mkdir -p $BUILD_ROOT/proc
119 mkdir -p $BUILD_ROOT/dev/pts
120 if [ "$UID" = '0' ]; then
121 mount -n -tproc none $BUILD_ROOT/proc
122 mount -n -tdevpts none $BUILD_ROOT/dev/pts
130 echo "preinstalling $1..."
131 cd $BUILD_ROOT || cleanup_and_exit 1
132 if test -x /usr/bin/bsdtar ; then
133 CPIO="/usr/bin/bsdtar --chroot -o --numeric-owner -x -f-"
134 TAR="/usr/bin/bsdtar --chroot -o --numeric-owner -x"
136 CPIO="cpio --extract --unconditional --preserve-modification-time --make-directories --no-absolute-filenames --quiet"
139 if test -e "$BUILD_ROOT/.init_b_cache/rpms/$1.rpm" ; then
140 PAYLOADDECOMPRESS=cat
141 case `rpm -qp --nodigest --nosignature --qf "%{PAYLOADCOMPRESSOR}\n" "$BUILD_ROOT/.init_b_cache/rpms/$1.rpm"` in
142 lzma) rpm --showrc | grep PayloadIsLzma > /dev/null || PAYLOADDECOMPRESS="lzma -d" ;;
143 xz) rpm --showrc | grep PayloadIsXz > /dev/null || PAYLOADDECOMPRESS="xz -d" ;;
145 if test "$PAYLOADDECOMPRESS" = "lzma -d" ; then
146 if ! lzma </dev/null >/dev/null 2>&1 ; then
147 test -f "$BUILD_DIR/lzmadec.sh" && PAYLOADDECOMPRESS="bash $BUILD_DIR/lzmadec.sh"
150 if test "$PAYLOADDECOMPRESS" = "xz -d" ; then
151 if ! xz </dev/null >/dev/null 2>&1 ; then
152 test -f "$BUILD_DIR/xzdec.sh" && PAYLOADDECOMPRESS="bash $BUILD_DIR/xzdec.sh"
155 if test "$PAYLOADDECOMPRESS" = cat ; then
156 rpm2cpio "$BUILD_ROOT/.init_b_cache/rpms/$1.rpm" | $CPIO
158 rpm2cpio "$BUILD_ROOT/.init_b_cache/rpms/$1.rpm" | $PAYLOADDECOMPRESS | $CPIO
160 if test -e ".init_b_cache/scripts/$1.run" ; then
161 rpm -qp --nodigest --nosignature --qf "%{PREIN}" "$BUILD_ROOT/.init_b_cache/rpms/$1.rpm" > ".init_b_cache/scripts/$1.pre"
162 rpm -qp --nodigest --nosignature --qf "%{POSTIN}" "$BUILD_ROOT/.init_b_cache/rpms/$1.rpm" > ".init_b_cache/scripts/$1.post"
163 echo -n '(none)' > .init_b_cache/scripts/.none
164 cmp -s ".init_b_cache/scripts/$1.pre" .init_b_cache/scripts/.none && rm -f ".init_b_cache/scripts/$1.pre"
165 cmp -s ".init_b_cache/scripts/$1.post" .init_b_cache/scripts/.none && rm -f ".init_b_cache/scripts/$1.post"
166 rm -f .init_b_cache/scripts/.none
168 elif test -e "$BUILD_ROOT/.init_b_cache/rpms/$1.deb" ; then
169 ar x "$BUILD_ROOT/.init_b_cache/rpms/$1.deb" control.tar.gz data.tar.gz
170 mkdir -p .init_b_cache/scripts/control
171 $TAR -C .init_b_cache/scripts/control -z -f control.tar.gz
172 $TAR -z -f data.tar.gz
173 if test -e ".init_b_cache/scripts/$1.run" ; then
174 test -e .init_b_cache/scripts/control/preinst && mv .init_b_cache/scripts/control/preinst ".init_b_cache/scripts/$1.pre"
175 test -e .init_b_cache/scripts/control/postinst && mv .init_b_cache/scripts/control/postinst ".init_b_cache/scripts/$1.post"
177 rm -rf .init_b_cache/scripts/control control.tar.gz data.tar.gz
179 echo "warning: package $1 does not exist"
185 chroot $BUILD_ROOT /sbin/ldconfig 2>/dev/null
186 for PKG in $PACKAGES_TO_RUNSCRIPTS ; do
187 if test -e "$BUILD_ROOT/.init_b_cache/scripts/$PKG.pre" ; then
188 echo "running $PKG preinstall script"
189 if test -e "$BUILD_ROOT/.init_b_cache/rpms/$PKG.rpm" ; then
190 chroot $BUILD_ROOT sh ".init_b_cache/scripts/$PKG.pre" 0
192 chroot $BUILD_ROOT ".init_b_cache/scripts/$PKG.pre" install < /dev/null
194 rm -f "$BUILD_ROOT/.init_b_cache/scripts/$PKG.pre"
196 if test -e "$BUILD_ROOT/.init_b_cache/scripts/$PKG.post" ; then
197 echo "running $PKG postinstall script"
198 if test -e "$BUILD_ROOT/.init_b_cache/rpms/$PKG.rpm" ; then
199 chroot $BUILD_ROOT sh ".init_b_cache/scripts/$PKG.post" 1
201 chroot $BUILD_ROOT ".init_b_cache/scripts/$PKG.post" configure '' < /dev/null
203 rm -f "$BUILD_ROOT/.init_b_cache/scripts/$PKG.post"
211 if test $PSUF = rpm ; then
212 echo initializing rpm db...
213 chroot $BUILD_ROOT rpm --initdb || cleanup_and_exit 1
214 # hack: add nofsync to db config to speed up install
215 mkdir -p $BUILD_ROOT/root
216 echo '%__dbi_perms perms=0644 nofsync' > $BUILD_ROOT/.rpmmacros
217 echo '%__dbi_perms perms=0644 nofsync' > $BUILD_ROOT/root/.rpmmacros
219 # force dpkg into database to make epoch test work
220 if ! test "$BUILD_ROOT/.init_b_cache/rpms/dpkg.deb" -ef "$BUILD_ROOT/.init_b_cache/dpkg.deb" ; then
221 rm -f $BUILD_ROOT/.init_b_cache/dpkg.deb
222 cp $BUILD_ROOT/.init_b_cache/rpms/dpkg.deb $BUILD_ROOT/.init_b_cache/dpkg.deb || cleanup_and_exit 1
224 chroot $BUILD_ROOT dpkg -i --force all .init_b_cache/dpkg.deb >/dev/null 2>&1
230 test -z "$*" && return
231 rm -f $BUILD_ROOT/.init_b_cache/order.manifest
233 echo "$PKG" >> $BUILD_ROOT/.init_b_cache/order.manifest
235 $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
236 rm -f $BUILD_ROOT/.init_b_cache/order.manifest
241 local com file mode arg
243 mkdir -m 755 -p $BUILD_ROOT/dev/pts
244 test -f $BUILD_ROOT/dev/shm && rm -f $BUILD_ROOT/dev/shm
245 mkdir -m 755 -p $BUILD_ROOT/dev/shm
246 while read com file mode arg ; do
247 rm -f $BUILD_ROOT/dev/$file
248 if test $com = ln ; then
249 ln -s $arg $BUILD_ROOT/dev/$file
252 $com -m $mode $BUILD_ROOT/dev/$file $arg
257 mknod random 666 c 1 8
258 mknod urandom 644 c 1 9
261 mknod loop0 640 b 7 0
262 mknod loop1 640 b 7 1
263 mknod loop2 640 b 7 2
264 mknod loop3 640 b 7 3
265 ln fd 777 /proc/self/fd
272 # check whether the repo list contains a plain "zypp://". Add all
273 # enabled zypp repos in this case
274 maybe_add_all_zypp_repos()
278 for i in "${repos[@]}"; do
279 if [ "$i" = "zypp://" ]; then
281 j="${j#/etc/zypp/repos.d/}"
282 r=("${r[@]}" "zypp://${j%.repo}")
283 done < <(grep -l enabled=1 /etc/zypp/repos.d/*.repo)
291 validate_cache_file()
294 maybe_add_all_zypp_repos
295 if ! test -f $CACHE_FILE || ! test -f $CACHE_FILE.id || \
296 test "${repos[*]} ${BUILD_RPMS//:/ /}" != "$(cat $CACHE_FILE.id 2>/dev/null)"; then
299 for SRC in "${repos[@]}" ${BUILD_RPMS//:/ /}; do
300 test -n "$SRC" || SRC=.
301 if [ "${SRC#zypp://}" != "$SRC" ]; then
302 SRC="/var/cache/zypp/raw" # XXX can't use name here as we'd need to parse the file
304 if test "$SRC" -nt $CACHE_FILE; then
310 if ! test -f $CACHE_FILE.id ; then
311 test -z "$LIST_STATE" && echo initializing $CACHE_FILE ...
312 for SRC in "${repos[@]}" -- ${BUILD_RPMS//:/ /}; do
313 if test "$SRC" = '--' ; then
317 test -z "$SRC" && SRC=`pwd`
318 if [ "${SRC#zypp://}" != "$SRC" ]; then
319 set -- $BUILD_DIR/createrepomddeps "$SRC"
320 elif [ "${SRC#http://}" != "$SRC" -o "${SRC#https://}" != "$SRC" -o "${SRC#ftp://}" != "$SRC" -o "${SRC#ftps://}" != "$SRC" ]; then
321 mkdir -p "$(getcachedir "$SRC")"
322 set -- $BUILD_DIR/createrepomddeps --cachedir="$CACHE_DIR" "$SRC"
323 elif [ ! -e "$SRC" ]; then
324 echo "*** $SRC does not exist" >&2
326 elif [ -z "$findonly" -a -e "$SRC"/suse/setup/descr/packages -o -e "$SRC"/suse/setup/descr/packages.gz ]; then
327 set -- $BUILD_DIR/createyastdeps "$SRC"
328 elif [ -z "$findonly" -a -e "$SRC"/repodata/repomd.xml ]; then
329 set -- $BUILD_DIR/createrepomddeps "$SRC"
331 set -- $BUILD_DIR/createrpmdeps "$SRC"
334 "$@" || cleanup_and_exit 1
336 done > $CACHE_FILE.new
338 mv $CACHE_FILE.new $CACHE_FILE
339 echo "${repos[*]} ${BUILD_RPMS//:/ /}" > $CACHE_FILE.id
344 # Detect cross-build (fixed code) and copy qemus for cross-build emulation mode
345 # And copy also a static host binary shell to run the init scripts in the target chroot
350 mkdir -p $BUILD_ROOT/usr/bin $BUILD_ROOT/usr/sbin
351 install -m755 /usr/bin/qemu-* $BUILD_ROOT/usr/bin
352 install -m755 /usr/sbin/qemu-binfmt-conf.sh $BUILD_ROOT/usr/sbin
353 # To initially run the init script, there needs to be also a
354 # static bash to register qemu in this chroot and to start up
356 if [ -n "$PREPARE_VM" ]; then
357 mkdir -p $BUILD_ROOT/bin
358 install -m755 /bin/bash-static $BUILD_ROOT/bin
359 install -m755 /bin/mount-static $BUILD_ROOT/bin
363 check_binfmt_registered()
366 for arch in arm $EMULATOR_ARCHS; do
367 if test -e /proc/sys/fs/binfmt_misc/$arch; then
385 if [ "${url:0:7}" == "zypp://" ] ; then
386 cachedir="/var/cache/zypp/packages/"
387 SRC="$cachedir${url#zypp://}"
388 mkdir -p "${SRC%/*}" || cleanup_and_exit 1
389 elif [ "${url:0:7}" == "http://" -o "${url:0:8}" == "https://" -o "${url:0:6}" == "ftp://" -o "${url:0:7}" == "ftps://" ] ; then
390 cachedir="$(getcachedir "$url")"
391 local name="$(basename "$url")"
392 SRC="$cachedir/$name"
394 echo "Invalid url: $url"
398 if [ ! -e "$SRC" ]; then
399 local destdir="$cachedir/tmp"
401 echo "downloading $url ... ";
402 $BUILD_DIR/download "$destdir" "$url" || cleanup_and_exit 1
403 local destfile="$destdir/${url##*/}"
404 if [ ! -e "$destfile" ]; then
405 echo "expected $destfile after download but it's missing" >&2
408 rpm -K "$destfile" > $destfile.v || { echo "rpm verify failed" >&2; rm -rf "$destdir"; cleanup_and_exit 1; }
409 if grep "NOT OK" $destfile.v; then
414 mv "$destfile" "$SRC" || cleanup_and_exit 1
421 for repo in "${repos[@]}" ; do
422 if [ "${url:0:${#repo}}" == "$repo" ] ; then
423 read repoid dummy < <(echo -n "$repo" | md5sum)
424 echo "$CACHE_DIR/$repoid"
433 local name=$(basename $url)
434 local cachedir=$(getcachedir $url)
435 local destfile="$cachedir/$name"
443 if [ "$BUILD_ROOT" = / ]; then
444 read dummy dummy browner dummy < <(ls -ld /)
447 if [ -n "$CLEAN_BUILD" ]; then
452 # now test if there was an incomplete run
454 if test -e $BUILD_IS_RUNNING ; then
455 echo It seems that there was an incomplete setup of $BUILD_ROOT.
456 echo To be sure, we will build it again completely...
457 umount -n $BUILD_ROOT/proc/sys/fs/binfmt_misc 2> /dev/null || true
458 umount -n $BUILD_ROOT/proc 2> /dev/null
459 umount -n $BUILD_ROOT/dev/pts 2> /dev/null
460 umount -n $BUILD_ROOT/mnt 2> /dev/null
461 echo "Your build system is broken!! Shall I execute"
463 echo " rm -rf -- $BUILD_ROOT/*"
465 echo "y - yes, cleanup the build root"
466 echo "N - No, abort build (default on enter)"
467 echo "c - Continue anyway with this build root"
471 c|C) rm -f $BUILD_IS_RUNNING ;;
472 y|Y) clean_build_root ;;
473 *) cleanup_and_exit 1 ;;
478 # store that we start to build system
481 touch $BUILD_IS_RUNNING
483 if test -n "$PREPARE_VM" ; then
484 rm -f $BUILD_ROOT/.build/init_buildsystem.data
486 if test -e $BUILD_ROOT/.build/init_buildsystem.data ; then
488 . $BUILD_ROOT/.build/init_buildsystem.data
489 if ! test -e $BUILD_ROOT/.init_b_cache/preinstall_finished ; then
493 touch $BUILD_ROOT/.init_b_cache/preinstall_finished
497 # now make sure that all the packages are installed.
499 rm -rf $BUILD_ROOT/.init_b_cache
500 mkdir -p $BUILD_ROOT/.init_b_cache/scripts
502 if test -z "$RPMLIST" ; then
504 # create rpmdeps file
506 CACHE_FILE=$BUILD_ROOT/.srcfiles.cache
510 # select and expand packages
512 RPMLIST=$BUILD_ROOT/.init_b_cache/rpmlist
513 test -z "$LIST_STATE" && echo "expanding package dependencies..."
514 if ! $BUILD_DIR/expanddeps $USEUSEDFORBUILD "${definesnstuff[@]}" --dist "$BUILD_DIST" --depfile "$CACHE_FILE" --archpath "$BUILD_ARCH" --configdir $BUILD_DIR/configs "${PKGS[@]}" > $RPMLIST ; then
515 rm -f $BUILD_IS_RUNNING
520 if test -n "$LIST_STATE" ; then
521 rm -f $BUILD_IS_RUNNING
522 while read PKG SRC ; do
523 test "$PKG" = "preinstall:" && continue
524 test "$PKG" = "runscripts:" && continue
525 test "$PKG" = "cbpreinstall:" && continue
526 test "$PKG" = "vminstall:" && continue
527 test "$PKG" = "dist:" && continue
528 test "$PKG" = "rpmid:" && continue
530 done < $BUILD_ROOT/.init_b_cache/rpmlist
531 rm -rf $BUILD_ROOT/.init_b_cache
536 # copy the QEMU emulator
538 if check_use_emulator; then
540 if [ -z "$PREPARE_VM" ]; then
541 if ! check_binfmt_registered; then
542 echo "registering binfmt handlers"
543 /usr/sbin/qemu-binfmt-conf.sh
545 read mmap_min_addr < /proc/sys/vm/mmap_min_addr
546 if [ "$mmap_min_addr" != 0 ]; then
547 echo "Warning: mmap_min_addr is != 0. If programs fail at mmap this could be the reason"
553 PACKAGES_TO_PREINSTALL=
554 PACKAGES_TO_RUNSCRIPTS=
555 PACKAGES_TO_VMINSTALL=
556 PACKAGES_TO_CBPREINSTALL=
557 PACKAGES_TO_CBINSTALL=
560 mkdir -p $BUILD_ROOT/.init_b_cache/rpms
561 while read PKG SRC ; do
562 if test "$PKG" = "preinstall:" ; then
563 PACKAGES_TO_PREINSTALL=$SRC
566 if test "$PKG" = "vminstall:" ; then
567 PACKAGES_TO_VMINSTALL=$SRC
570 # these additional preinstall / install values are only set for
571 # emulated "CrossBuild" setups - thus CB(pre)install
572 if test "$PKG" = "cbpreinstall:" ; then
573 if is_emulator_arch ; then
574 PACKAGES_TO_CBPREINSTALL=$SRC
578 if test "$PKG" = "cbinstall:" ; then
579 if is_emulator_arch ; then
580 PACKAGES_TO_CBINSTALL=$SRC
584 if test "$PKG" = "runscripts:" ; then
586 PACKAGES_TO_RUNSCRIPTS=$SRC
589 if test "$PKG" = "dist:" ; then
593 if test "$PKG" = "rpmid:" ; then
594 echo "${SRC#*:}" > $BUILD_ROOT/.init_b_cache/rpms/${SRC%%:*}.id
597 if test "$PKG" != "${PKG%:}"; then
598 echo "Warning: ignoring unsupported tag '$PKG'" >&2
601 if [ "${SRC#/}" = "$SRC" ]; then
604 zypp://* | http://* | https://* | ftp://* | ftps://*)
608 echo "unsupported url for '$PKG': $url" >&2
613 # downloadpkg modified $SRC, so it has a right name for use
614 ln -s "$SRC" "$BUILD_ROOT/.init_b_cache/rpms/$PKG.${SRC##*.}"
615 PACKAGES_TO_INSTALL="$PACKAGES_TO_INSTALL $PKG"
618 test -n "$PACKAGES_TO_CBPREINSTALL" && echo "cbpreinstall: $PACKAGES_TO_CBPREINSTALL"
619 test -n "$PACKAGES_TO_CBINSTALL" && echo "cbinstall : $PACKAGES_TO_CBINSTALL"
621 test -z "$RUNSCRIPTS_SEEN" && PACKAGES_TO_RUNSCRIPTS="$PACKAGES_TO_PREINSTALL"
623 echo "$GUESSED_DIST" > $BUILD_ROOT/.guessed_dist
624 test -n "$BUILD_DIST" || BUILD_DIST="$GUESSED_DIST"
626 test -L $BUILD_ROOT/.init_b_cache/rpms/rpm.rpm || PSUF=deb
630 # now test if there is already a build dir.
632 if test ! -f $BUILD_ROOT/var/lib/rpm/packages.rpm -a ! -f $BUILD_ROOT/var/lib/rpm/Packages ; then
633 mkdir -p $BUILD_ROOT/var/lib/rpm || cleanup_and_exit 1
634 mkdir -p $BUILD_ROOT/usr/src/packages/SOURCES || cleanup_and_exit 1
635 mkdir -p $BUILD_ROOT/etc || cleanup_and_exit 1
636 mkdir -p $BUILD_ROOT/proc || cleanup_and_exit 1
637 test -f $BUILD_ROOT/etc/HOSTNAME || hostname -f > $BUILD_ROOT/etc/HOSTNAME
638 if test $PSUF = deb ; then
639 mkdir -p $BUILD_ROOT/var/lib/dpkg
640 mkdir -p $BUILD_ROOT/var/log
641 mkdir -p $BUILD_ROOT/etc/default
642 :> $BUILD_ROOT/var/lib/dpkg/status
643 :> $BUILD_ROOT/var/lib/dpkg/available
644 :> $BUILD_ROOT/var/log/dpkg.log
645 :> $BUILD_ROOT/etc/ld.so.conf
646 :> $BUILD_ROOT/etc/default/rcS
648 for PKG in $PACKAGES_TO_RUNSCRIPTS ; do
649 : > $BUILD_ROOT/.init_b_cache/scripts/$PKG.run
651 for PKG in $PACKAGES_TO_PREINSTALL ; do
652 preinstall ${PKG##*/}
654 if test -n "$PREPARE_VM" ; then
655 for PKG in $PACKAGES_TO_VMINSTALL ; do
656 preinstall ${PKG##*/}
659 # add cbpreinstall if cross HOST != TARGET
660 for PKG in $PACKAGES_TO_CBPREINSTALL ; do
661 preinstall ${PKG##*/}
663 if [ -w /root ]; then
664 test -c $BUILD_ROOT/dev/null || create_devs
666 test -e $BUILD_ROOT/etc/fstab || touch $BUILD_ROOT/etc/fstab
667 test -e $BUILD_ROOT/etc/ld.so.conf || cp $BUILD_ROOT/etc/ld.so.conf.in $BUILD_ROOT/etc/ld.so.conf
668 if test -z "$PREPARE_VM" ; then
671 touch $BUILD_ROOT/.init_b_cache/preinstall_finished
675 if test -n "$PREPARE_VM" ; then
676 mkdir -p $BUILD_ROOT/.build
677 echo "copying packages..."
678 for PKG in $PACKAGES_TO_INSTALL ; do
679 rm -f $BUILD_ROOT/.init_b_cache/$PKG.$PSUF
680 cp $BUILD_ROOT/.init_b_cache/rpms/$PKG.$PSUF $BUILD_ROOT/.init_b_cache/$PKG.$PSUF || cleanup_and_exit 1
681 ln -s -f ../$PKG.$PSUF $BUILD_ROOT/.init_b_cache/rpms/$PKG.$PSUF
684 # alreadyinstalled check will not work, but we have to live with
686 echo -n 'reordering...'
687 PACKAGES_TO_INSTALL=`reorder $PACKAGES_TO_INSTALL`
690 echo "PACKAGES_TO_INSTALL='${PACKAGES_TO_INSTALL//"'"/$Q}'" > $BUILD_ROOT/.build/init_buildsystem.data
691 echo "PACKAGES_TO_RUNSCRIPTS='${PACKAGES_TO_RUNSCRIPTS//"'"/$Q}'" >> $BUILD_ROOT/.build/init_buildsystem.data
692 echo "PSUF='$PSUF'" >> $BUILD_ROOT/.build/init_buildsystem.data
693 rm -f $BUILD_IS_RUNNING
697 mkdir -p $BUILD_ROOT/proc
698 mkdir -p $BUILD_ROOT/dev/pts
699 mount -n -tproc none $BUILD_ROOT/proc 2>/dev/null || true
700 mount -n -tdevpts none $BUILD_ROOT/dev/pts 2>/dev/null || true
703 # create .build.binaries directory if requested
705 rm -rf $BUILD_ROOT/.build.binaries
706 if test -n "$CREATE_BUILD_BINARIES" ; then
707 echo "creating .build.binaries directory..."
708 mkdir -p "$BUILD_ROOT/.build.binaries"
709 for PKG in $PACKAGES_TO_INSTALL ; do
710 test -L "$BUILD_ROOT/.init_b_cache/rpms/$PKG.$PSUF" || continue
711 LPKG=`readlink -f "$BUILD_ROOT/.init_b_cache/rpms/$PKG.$PSUF"`
712 ln "$LPKG" "$BUILD_ROOT/.build.binaries/$PKG.$PSUF" 2>/dev/null
713 test -f "$BUILD_ROOT/.build.binaries/$PKG.$PSUF" && continue
714 cp "$LPKG" "$BUILD_ROOT/.build.binaries/$PKG.$PSUF"
720 # get list and ids of already installed rpms
722 mkdir -p $BUILD_ROOT/.init_b_cache/alreadyinstalled
723 if test -f $BUILD_ROOT/var/lib/rpm/packages.rpm -o -f $BUILD_ROOT/var/lib/rpm/Packages ; then
724 chroot $BUILD_ROOT rpm -qa --qf "%{NAME} $RPMIDFMT" | (
726 echo "$ii" > "$BUILD_ROOT/.init_b_cache/alreadyinstalled/$pp"
732 # reorder packages (already done in vm continuation)
734 if ! test -e $BUILD_ROOT/.build/init_buildsystem.data ; then
735 echo -n 'reordering...'
736 PACKAGES_TO_INSTALL_FIRST=`reorder $PACKAGES_TO_INSTALL_FIRST`
737 PACKAGES_TO_INSTALL=`reorder $PACKAGES_TO_INSTALL`
743 chroot $BUILD_ROOT rpm --nodeps -e $PKG 2>&1 | \
747 r*failed:\ No\ such\ file\ or\ directory) ;;
748 error:\ failed\ to\ stat\ *:\ No\ such\ file\ or\ directory) ;;
749 error:\ *scriptlet\ failed*)
751 echo "re-try deleting $PKG using --noscripts"
752 chroot $BUILD_ROOT rpm --nodeps --noscripts -e $PKG || true
760 # delete all packages we don't want
762 mkdir -p $BUILD_ROOT/.init_b_cache/todelete
763 for PKG in $BUILD_ROOT/.init_b_cache/alreadyinstalled/* ; do
765 test "$PKG" = "*" && continue
766 ln $BUILD_ROOT/.init_b_cache/alreadyinstalled/$PKG $BUILD_ROOT/.init_b_cache/todelete/$PKG
768 for PKG in $PACKAGES_TO_INSTALL_FIRST $PACKAGES_TO_INSTALL $PACKAGES_TO_CBINSTALL ; do
769 rm -f $BUILD_ROOT/.init_b_cache/todelete/$PKG
771 for PKG in $BUILD_ROOT/.init_b_cache/todelete/* ; do
773 test "$PKG" = "*" && continue
778 rm -rf $BUILD_ROOT/.init_b_cache/todelete
780 rm -rf $BUILD_ROOT/.init_b_cache/preinstalls
781 mkdir -p $BUILD_ROOT/.init_b_cache/preinstalls
782 for PKG in $PACKAGES_TO_PREINSTALL $PACKAGES_TO_CBPREINSTALL; do
783 touch "$BUILD_ROOT/.init_b_cache/preinstalls/$PKG"
786 rm -rf $BUILD_ROOT/installed-pkg
787 mkdir -p $BUILD_ROOT/installed-pkg
791 # on Fedora 10 rpmbuild is in a separate package so we need something else to
793 test -x $BUILD_ROOT/usr/bin/rpmsign && RPMCHECKOPTS="--nodigest --nosignature"
794 test -x /usr/bin/rpmsign && RPMCHECKOPTS_HOST="--nodigest --nosignature"
796 for PKG in $PACKAGES_TO_INSTALL_FIRST RUN_LDCONFIG $PACKAGES_TO_INSTALL $PACKAGES_TO_CBINSTALL; do
800 test -x $BUILD_ROOT/sbin/ldconfig && chroot $BUILD_ROOT /sbin/ldconfig 2>&1
805 test -f $BUILD_ROOT/installed-pkg/$PKG && continue
807 if test $PSUF = deb ; then
808 # debian world, install deb files
809 test -L $BUILD_ROOT/.init_b_cache/rpms/$PKG.deb || continue
810 if ! test "$BUILD_ROOT/.init_b_cache/rpms/$PKG.deb" -ef "$BUILD_ROOT/.init_b_cache/$PKG.deb" ; then
811 rm -f $BUILD_ROOT/.init_b_cache/$PKG.deb
812 cp $BUILD_ROOT/.init_b_cache/rpms/$PKG.deb $BUILD_ROOT/.init_b_cache/$PKG.deb || cleanup_and_exit 1
814 PKGID=`readlink $BUILD_ROOT/.init_b_cache/rpms/$PKG.deb`
816 PKGID="${PKGID%.deb}"
817 echo "installing ${PKGID%_*}"
818 ( chroot $BUILD_ROOT dpkg --install --force all .init_b_cache/$PKG.deb 2>&1 || touch $BUILD_ROOT/exit ) | \
819 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'
821 echo "$PKGID debian" > $BUILD_ROOT/installed-pkg/$PKG
822 # ugly workaround for upstart system. some packages (procps) try
823 # to start a service in their configure phase. As we don't have
824 # a running upstart, we just link the start binary to /bin/true
825 if test -e "$BUILD_ROOT/sbin/start"; then
826 if test "$BUILD_ROOT/sbin/start" -ef "$BUILD_ROOT/sbin/initctl" ; then
827 echo "linking /sbin/start to /bin/true"
828 mv "$BUILD_ROOT/sbin/start" "$BUILD_ROOT/sbin/start.disabled"
829 ln -s "/bin/true" "$BUILD_ROOT/sbin/start"
835 test -L $BUILD_ROOT/.init_b_cache/rpms/$PKG.rpm || continue
837 if test -f $BUILD_ROOT/.init_b_cache/rpms/$PKG.id -a -f $BUILD_ROOT/.init_b_cache/alreadyinstalled/$PKG ; then
838 read PKGID < $BUILD_ROOT/.init_b_cache/rpms/$PKG.id
839 read OLDPKGID < $BUILD_ROOT/.init_b_cache/alreadyinstalled/$PKG
840 if test "$PKGID" = "$OLDPKGID" ; then
841 #echo "keeping ${PKGID%% *}"
842 echo "$PKGID" > $BUILD_ROOT/installed-pkg/$PKG
847 PKGID=`rpm -qp --qf "$RPMIDFMT" $RPMCHECKOPTS_HOST $BUILD_ROOT/.init_b_cache/rpms/$PKG.rpm`
849 if test -f $BUILD_ROOT/.init_b_cache/alreadyinstalled/$PKG ; then
850 read OLDPKGID < $BUILD_ROOT/.init_b_cache/alreadyinstalled/$PKG
851 if test "$PKGID" != "$OLDPKGID" ; then
852 echo deleting unwanted ${OLDPKGID%% *}
854 elif test "$VERIFY_BUILD_SYSTEM" = true ; then
855 chroot $BUILD_ROOT rpm --verify $PKG 2>&1 | tee $TMPFILE
856 if grep ^missing $TMPFILE > /dev/null ; then
857 echo deleting incomplete ${PKGID%% *}
860 #echo "keeping ${PKGID%% *}"
861 echo "$PKGID" > $BUILD_ROOT/installed-pkg/$PKG
865 #echo "keeping ${PKGID%% *}"
866 echo "$PKGID" > $BUILD_ROOT/installed-pkg/$PKG
869 if test -e "$BUILD_ROOT/.init_b_cache/preinstalls/$PKG" ; then
871 # call for rpm-4.x and not rpm-devel
872 test -z "${PKG##rpm-[0-9]*}" && chroot $BUILD_ROOT rpm --rebuilddb
873 # also exec for exchanged rpm ! naming is rpm-x86-<target>-<ver>
874 test -z "${PKG##rpm-x86-*[0-9]*}" && chroot $BUILD_ROOT rpm --rebuilddb
877 export ADDITIONAL_PARAMS=
878 if test "$USE_FORCE" = true ; then
879 export ADDITIONAL_PARAMS="$ADDITIONAL_PARAMS --force"
881 # work around for cross-build installs, we must not overwrite the running rpm
882 if test "$PKG" = rpm ; then
883 for i in $BUILD_ROOT/.init_b_cache/preinstalls/rpm-x86-* ; do
884 test -e "$i" && ADDITIONAL_PARAMS="$ADDITIONAL_PARAMS --justdb"
887 echo "installing ${PKGID%% *}"
888 if ! test "$BUILD_ROOT/.init_b_cache/rpms/$PKG.rpm" -ef "$BUILD_ROOT/.init_b_cache/$PKG.rpm" ; then
889 rm -f $BUILD_ROOT/.init_b_cache/$PKG.rpm
890 cp $BUILD_ROOT/.init_b_cache/rpms/$PKG.rpm $BUILD_ROOT/.init_b_cache/$PKG.rpm || cleanup_and_exit 1
892 ( chroot $BUILD_ROOT rpm --ignorearch --nodeps -U --oldpackage --ignoresize $RPMCHECKOPTS \
893 $ADDITIONAL_PARAMS .init_b_cache/$PKG.rpm 2>&1 || \
894 touch $BUILD_ROOT/exit ) | \
895 grep -v "^warning:.*saved as.*rpmorig$"
896 # delete link so package is only installed once
897 rm -f $BUILD_ROOT/.init_b_cache/$PKG.rpm
899 echo "$PKGID" > $BUILD_ROOT/installed-pkg/$PKG
903 if test $PSUF = deb ; then
904 echo "configure all installed packages..."
905 # configure all packages after complete installation, not for each package like rpm does
906 # We need to run this twice, because of cyclic dependencies as it does not succeed on most
907 # debian based distros in the first attempt.
908 if ! chroot $BUILD_ROOT dpkg --configure --pending 2>&1; then
909 echo "first configure attempt failed, trying again..."
910 chroot $BUILD_ROOT dpkg --configure --pending 2>&1 || touch $BUILD_ROOT/exit
914 # devices can vanish if devs got uninstalled
915 test -c $BUILD_ROOT/dev/null || create_devs
917 cd $BUILD_ROOT || cleanup_and_exit 1
922 rm -f $BUILD_ROOT/etc/mtab
923 cp /proc/mounts $BUILD_ROOT/etc/mtab
924 chmod 644 $BUILD_ROOT/etc/mtab
927 # to be sure, path is set correctly, we have to source /etc/profile before
931 #rm -f $BUILD_ROOT/bin/rpm.sh
932 #cp $BUILD_LIBDIR/lib/rpm.sh $BUILD_ROOT/bin/rpm.sh
933 #chmod 755 $BUILD_ROOT/bin/rpm.sh
934 #test -f $BUILD_ROOT/bin/rpm -a ! -L $BUILD_ROOT/bin/rpm && \
935 # mv $BUILD_ROOT/bin/rpm $BUILD_ROOT/bin/rpm.bin
936 #rm -f $BUILD_ROOT/bin/rpm
937 #ln -s rpm.sh $BUILD_ROOT/bin/rpm
940 # some packages use uname -r to decide which kernel is used to build for.
941 # this does not work in autobuild always. Here is a wrapper script, that
942 # gets Version from kernel sources.
945 #rm -f $BUILD_ROOT/bin/uname.sh
946 #cp -v $BUILD_LIBDIR/lib/uname.sh $BUILD_ROOT/bin/uname.sh
947 #chmod 755 $BUILD_ROOT/bin/uname.sh
948 #test -f $BUILD_ROOT/bin/uname -a ! -L $BUILD_ROOT/bin/uname && \
949 # mv $BUILD_ROOT/bin/uname $BUILD_ROOT/bin/uname.bin
950 #rm -f $BUILD_ROOT/bin/uname
951 #ln -s uname.sh $BUILD_ROOT/bin/uname
954 # some distributions have a /etc/rpmrc or /etc/rpm/macros and some not.
955 # make sure, that it is setup correctly.
958 #rm -f $BUILD_ROOT/etc/rpmrc
959 #if test -e $BUILD_LIBDIR/lib/rpmrc.$BUILD_BASENAME ; then
960 # cp -v $BUILD_LIBDIR/lib/rpmrc.$BUILD_BASENAME $BUILD_ROOT/etc/rpmrc
961 #elif test -e $BUILD_LIBDIR/lib/rpmrc ; then
962 # cp -v $BUILD_LIBDIR/lib/rpmrc $BUILD_ROOT/etc/rpmrc
966 #rm -f $BUILD_ROOT/etc/rpm/macros $BUILD_ROOT/etc/rpm/suse_macros
967 #mkdir -p $BUILD_ROOT/etc/rpm
968 #if test -e $BUILD_LIBDIR/lib/macros.$BUILD_BASENAME ; then
969 # cp -v $BUILD_LIBDIR/lib/macros.$BUILD_BASENAME $BUILD_ROOT/etc/rpm/macros
970 # cp -v $BUILD_LIBDIR/lib/macros.$BUILD_BASENAME $BUILD_ROOT/etc/rpm/suse_macros
971 #elif test -e $BUILD_LIBDIR/lib/macros ; then
972 # cp -v $BUILD_LIBDIR/lib/macros $BUILD_ROOT/etc/rpm/macros
973 # cp -v $BUILD_LIBDIR/lib/macros $BUILD_ROOT/etc/rpm/suse_macros
977 # make sure, that our nis is not present in the chroot system
979 test -e $BUILD_ROOT/etc/nsswitch.conf && {
980 echo removing nis flags from $BUILD_ROOT/etc/nsswitch.conf...
981 cat $BUILD_ROOT/etc/nsswitch.conf | sed -e"s:nis::g" > \
982 $BUILD_ROOT/etc/nsswitch.conf.tmp
983 mv $BUILD_ROOT/etc/nsswitch.conf.tmp $BUILD_ROOT/etc/nsswitch.conf
987 # creating some default directories
988 for DIR in /usr/share/doc/packages \
989 /usr/X11R6/include/X11/pixmaps \
990 /usr/X11R6/include/X11/bitmaps ; do
991 mkdir -p $BUILD_ROOT/$DIR
994 for FILE in /var/run/utmp /var/log/wtmp /etc/fstab ; do
995 touch $BUILD_ROOT/$FILE
998 echo now finalizing build dir...
999 CHROOT_RETURN="`chroot $BUILD_ROOT /sbin/ldconfig 2>&1`"
1000 case "$CHROOT_RETURN" in
1002 chroot $BUILD_ROOT /sbin/ldconfig
1004 echo chroot $BUILD_ROOT /sbin/ldconfig
1006 echo "$CHROOT_RETURN"
1008 echo "Problem with ldconfig. It's better to reinit the build system..."
1013 test -x $BUILD_ROOT/usr/sbin/Check && chroot $BUILD_ROOT /usr/sbin/Check
1015 mkdir -p $BUILD_ROOT/var/adm/packages
1016 touch $BUILD_ROOT/var/adm/packages
1017 if test -x $BUILD_ROOT/sbin/SuSEconfig ; then
1018 if grep norestarts $BUILD_ROOT/sbin/SuSEconfig > /dev/null ; then
1019 chroot $BUILD_ROOT /sbin/SuSEconfig --norestarts --force
1021 chroot $BUILD_ROOT /sbin/SuSEconfig --force
1025 if test -x $BUILD_ROOT/usr/X11R6/bin/switch2mesasoft ; then
1026 chroot $BUILD_ROOT /usr/X11R6/bin/switch2mesasoft
1029 for PROG in /usr/bin/TeX/texhash /usr/bin/texhash ; do
1030 test -x $BUILD_ROOT/$PROG && \
1031 chroot $BUILD_ROOT bash -c ". /etc/profile ; $PROG"
1034 if test -e $BUILD_ROOT/usr/share/zoneinfo/UTC ; then
1035 chroot $BUILD_ROOT zic -l UTC
1038 test -e $BUILD_ROOT/.build/init_buildsystem.data || HOST=`hostname`
1039 test -e $BUILD_ROOT/etc/hosts || echo "127.0.0.1 localhost" > $BUILD_ROOT/etc/hosts
1040 if ! grep -F "127.0.0.1 $HOST" $BUILD_ROOT/etc/hosts > /dev/null ; then
1041 # this makes a reverse lookup on 127.0.0.1 return the host name,
1042 # which is bad, but 127.0.0.2 does not work on all unix systems
1043 echo "127.0.0.1 $HOST" > $BUILD_ROOT/etc/hosts.new
1044 test -f $BUILD_ROOT/etc/hosts && cat $BUILD_ROOT/etc/hosts >> $BUILD_ROOT/etc/hosts.new
1045 mv $BUILD_ROOT/etc/hosts.new $BUILD_ROOT/etc/hosts
1048 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
1049 echo "initializing rpm db..."
1050 chroot $BUILD_ROOT rpm --initdb || cleanup_and_exit 1
1051 # create provides index
1052 chroot $BUILD_ROOT rpm -q --whatprovides rpm >/dev/null 2>&1
1055 # create modules.dep in kvm/xen
1056 # This can not work, until we use the native repository kernel
1057 #if [ $BUILD_ROOT = "/" -a -x /sbin/depmod ]; then
1061 rm -f $BUILD_ROOT/.rpmmacros $BUILD_ROOT/root/.rpmmacros
1062 rm -rf $BUILD_ROOT/.init_b_cache
1063 rm -f $BUILD_IS_RUNNING