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 # should RPMs be installed with --force ?
28 BUILD_IS_RUNNING=$BUILD_ROOT/not-ready
29 TMPFILE=$BUILD_ROOT/tmpfile
30 #buildhost removed so that id can be generated from repo files
31 #RPMIDFMT="%{NAME}-%{VERSION}-%{RELEASE} %{BUILDHOST}-%{BUILDTIME}\n"
32 RPMIDFMT="%{NAME}-%{VERSION}-%{RELEASE} %{BUILDTIME}\n"
39 CREATE_BUILD_BINARIES=
41 while test -n "$1" ; do
47 --create-build-binaries)
49 CREATE_BUILD_BINARIES=true
53 USEUSEDFORBUILD=--useusedforbuild
64 --define|--with|--without)
65 definesnstuff[${#definesnstuff[@]}]="$1";
66 definesnstuff[${#definesnstuff[@]}]="$2";
70 repos[${#repos[@]}]="$2";
88 function cleanup_and_exit {
90 [ "$BUILD_ROOT" != / ] || chown $browner $BUILD_ROOT
91 # umount so init_buildsystem can be used standalone
92 # XXX: use stat -f /dev/pts/ -c %T to check whether it's mounted and not suppress errors then?
93 umount -n $BUILD_ROOT/proc 2> /dev/null || true
94 umount -n $BUILD_ROOT/dev/pts 2> /dev/null || true
95 umount -n $BUILD_ROOT/mnt 2> /dev/null || true
99 function clean_build_root () {
100 test -n "$BUILD_ROOT" && {
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
104 rm -rf -- $BUILD_ROOT/*
105 rm -rf -- $BUILD_ROOT/.build
106 rm -rf -- $BUILD_ROOT/.init_b_cache
107 mkdir -p $BUILD_ROOT/proc
108 mkdir -p $BUILD_ROOT/dev/pts
109 if [ "$UID" = '0' ]; then
110 mount -n -tproc none $BUILD_ROOT/proc
111 mount -n -tdevpts none $BUILD_ROOT/dev/pts
116 function preinstall {
117 if test -n "$1" ; then
118 echo "preinstalling $1..."
119 cd $BUILD_ROOT || cleanup_and_exit 1
120 CPIO="cpio --extract --unconditional --preserve-modification-time --make-directories --no-absolute-filenames --quiet"
121 if test -e "$BUILD_ROOT/.init_b_cache/rpms/$1.rpm" ; then
122 PAYLOADDECOMPRESS=cat
123 case `rpm -qp --nodigest --nosignature --qf "%{PAYLOADCOMPRESSOR}\n" "$BUILD_ROOT/.init_b_cache/rpms/$1.rpm"` in
124 lzma) rpm --showrc | grep PayloadIsLzma > /dev/null || PAYLOADDECOMPRESS="lzma -d" ;;
126 if test "$PAYLOADDECOMPRESS" = "lzma -d" ; then
127 if ! lzma </dev/null >/dev/null 2>&1 ; then
128 test -f "$BUILD_DIR/lzmadec.sh" && PAYLOADDECOMPRESS="bash $BUILD_DIR/lzmadec.sh"
131 if test "$PAYLOADDECOMPRESS" = cat ; then
132 rpm2cpio "$BUILD_ROOT/.init_b_cache/rpms/$1.rpm" | $CPIO
134 rpm2cpio "$BUILD_ROOT/.init_b_cache/rpms/$1.rpm" | $PAYLOADDECOMPRESS | $CPIO
136 if test -e .init_b_cache/scripts/$1.run ; then
137 rpm -qp --nodigest --nosignature --qf "%{PREIN}" "$BUILD_ROOT/.init_b_cache/rpms/$1.rpm" > .init_b_cache/scripts/$1.pre
138 rpm -qp --nodigest --nosignature --qf "%{POSTIN}" "$BUILD_ROOT/.init_b_cache/rpms/$1.rpm" > .init_b_cache/scripts/$1.post
139 echo -n '(none)' > .init_b_cache/scripts/.none
140 cmp -s .init_b_cache/scripts/$1.pre .init_b_cache/scripts/.none && rm -f .init_b_cache/scripts/$1.pre
141 cmp -s .init_b_cache/scripts/$1.post .init_b_cache/scripts/.none && rm -f .init_b_cache/scripts/$1.post
142 rm -f .init_b_cache/scripts/.none
144 elif test -e "$BUILD_ROOT/.init_b_cache/rpms/$1.deb" ; then
145 ar x "$BUILD_ROOT/.init_b_cache/rpms/$1.deb" control.tar.gz data.tar.gz
146 mkdir -p .init_b_cache/scripts/control
147 tar -C .init_b_cache/scripts/control -xzf control.tar.gz
149 if test -e .init_b_cache/scripts/$1.run ; then
150 test -e .init_b_cache/scripts/control/preinst && mv .init_b_cache/scripts/control/preinst .init_b_cache/scripts/$1.pre
151 test -e .init_b_cache/scripts/control/postinst && mv .init_b_cache/scripts/control/postinst .init_b_cache/scripts/$1.post
153 rm -rf .init_b_cache/scripts/control control.tar.gz data.tar.gz
155 echo "warning: package $1 does not exist"
158 if test -n "$2" ; then
159 chroot $BUILD_ROOT /sbin/ldconfig 2>/dev/null
160 for PKG in $PACKAGES_TO_RUNSCRIPTS ; do
161 if test -e "$BUILD_ROOT/.init_b_cache/scripts/$PKG.pre" ; then
162 echo "running $PKG preinstall script"
163 if test -e "$BUILD_ROOT/.init_b_cache/rpms/$PKG.rpm" ; then
164 chroot $BUILD_ROOT sh ".init_b_cache/scripts/$PKG.pre" 0
166 chroot $BUILD_ROOT ".init_b_cache/scripts/$PKG.pre" install < /dev/null
168 rm -f "$BUILD_ROOT/.init_b_cache/scripts/$PKG.pre"
170 if test -e "$BUILD_ROOT/.init_b_cache/scripts/$PKG.post" ; then
171 echo "running $PKG postinstall script"
172 if test -e "$BUILD_ROOT/.init_b_cache/rpms/$PKG.rpm" ; then
173 chroot $BUILD_ROOT sh ".init_b_cache/scripts/$PKG.post" 1
175 chroot $BUILD_ROOT ".init_b_cache/scripts/$PKG.post" configure '' < /dev/null
177 rm -f "$BUILD_ROOT/.init_b_cache/scripts/$PKG.post"
184 if test $PSUF = rpm ; then
185 echo initializing rpm db...
186 chroot $BUILD_ROOT rpm --initdb || cleanup_and_exit 1
188 # force dpkg into database to make epoch test work
189 if ! test "$BUILD_ROOT/.init_b_cache/rpms/dpkg.deb" -ef "$BUILD_ROOT/.init_b_cache/dpkg.deb" ; then
190 rm -f $BUILD_ROOT/.init_b_cache/dpkg.deb
191 cp $BUILD_ROOT/.init_b_cache/rpms/dpkg.deb $BUILD_ROOT/.init_b_cache/dpkg.deb || cleanup_and_exit 1
193 chroot $BUILD_ROOT dpkg -i --force all .init_b_cache/dpkg.deb >/dev/null 2>&1
198 test -z "$*" && return
199 rm -f $BUILD_ROOT/.init_b_cache/order.manifest
201 echo "$PKG" >> $BUILD_ROOT/.init_b_cache/order.manifest
203 $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
204 rm -f $BUILD_ROOT/.init_b_cache/order.manifest
207 function create_devs {
208 local com file mode arg
210 mkdir -m 755 -p $BUILD_ROOT/dev/pts
211 test -f $BUILD_ROOT/dev/shm && rm -f $BUILD_ROOT/dev/shm
212 mkdir -m 755 -p $BUILD_ROOT/dev/shm
213 while read com file mode arg ; do
214 rm -f $BUILD_ROOT/dev/$file
215 if test $com = ln ; then
216 ln -s $arg $BUILD_ROOT/dev/$file
219 $com -m $mode $BUILD_ROOT/dev/$file $arg
224 mknod random 666 c 1 8
225 mknod urandom 644 c 1 9
228 mknod loop0 640 b 7 0
229 mknod loop1 640 b 7 1
230 mknod loop2 640 b 7 2
231 mknod loop3 640 b 7 3
232 ln fd 777 /proc/self/fd
239 function validate_cache_file {
241 test "${repos[*]} ${BUILD_RPMS//:/ /}" != "$(cat $CACHE_FILE.id 2>/dev/null)" && rm -f $CACHE_FILE.id
242 test -f $CACHE_FILE || rm -f $CACHE_FILE.id
243 for SRC in "${repos[@]}" ${BUILD_RPMS//:/ /}; do
244 test -z "$SRC" && SRC=.
245 test "$SRC" -nt $CACHE_FILE && rm -f $CACHE_FILE.id
247 if ! test -f $CACHE_FILE.id ; then
248 test -z "$LIST_STATE" && echo initializing $CACHE_FILE ...
249 for SRC in "${repos[@]}" -- ${BUILD_RPMS//:/ /}; do
250 if test "$SRC" = '--' ; then
254 test -z "$SRC" && SRC=`pwd`
255 if [ ! -e "$SRC" ]; then
256 echo "*** $SRC does not exist" >&2
258 elif [ -z "$findonly" -a -e "$SRC"/suse/setup/descr/packages -o -e "$SRC"/suse/setup/descr/packages.gz ]; then
259 set -- $BUILD_DIR/createyastdeps "$SRC"
260 elif [ -z "$findonly" -a -e "$SRC"/repodata/repomd.xml ]; then
261 set -- $BUILD_DIR/createrepomddeps "$SRC"
263 set -- $BUILD_DIR/createrpmdeps "$SRC"
266 "$@" || cleanup_and_exit 1
267 done > $CACHE_FILE.new
269 mv $CACHE_FILE.new $CACHE_FILE
270 echo "${repos[*]} ${BUILD_RPMS//:/ /}" > $CACHE_FILE.id
281 if [ "$BUILD_ROOT" = / ]; then
282 read dummy dummy browner dummy < <(ls -ld /)
285 if [ -n "$CLEAN_BUILD" ]; then
290 # now test if there was an incomplete run
292 if test -e $BUILD_IS_RUNNING ; then
293 echo It seems that there was an incomplete setup of $BUILD_ROOT.
294 echo To be sure, we will build it again completely...
295 umount -n $BUILD_ROOT/proc 2> /dev/null
296 umount -n $BUILD_ROOT/dev/pts 2> /dev/null
297 umount -n $BUILD_ROOT/mnt 2> /dev/null
298 echo "Your build system is broken!! Shall I execute"
300 echo " rm -rf -- $BUILD_ROOT/*"
305 c|C) rm -f $BUILD_IS_RUNNING ;;
306 y|Y) clean_build_root ;;
307 *) cleanup_and_exit 1 ;;
312 # store that we start to build system
315 touch $BUILD_IS_RUNNING
317 if test -n "$PREPARE_XEN" ; then
318 rm -f $BUILD_ROOT/.build/init_buildsystem.data
320 if test -e $BUILD_ROOT/.build/init_buildsystem.data ; then
322 . $BUILD_ROOT/.build/init_buildsystem.data
323 if ! test -e $BUILD_ROOT/.init_b_cache/preinstall_finished ; then
327 touch $BUILD_ROOT/.init_b_cache/preinstall_finished
331 # Hack to detect cross-build (fixed code) and copy qemus for cross-build emulation mode
333 if [ x"$BUILD_ARCH" == xarmv4l -o x"$BUILD_ARCH" == xarmv5el -o x"$BUILD_ARCH" == xarmv7el -o x"$BUILD_ARCH" == xsh4 ]; then
334 if [ x"`uname -i`" == xx86_64 -o x"`uname -i`" == xi386 ]; then
335 if [ -e /proc/sys/fs/binfmt_misc/arm -o -e /proc/sys/fs/binfmt_misc/armeb -o -e /proc/sys/fs/binfmt_misc/sh4 ]; then
336 echo -n "qemu-* already registered "
338 echo -n "qemu will be registered " && test -e /usr/sbin/qemu-binfmt-conf.sh && sh /usr/sbin/qemu-binfmt-conf.sh
340 if [ -e /usr/sbin/qemu-binfmt-conf.sh ]; then
341 (mkdir -p $BUILD_ROOT/usr/bin && set -x && cp /usr/bin/qemu-* $BUILD_ROOT/usr/bin)
342 # Hack to circumvent qemu mmap addr bug
343 test -e /proc/sys/vm/mmap_min_addr && echo 0 > /proc/sys/vm/mmap_min_addr
348 # now make sure that all the packages are installed.
350 rm -rf $BUILD_ROOT/.init_b_cache
351 mkdir -p $BUILD_ROOT/.init_b_cache/scripts
353 if test -z "$RPMLIST" ; then
355 # create rpmdeps file
357 CACHE_FILE=$BUILD_ROOT/.srcfiles.cache
361 # select and expand packages
363 RPMLIST=$BUILD_ROOT/.init_b_cache/rpmlist
364 test -z "$LIST_STATE" && echo "expanding package dependencies..."
365 if ! $BUILD_DIR/expanddeps $USEUSEDFORBUILD "${definesnstuff[@]}" --dist "$BUILD_DIST" --depfile "$CACHE_FILE" --archpath "$BUILD_ARCH" --configdir $BUILD_DIR/configs "${PKGS[@]}" > $RPMLIST ; then
366 rm -f $BUILD_IS_RUNNING
371 if test -n "$LIST_STATE" ; then
372 rm -f $BUILD_IS_RUNNING
373 while read PKG SRC ; do
374 test "$PKG" = "preinstall:" && continue
375 test "$PKG" = "runscripts:" && continue
376 test "$PKG" = "vminstall:" && continue
377 test "$PKG" = "dist:" && continue
378 test "$PKG" = "rpmid:" && continue
380 done < $BUILD_ROOT/.init_b_cache/rpmlist
381 rm -rf $BUILD_ROOT/.init_b_cache
386 PACKAGES_TO_PREINSTALL=
387 PACKAGES_TO_RUNSCRIPTS=
388 PACKAGES_TO_VMINSTALL=
391 mkdir -p $BUILD_ROOT/.init_b_cache/rpms
392 while read PKG SRC ; do
393 if test "$PKG" = "preinstall:" ; then
394 PACKAGES_TO_PREINSTALL=$SRC
397 if test "$PKG" = "vminstall:" ; then
398 PACKAGES_TO_VMINSTALL=$SRC
401 if test "$PKG" = "runscripts:" ; then
403 PACKAGES_TO_RUNSCRIPTS=$SRC
406 if test "$PKG" = "dist:" ; then
410 if test "$PKG" = "rpmid:" ; then
411 echo "${SRC#*:}" > $BUILD_ROOT/.init_b_cache/rpms/${SRC%%:*}.id
414 ln -s "$SRC" "$BUILD_ROOT/.init_b_cache/rpms/$PKG.${SRC##*.}"
415 PACKAGES_TO_INSTALL="$PACKAGES_TO_INSTALL $PKG"
419 test -z "$RUNSCRIPTS_SEEN" && PACKAGES_TO_RUNSCRIPTS="$PACKAGES_TO_PREINSTALL"
421 echo "$GUESSED_DIST" > $BUILD_ROOT/.guessed_dist
423 test -L $BUILD_ROOT/.init_b_cache/rpms/rpm.rpm || PSUF=deb
427 # now test if there is already a build dir.
429 if test ! -f $BUILD_ROOT/var/lib/rpm/packages.rpm -a ! -f $BUILD_ROOT/var/lib/rpm/Packages ; then
430 mkdir -p $BUILD_ROOT/var/lib/rpm || cleanup_and_exit 1
431 mkdir -p $BUILD_ROOT/usr/src/packages/SOURCES || cleanup_and_exit 1
432 mkdir -p $BUILD_ROOT/etc || cleanup_and_exit 1
433 mkdir -p $BUILD_ROOT/proc || cleanup_and_exit 1
434 test -f $BUILD_ROOT/etc/HOSTNAME || hostname -f > $BUILD_ROOT/etc/HOSTNAME
435 if test $PSUF = deb ; then
436 mkdir -p $BUILD_ROOT/var/lib/dpkg
437 mkdir -p $BUILD_ROOT/var/log
438 mkdir -p $BUILD_ROOT/etc/default
439 :> $BUILD_ROOT/var/lib/dpkg/status
440 :> $BUILD_ROOT/var/lib/dpkg/available
441 :> $BUILD_ROOT/var/log/dpkg.log
442 :> $BUILD_ROOT/etc/ld.so.conf
443 :> $BUILD_ROOT/etc/default/rcS
445 for PKG in $PACKAGES_TO_RUNSCRIPTS ; do
446 : > $BUILD_ROOT/.init_b_cache/scripts/$PKG.run
448 for PKG in $PACKAGES_TO_PREINSTALL ; do
449 preinstall ${PKG##*/}
451 if test -n "$PREPARE_XEN" ; then
452 for PKG in $PACKAGES_TO_VMINSTALL ; do
453 preinstall ${PKG##*/}
456 if [ -w /root ]; then
457 test -c $BUILD_ROOT/dev/null || create_devs
459 test -e $BUILD_ROOT/etc/fstab || touch $BUILD_ROOT/etc/fstab
460 test -e $BUILD_ROOT/etc/ld.so.conf || cp $BUILD_ROOT/etc/ld.so.conf.in $BUILD_ROOT/etc/ld.so.conf
461 if test -z "$PREPARE_XEN" ; then
464 touch $BUILD_ROOT/.init_b_cache/preinstall_finished
468 if test -n "$PREPARE_XEN" ; then
469 mkdir -p $BUILD_ROOT/.build
470 echo "copying packages..."
471 for PKG in $PACKAGES_TO_INSTALL ; do
472 rm -f $BUILD_ROOT/.init_b_cache/$PKG.$PSUF
473 cp $BUILD_ROOT/.init_b_cache/rpms/$PKG.$PSUF $BUILD_ROOT/.init_b_cache/$PKG.$PSUF || cleanup_and_exit 1
474 ln -s -f ../$PKG.$PSUF $BUILD_ROOT/.init_b_cache/rpms/$PKG.$PSUF
476 # alreadyinstalled check will not work, but we have to live with
478 echo -n 'reordering...'
479 PACKAGES_TO_INSTALL=`reorder $PACKAGES_TO_INSTALL`
482 echo "PACKAGES_TO_INSTALL='${PACKAGES_TO_INSTALL//"'"/$Q}'" > $BUILD_ROOT/.build/init_buildsystem.data
483 echo "PACKAGES_TO_RUNSCRIPTS='${PACKAGES_TO_RUNSCRIPTS//"'"/$Q}'" >> $BUILD_ROOT/.build/init_buildsystem.data
484 echo "PSUF='$PSUF'" >> $BUILD_ROOT/.build/init_buildsystem.data
485 rm -f $BUILD_IS_RUNNING
489 mkdir -p $BUILD_ROOT/proc
490 mkdir -p $BUILD_ROOT/dev/pts
491 mount -n -tproc none $BUILD_ROOT/proc 2>/dev/null || true
492 mount -n -tdevpts none $BUILD_ROOT/dev/pts 2>/dev/null || true
495 # create .build.binaries directory if requested
497 rm -rf $BUILD_ROOT/.build.binaries
498 if test -n "$CREATE_BUILD_BINARIES" ; then
499 echo "creating .build.binaries directory..."
500 mkdir -p "$BUILD_ROOT/.build.binaries"
501 for PKG in $PACKAGES_TO_INSTALL ; do
502 test -L "$BUILD_ROOT/.init_b_cache/rpms/$PKG.$PSUF" || continue
503 LPKG=`readlink -f "$BUILD_ROOT/.init_b_cache/rpms/$PKG.$PSUF"`
504 ln "$LPKG" "$BUILD_ROOT/.build.binaries/$PKG.$PSUF" 2>/dev/null
505 test -f "$BUILD_ROOT/.build.binaries/$PKG.$PSUF" && continue
506 cp "$LPKG" "$BUILD_ROOT/.build.binaries/$PKG.$PSUF"
511 # get list and ids of already installed rpms
513 mkdir -p $BUILD_ROOT/.init_b_cache/alreadyinstalled
514 if test -f $BUILD_ROOT/var/lib/rpm/packages.rpm -o -f $BUILD_ROOT/var/lib/rpm/Packages ; then
515 chroot $BUILD_ROOT rpm -qa --qf "%{NAME} $RPMIDFMT" | (
517 echo "$ii" > "$BUILD_ROOT/.init_b_cache/alreadyinstalled/$pp"
523 # reorder packages (already done in XEN continuation)
525 if ! test -e $BUILD_ROOT/.build/init_buildsystem.data ; then
526 echo -n 'reordering...'
527 PACKAGES_TO_INSTALL_FIRST=`reorder $PACKAGES_TO_INSTALL_FIRST`
528 PACKAGES_TO_INSTALL=`reorder $PACKAGES_TO_INSTALL`
533 # delete all packages we don't want
535 mkdir -p $BUILD_ROOT/.init_b_cache/todelete
536 for PKG in $BUILD_ROOT/.init_b_cache/alreadyinstalled/* ; do
538 test "$PKG" = "*" && continue
539 ln $BUILD_ROOT/.init_b_cache/alreadyinstalled/$PKG $BUILD_ROOT/.init_b_cache/todelete/$PKG
541 for PKG in $PACKAGES_TO_INSTALL_FIRST $PACKAGES_TO_INSTALL ; do
542 rm -f $BUILD_ROOT/.init_b_cache/todelete/$PKG
544 for PKG in $BUILD_ROOT/.init_b_cache/todelete/* ; do
546 test "$PKG" = "*" && continue
547 echo deleting `sed -e 's/ .*//' < $BUILD_ROOT/.init_b_cache/todelete/$PKG`
548 chroot $BUILD_ROOT rpm --nodeps -e $PKG 2>&1 | \
549 grep -v -e "^r.*failed: No such file or directory" -e "^error: failed to stat .*: No such file or directory"
551 rm -rf $BUILD_ROOT/.init_b_cache/todelete
553 rm -rf $BUILD_ROOT/.init_b_cache/preinstalls
554 mkdir -p $BUILD_ROOT/.init_b_cache/preinstalls
555 for PKG in $PACKAGES_TO_PREINSTALL ; do
556 touch "$BUILD_ROOT/.init_b_cache/preinstalls/$PKG"
559 rm -rf $BUILD_ROOT/installed-pkg
560 mkdir -p $BUILD_ROOT/installed-pkg
564 # on Fedoar 10 rpmbuild is in a separate package so we need something else to
566 test -x $BUILD_ROOT/usr/bin/rpmsign && RPMCHECKOPTS="--nodigest --nosignature"
567 test -x /usr/bin/rpmsign && RPMCHECKOPTS_HOST="--nodigest --nosignature"
569 for PKG in $PACKAGES_TO_INSTALL_FIRST RUN_LDCONFIG $PACKAGES_TO_INSTALL ; do
572 test -x $BUILD_ROOT/sbin/ldconfig && chroot $BUILD_ROOT /sbin/ldconfig 2>&1
576 test -f $BUILD_ROOT/installed-pkg/$PKG && continue
578 if test $PSUF = deb ; then
579 # debian world, install deb files
580 test -L $BUILD_ROOT/.init_b_cache/rpms/$PKG.deb || continue
581 if ! test "$BUILD_ROOT/.init_b_cache/rpms/$PKG.deb" -ef "$BUILD_ROOT/.init_b_cache/$PKG.deb" ; then
582 rm -f $BUILD_ROOT/.init_b_cache/$PKG.deb
583 cp $BUILD_ROOT/.init_b_cache/rpms/$PKG.deb $BUILD_ROOT/.init_b_cache/$PKG.deb || cleanup_and_exit 1
585 PKGID=`readlink $BUILD_ROOT/.init_b_cache/rpms/$PKG.deb`
587 PKGID="${PKGID%.deb}"
588 echo "installing ${PKGID%_*}"
589 ( chroot $BUILD_ROOT dpkg -i --force all .init_b_cache/$PKG.deb 2>&1 || touch $BUILD_ROOT/exit ) | \
590 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'
591 test -e $BUILD_ROOT/exit && cleanup_and_exit 1
592 echo "$PKGID debian" > $BUILD_ROOT/installed-pkg/$PKG
596 test -L $BUILD_ROOT/.init_b_cache/rpms/$PKG.rpm || continue
598 if test -f $BUILD_ROOT/.init_b_cache/rpms/$PKG.id -a -f $BUILD_ROOT/.init_b_cache/alreadyinstalled/$PKG ; then
599 read PKGID < $BUILD_ROOT/.init_b_cache/rpms/$PKG.id
600 read OLDPKGID < $BUILD_ROOT/.init_b_cache/alreadyinstalled/$PKG
601 if test "$PKGID" = "$OLDPKGID" ; then
602 echo "keeping ${PKGID%% *}"
603 echo "$PKGID" > $BUILD_ROOT/installed-pkg/$PKG
608 PKGID=`rpm -qp --qf "$RPMIDFMT" $RPMCHECKOPTS_HOST $BUILD_ROOT/.init_b_cache/rpms/$PKG.rpm`
610 if test -f $BUILD_ROOT/.init_b_cache/alreadyinstalled/$PKG ; then
611 read OLDPKGID < $BUILD_ROOT/.init_b_cache/alreadyinstalled/$PKG
612 if test "$PKGID" != "$OLDPKGID" ; then
613 echo deleting unwanted ${OLDPKGID%% *}
614 chroot $BUILD_ROOT rpm --nodeps -e $PKG 2>&1 | \
615 grep -v -e "^r.*failed: No such file or directory" -e "^error: failed to stat .*: No such file or directory"
616 elif test "$VERIFY_BUILD_SYSTEM" = true ; then
617 chroot $BUILD_ROOT rpm --verify $PKG 2>&1 | tee $TMPFILE
618 if grep ^missing $TMPFILE > /dev/null ; then
619 echo deleting incomplete ${PKGID%% *}
620 chroot $BUILD_ROOT rpm --nodeps -e $PKG 2>&1 | \
621 grep -v -e "^r.*failed: No such file or directory" -e "^error: failed to stat .*: No such file or directory"
623 echo "keeping ${PKGID%% *}"
624 echo "$PKGID" > $BUILD_ROOT/installed-pkg/$PKG
628 echo "keeping ${PKGID%% *}"
629 echo "$PKGID" > $BUILD_ROOT/installed-pkg/$PKG
632 if test -e "$BUILD_ROOT/.init_b_cache/preinstalls/$PKG" ; then
634 test rpm = "$PKG" && chroot $BUILD_ROOT rpm --rebuilddb
637 export ADDITIONAL_PARAMS=
638 if test "$USE_FORCE" = true ; then
639 export ADDITIONAL_PARAMS="$ADDITIONAL_PARAMS --force"
641 echo "installing ${PKGID%% *}"
642 if ! test "$BUILD_ROOT/.init_b_cache/rpms/$PKG.rpm" -ef "$BUILD_ROOT/.init_b_cache/$PKG.rpm" ; then
643 rm -f $BUILD_ROOT/.init_b_cache/$PKG.rpm
644 cp $BUILD_ROOT/.init_b_cache/rpms/$PKG.rpm $BUILD_ROOT/.init_b_cache/$PKG.rpm || cleanup_and_exit 1
646 ( chroot $BUILD_ROOT rpm --ignorearch --nodeps -U --oldpackage --ignoresize $RPMCHECKOPTS \
647 $ADDITIONAL_PARAMS .init_b_cache/$PKG.rpm 2>&1 || \
648 touch $BUILD_ROOT/exit ) | \
649 grep -v "^warning:.*saved as.*rpmorig$"
650 # delete link so package is only installed once
651 rm -f $BUILD_ROOT/.init_b_cache/$PKG.rpm
652 test -e $BUILD_ROOT/exit && cleanup_and_exit 1
653 echo "$PKGID" > $BUILD_ROOT/installed-pkg/$PKG
656 # devices can vanish if devs got uninstalled
657 test -c $BUILD_ROOT/dev/null || create_devs
659 cd $BUILD_ROOT || cleanup_and_exit 1
664 rm -f $BUILD_ROOT/etc/mtab
665 cp /proc/mounts $BUILD_ROOT/etc/mtab
666 chmod 644 $BUILD_ROOT/etc/mtab
669 # to be sure, path is set correctly, we have to source /etc/profile before
673 #rm -f $BUILD_ROOT/bin/rpm.sh
674 #cp $BUILD_LIBDIR/lib/rpm.sh $BUILD_ROOT/bin/rpm.sh
675 #chmod 755 $BUILD_ROOT/bin/rpm.sh
676 #test -f $BUILD_ROOT/bin/rpm -a ! -L $BUILD_ROOT/bin/rpm && \
677 # mv $BUILD_ROOT/bin/rpm $BUILD_ROOT/bin/rpm.bin
678 #rm -f $BUILD_ROOT/bin/rpm
679 #ln -s rpm.sh $BUILD_ROOT/bin/rpm
682 # some packages use uname -r to decide which kernel is used to build for.
683 # this does not work in autobuild always. Here is a wrapper script, that
684 # gets Version from kernel sources.
687 #rm -f $BUILD_ROOT/bin/uname.sh
688 #cp -v $BUILD_LIBDIR/lib/uname.sh $BUILD_ROOT/bin/uname.sh
689 #chmod 755 $BUILD_ROOT/bin/uname.sh
690 #test -f $BUILD_ROOT/bin/uname -a ! -L $BUILD_ROOT/bin/uname && \
691 # mv $BUILD_ROOT/bin/uname $BUILD_ROOT/bin/uname.bin
692 #rm -f $BUILD_ROOT/bin/uname
693 #ln -s uname.sh $BUILD_ROOT/bin/uname
696 # some distributions have a /etc/rpmrc or /etc/rpm/macros and some not.
697 # make sure, that it is setup correctly.
700 #rm -f $BUILD_ROOT/etc/rpmrc
701 #if test -e $BUILD_LIBDIR/lib/rpmrc.$BUILD_BASENAME ; then
702 # cp -v $BUILD_LIBDIR/lib/rpmrc.$BUILD_BASENAME $BUILD_ROOT/etc/rpmrc
703 #elif test -e $BUILD_LIBDIR/lib/rpmrc ; then
704 # cp -v $BUILD_LIBDIR/lib/rpmrc $BUILD_ROOT/etc/rpmrc
708 #rm -f $BUILD_ROOT/etc/rpm/macros $BUILD_ROOT/etc/rpm/suse_macros
709 #mkdir -p $BUILD_ROOT/etc/rpm
710 #if test -e $BUILD_LIBDIR/lib/macros.$BUILD_BASENAME ; then
711 # cp -v $BUILD_LIBDIR/lib/macros.$BUILD_BASENAME $BUILD_ROOT/etc/rpm/macros
712 # cp -v $BUILD_LIBDIR/lib/macros.$BUILD_BASENAME $BUILD_ROOT/etc/rpm/suse_macros
713 #elif test -e $BUILD_LIBDIR/lib/macros ; then
714 # cp -v $BUILD_LIBDIR/lib/macros $BUILD_ROOT/etc/rpm/macros
715 # cp -v $BUILD_LIBDIR/lib/macros $BUILD_ROOT/etc/rpm/suse_macros
719 # make sure, that our nis is not present in the chroot system
721 test -e $BUILD_ROOT/etc/nsswitch.conf && {
722 echo removing nis flags from $BUILD_ROOT/etc/nsswitch.conf...
723 cat $BUILD_ROOT/etc/nsswitch.conf | sed -e"s:nis::g" > \
724 $BUILD_ROOT/etc/nsswitch.conf.tmp
725 mv $BUILD_ROOT/etc/nsswitch.conf.tmp $BUILD_ROOT/etc/nsswitch.conf
729 # creating some default directories
730 for DIR in /usr/share/doc/packages \
731 /usr/X11R6/include/X11/pixmaps \
732 /usr/X11R6/include/X11/bitmaps ; do
733 mkdir -p $BUILD_ROOT/$DIR
736 for FILE in /var/run/utmp /var/log/wtmp /etc/fstab ; do
737 touch $BUILD_ROOT/$FILE
740 echo now finalizing build dir...
741 CHROOT_RETURN="`chroot $BUILD_ROOT /sbin/ldconfig 2>&1`"
742 case "$CHROOT_RETURN" in
744 chroot $BUILD_ROOT /sbin/ldconfig
746 echo chroot $BUILD_ROOT /sbin/ldconfig
748 echo "$CHROOT_RETURN"
750 echo "Problem with ldconfig. It's better to reinit the build system..."
755 test -x $BUILD_ROOT/usr/sbin/Check && chroot $BUILD_ROOT /usr/sbin/Check
757 mkdir -p $BUILD_ROOT/var/adm/packages
758 touch $BUILD_ROOT/var/adm/packages
759 if test -x $BUILD_ROOT/sbin/SuSEconfig ; then
760 if grep norestarts $BUILD_ROOT/sbin/SuSEconfig > /dev/null ; then
761 chroot $BUILD_ROOT /sbin/SuSEconfig --norestarts --force
763 chroot $BUILD_ROOT /sbin/SuSEconfig --force
767 if test -x $BUILD_ROOT/usr/X11R6/bin/switch2mesasoft ; then
768 chroot $BUILD_ROOT /usr/X11R6/bin/switch2mesasoft
771 for PROG in /usr/bin/TeX/texhash /usr/bin/texhash ; do
772 test -x $BUILD_ROOT/$PROG && \
773 chroot $BUILD_ROOT bash -c ". /etc/profile ; $PROG"
776 if test -e $BUILD_ROOT/usr/share/zoneinfo/UTC ; then
777 chroot $BUILD_ROOT zic -l UTC
780 test -e $BUILD_ROOT/.build/init_buildsystem.data || HOST=`hostname`
781 test -e $BUILD_ROOT/etc/hosts || echo "127.0.0.1 localhost" > $BUILD_ROOT/etc/hosts
782 if ! grep -F "127.0.0.1 $HOST" $BUILD_ROOT/etc/hosts > /dev/null ; then
783 # this makes a reverse lookup on 127.0.0.1 return the host name,
784 # which is bad, but 127.0.0.2 does not work on all unix systems
785 echo "127.0.0.1 $HOST" > $BUILD_ROOT/etc/hosts.new
786 test -f $BUILD_ROOT/etc/hosts && cat $BUILD_ROOT/etc/hosts >> $BUILD_ROOT/etc/hosts.new
787 mv $BUILD_ROOT/etc/hosts.new $BUILD_ROOT/etc/hosts
790 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
791 echo "initializing rpm db..."
792 chroot $BUILD_ROOT rpm --initdb || cleanup_and_exit 1
793 # create provides index
794 chroot $BUILD_ROOT rpm -q --whatprovides rpm >/dev/null 2>&1
797 rm -rf $BUILD_ROOT/.init_b_cache
799 rm -f $BUILD_IS_RUNNING
803 if df $BUILD_ROOT 2>/dev/null | grep -q "100%"; then
805 echo "build does not work on a completely full filesystem"