e09f8298fd665d0280a6f0d199b7a755216b9efa
[platform/upstream/build.git] / build
1 #!/bin/bash
2 # Script to build a package.  It uses init_buildsystem to setup a chroot
3 # building tree.  This script needs a directory as parameter.  This directory
4 # has to include sources and a spec file.
5 #
6 # BUILD_ROOT        here the packages will be built
7 #
8 # (c) 1997-2008 SuSE GmbH Nuernberg, Germany
9
10 test -z "$BUILD_DIR" && BUILD_DIR=/usr/lib/build
11 test -z "$BUILD_ROOT" && BUILD_ROOT=/var/tmp/build-root
12
13 export BUILD_ARCH BUILD_HOST_ARCH BUILD_ROOT BUILD_RPMS BUILD_DIR BUILD_DEBUG
14 export BUILD_DIST
15
16 ccache=0
17 icecream=0
18 shell=
19 definesnstuff=()
20 repos=()
21 old_packages=()
22
23 # defaults for vm_img_mkfs
24 vm_img_mkfs_ext4='mkfs.ext4 -m 0 -q -F'
25 vm_img_tunefs_ext4='tune2fs -c 0 -O ^has_journal'
26 vm_img_mkfs_ext3='mkfs.ext3 -m 0 -q -F'
27 vm_img_tunefs_ext3='tune2fs -c 0 -o journal_data_writeback'
28 vm_img_mkfs_ext2='mkfs.ext2 -m 0 -q -F'
29 vm_img_tunefs_ext2='tune2fs -c 0'
30 vm_img_mkfs_reiserfs='mkreiserfs -q -f'
31 vm_img_mkfs_btrfs='mkfs.btrfs'
32
33 vm_kernel=/boot/vmlinuz
34 vm_initrd=/boot/initrd
35 qemu_bin=/usr/bin/qemu
36 uml_kernel=/boot/vmlinux-um
37 uml_initrd=/boot/initrd-um
38
39 kvm_bin=/usr/bin/qemu-kvm
40 # whether we have virtio support
41 kvm_virtio=
42
43 # guest visible console device name
44 console=ttyS0
45
46 # need to restore build root owner for non-root builds
47 browner=0
48
49 # Default uid:gid for the build user
50 ABUILD_UID=399
51 ABUILD_GID=399
52
53 DO_INIT=true
54 DO_LINT=
55 DO_CHECKS=true
56 CLEAN_BUILD=
57 SPECFILES=()
58 SRCDIR=
59 BUILD_JOBS=
60 ABUILD_TARGET=
61 CREATE_BASELIBS=
62 USEUSEDFORBUILD=
63 LIST_STATE=
64 VM_IMAGE=
65 VM_SWAP=
66 VM_KERNEL=
67 VM_INITRD=
68 VMDISK_ROOTSIZE=4096
69 VMDISK_SWAPSIZE=1024
70 VMDISK_FILESYSTEM=ext3
71 # settings are for speed and not data safety, we format anyway on next run
72 VMDISK_MOUNT_OPTIONS='-o data=writeback,nobarrier,commit=150,noatime'
73 MEMSIZE=
74 RUNNING_IN_VM=
75 RPMLIST=
76 RELEASE=
77 REASON=
78 NOROOTFORBUILD=
79 LOGFILE=
80 KILL=
81 CHANGELOG=
82 BUILD_DEBUG=
83 PERSONALITY_SYSCALL=
84 INCARNATION=
85 DISTURL=
86 LINKSOURCES=
87 OVERLAY=
88 RSYNCSRC=
89 RSYNCDEST=
90 RSYNCDONE=
91 SIGNDUMMY=
92 HOST_ARCH=
93
94 # list of archs which need emulator initialization
95 : ${EMULATOR_ARCHS:="armv4l armv5l armv6l armv7l armv5el armv6el armv7el armv7hl armv8el mips mipsel mips64 mips64el ppc ppc64 sh4 sparc sparc64 s390 s390x"}
96 export EMULATOR_ARCHS
97
98 # list of devices registered by binfmt handlers in /proc/sys/fs/binfmt_misc
99 : ${EMULATOR_DEVS:="arm armeb mips mipsel mips64 mips64el ppc sh4 sh4eb sparc s390x"}
100 export EMULATOR_DEVS
101
102 # This is for insserv
103 export YAST_IS_RUNNING=instsys
104
105 unset LANGUAGE
106 unset LANG
107 export LC_ALL=POSIX
108 umask 022
109
110 echo_help () {
111     cat << EOT
112
113 Some comments for build
114 -----------------------
115
116 With build you can create rpm packages.  They will be built in a chroot
117 system.  This chroot system will be setup automatically.  Normally you can
118 simply call build with a spec file as parameter - nothing else has to be
119 set.
120
121 If you want to set the directory were the chroot system will be setup
122 (at the moment it uses $BUILD_ROOT),
123 simply set the the environment variable BUILD_ROOT.
124
125 Example:
126
127   export BUILD_ROOT=/var/tmp/mybuildroot
128
129
130 Normally build builds the complete package including src.rpm (rpmbuild -ba).
131 If you want let build only make the binary package, simply set
132
133    export BUILD_RPM_BUILD_STAGE=-bb
134
135 (or -bc, -bp, -bi, ...  see "Maximum RPM" for more details [*]).
136
137 When the build command succeeds, the rpm files can be found under
138 $BUILD_ROOT/usr/src/packages/RPMS/
139
140
141 Known Parameters:
142
143   --help      You already got it :)
144
145   --clean     Delete old build root before initializing it
146
147   --no-init   Skip initialization of build root and start with build
148               immediately.
149
150   --no-checks Do not run post-build checks
151
152   --repository PATH
153               Use package repository at PATH. Supported formats are
154               rpm-md and yast2.
155               Alternatively zypp://NAME specifies the zypp
156               repository NAME. The repo must be refreshed with zypp
157               so package meta data is available locally. With emtpy
158               NAME all enabled repositories are used.
159               a url can specify a remote repo.
160
161   --rpms path1:path2:...
162               Specify path where to find the RPMs for the build system
163
164   --arch arch1:arch2:...
165               Specify what architectures to select from the RPMs
166
167   --verify    Run verify when initializing the build root
168
169   --extra-packs pack
170               Also install package 'pack'
171
172   --root rootdir
173               Use 'rootdir' to setup chroot environment
174
175   --cachedir cachedir
176               Use 'cachedir' to cache remote repo's packages, the
177               default cache dir is /var/cache/build, every repo
178               given by --repository corresponds to a subdir named
179               as md5sum of its repo url, forx eaxmple:
180                  /var/cache/build/3e8ea9b47808629414a0cebc33ea285e
181
182   --oldpackages oldpackagesdir
183               Define a directory with a former build
184
185   --baselibs  Create -32bit/-64bit/-x86 rpms for other architectures
186
187   --list-state
188               List rpms that would be used to create a fresh build root.
189               Does not create the build root or perform a build.
190
191   --with X
192               enable feature X for build
193
194   --without X
195               disable feature X for build
196
197   --define 'X Y'
198               define macro X with value Y
199
200   --ccache
201               use ccache to speed up rebuilds
202
203   --icecream N
204               use N parallel build jobs with icecream
205   --overlay OVERLAY
206               Copy overlay filesystem to buildroot after installing
207               all RPMs. This must be a valid directory.
208
209   --rsync-src RSYNCSRC
210               Copy overlay folder (RSYNCSRC) to a folder (RSYNCDEST)
211               inside the buildroot using rsync.
212               It will "%define RSYNCDONE 1" for handling %setup in your
213               specfile. E.g.:
214               %prep
215               %if 0%{?RSYNCDONE}
216               %setup -n aaa_base -T -D -b 5 -b 7
217               %else
218               %setup -n aaa_base -b 5 -b 7
219               %endif
220
221   --rsync-dest RSYNCDEST
222               Copy overlay folder (RSYNCSRC) to a folder (RSYNCDEST)
223               inside the buildroot using rsync.
224
225   --uid uid:gid
226               Specify the uid and gid to use for the abuild user.
227               This is useful if you are hacking in the buildroot.
228               This must be set to the same value if the buildroot is re-used.
229
230   --vm-type TYPE
231               Use virtual machine instead of chroot
232               TYPE is one of xen|kvm|uml|qemu|lxc
233
234   --vm-disk FILE
235               Use FILE as disk for virtual machine.
236               Defaults to \$BUILD_ROOT.img if unset
237
238   --vm-swap FILE
239               Use FILE as swap space for virtual machine. The swap space is
240               also used for retrieving packages from the VM so it's size must be
241               sufficiently large
242
243   --vm-disk-size SIZEINMB
244   --vm-swap-size SIZEINMB
245   --vm-disk-filesystem TYPE
246               Defaults for automatic setup of VM root/swap files
247
248   --vm-kernel FILE
249   --vm-initrd FILE
250               Kernel and initrd to use for VM (kvm and qemu only)
251
252   --debug
253               enable creation of a debuginfo package
254
255 Remember to have fun!
256
257 [*] Maximum RPM: http://www.rpm.org/max-rpm/
258 EOT
259 }
260 usage () {
261     echo "Usage: `basename $0` [--no-init|--clean|--rpms path|--verify|--help] [dir-to-build|spec-to-build]"
262     cleanup_and_exit 1
263 }
264
265 #
266 #  cleanup_and_exit
267 #  return values: 0 -> success, new packages built
268 #                 1 -> error, build failed
269 #                 2 -> successfull build, but no changes to former built packages
270 #                 3 -> something wrong with build host
271 #
272 cleanup_and_exit () {
273     trap EXIT
274     test -z "$1" && set 0
275     rm -f $BUILD_ROOT/exit
276     if test "$1" -eq 1 -a -x /bin/df ; then
277         # okay, it failed, but maybe because disk space?
278         if df $BUILD_ROOT 2>/dev/null | grep -q "100%"; then
279             set 3
280         fi
281     fi
282     if test -n "$RUNNING_IN_VM" ; then
283         chown $browner $BUILD_ROOT
284         cd /
285         if test -n "$VM_SWAP" -a -e "$VM_SWAP" ; then
286             swapoff "$VM_SWAP" 2>/dev/null
287             echo -n "BUILDSTATUS$1" >"$VM_SWAP"
288         fi
289         exec >&0 2>&0        # so that the logging tee finishes
290         sleep 1                # wait till tee terminates
291         if test "$VM_TYPE" != lxc; then
292             kill -9 -1        # goodbye cruel world
293             if ! test -x /sbin/halt ; then
294                 test -e /proc/sysrq-trigger || mount -n -tproc none /proc
295                 sync
296                 sleep 2 # like halt does
297                 if test -e /proc/sysrq-trigger; then
298                     echo o > /proc/sysrq-trigger
299                     sleep 5 # wait for sysrq to take effect
300                 else
301                     echo "Warning: VM doesn't support sysrq and /sbin/halt not installed"
302                 fi
303             else
304                 halt -f -p
305             fi
306             echo "Warning: clean shut down of the VM didn't work"
307         fi
308     else
309         umount -n $BUILD_ROOT/proc/sys/fs/binfmt_misc 2> /dev/null || true
310         umount -n $BUILD_ROOT/proc 2>/dev/null || true
311         umount -n $BUILD_ROOT/dev/pts 2>/dev/null || true
312         test "$VM_IMAGE" = 1 && VM_IMAGE=
313         [ -n "$VM_IMAGE" ] && umount $BUILD_ROOT 2>/dev/null || true
314     fi
315 #    echo "pid $$ exit $1"
316     exit $1
317 }
318
319 fail_exit()
320 {
321   cleanup_and_exit 1
322 }
323
324 shellquote()
325 {
326     for arg; do
327         arg=${arg/\\/\\\\}
328         arg=${arg/\$/\\\$}
329         arg=${arg/\"/\\\"}
330         arg=${arg/\`/\\\`}
331         echo -n " \"$arg\""
332     done
333 }
334
335 # create a shell script from command line. Used for preserving arguments
336 # through /bin/su -c
337 toshellscript()
338 {
339         echo "#!/bin/sh -x"
340         echo -n exec
341         shellquote "$@"
342         echo
343 }
344
345 setupccache()
346 {
347     if [ "$ccache" = 1 ]; then
348         if mkdir -p $BUILD_ROOT/var/lib/build/ccache/bin; then
349             for i in $(ls $BUILD_ROOT/usr/bin | grep -E '^(cc|gcc|[cg][+][+])([-]?[234][.]?[0-9])*$'); do
350 #                ln -sf /usr/bin/ccache $BUILD_ROOT/var/lib/build/ccache/bin/$i
351                 rm -f $BUILD_ROOT/var/lib/build/ccache/bin/$i
352                 test -e $BUILD_ROOT/usr/bin/$i || continue
353                 echo '#! /bin/sh' > $BUILD_ROOT/var/lib/build/ccache/bin/$i
354                 echo "test -e /usr/bin/$i || exit 1" >> $BUILD_ROOT/var/lib/build/ccache/bin/$i
355                 echo 'export PATH=/opt/icecream/bin:/usr/bin:$PATH' >> $BUILD_ROOT/var/lib/build/ccache/bin/$i
356                 echo "ccache $i \"\$@\"" >> $BUILD_ROOT/var/lib/build/ccache/bin/$i
357                 chmod 755 $BUILD_ROOT/var/lib/build/ccache/bin/$i
358                 echo "Installed ccache wrapper as $BUILD_ROOT/var/lib/build/ccache/bin/$i"
359             done
360         fi
361         mkdir -p "$BUILD_ROOT"/.ccache
362         chown -R "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT/.ccache"
363         echo "export CCACHE_DIR=/.ccache" > "$BUILD_ROOT"/etc/profile.d/build_ccache.sh
364         echo 'export PATH=/var/lib/build/ccache/bin:$PATH' >> "$BUILD_ROOT"/etc/profile.d/build_ccache.sh
365     else
366         rm -f "$BUILD_ROOT$builduserhome"/bin/{gcc,g++,cc,c++}
367         rm -f "$BUILD_ROOT"/var/lib/build/ccache/bin/{gcc,g++,cc,c++}
368     fi
369 }
370
371 setupicecream()
372 {
373     if [ "$icecream" -eq 0 ]; then
374         rm -rf "$BUILD_ROOT"/var/run/icecream
375         rm -f "$BUILD_ROOT"/etc/profile.d/build_icecream.sh
376         return
377     fi
378
379     if ! chroot "$BUILD_ROOT" rpm -q icecream >/dev/null 2>/dev/null; then
380         echo "*** icecream package not installed ***"
381         false
382         return
383     fi
384
385     echo "using icecream with $icecream jobs"
386
387     if [ "$ccache" -ne 1 ]; then
388         echo 'export PATH=/opt/icecream/bin:$PATH' > "$BUILD_ROOT"/etc/profile.d/build_icecream.sh
389     else
390         echo 'export CCACHE_PATH=/opt/icecream/bin' > "$BUILD_ROOT"/etc/profile.d/build_icecream.sh
391     fi
392
393     local icecc_vers=(`shopt -s nullglob; echo $BUILD_ROOT/var/run/icecream/*.tar.{bz2,gz}`)
394     icecc_vers=${icecc_vers//$BUILD_ROOT/}
395
396     # XXX use changelog like autobuild does instead?
397     # only run create-env if compiler or glibc changed
398     if [ -z "$icecc_vers" \
399         -o ! -e "$BUILD_ROOT/$icecc_vers" \
400         -o "$BUILD_ROOT/usr/bin/gcc" -nt "$BUILD_ROOT/$icecc_vers" \
401         -o "$BUILD_ROOT/usr/bin/g++" -nt "$BUILD_ROOT/$icecc_vers" \
402         -o "$BUILD_ROOT/usr/bin/as" -nt "$BUILD_ROOT/$icecc_vers" \
403         -o "$BUILD_ROOT/lib/libc.so.6" -nt "$BUILD_ROOT/$icecc_vers" ]
404     then
405         rm -rf $BUILD_ROOT/var/run/icecream
406         mkdir -p $BUILD_ROOT/var/run/icecream
407         if [ -e "$BUILD_ROOT"/usr/bin/create-env ]; then
408           createenv=/usr/bin/create-env
409         elif [ -e "$BUILD_ROOT"/usr/lib/icecc/icecc-create-env ]; then
410           createenv="/usr/lib/icecc/icecc-create-env /usr/bin/gcc /usr/bin/g++" # XXX
411         elif [ -e "$BUILD_ROOT"/usr/lib64/icecc/icecc-create-env ]; then
412           createenv="/usr/lib64/icecc/icecc-create-env /usr/bin/gcc /usr/bin/g++" # XXX
413         else
414           echo "create-env not found"
415           false
416           return
417         fi
418         chroot $BUILD_ROOT bash -c "cd /var/run/icecream; $createenv" || cleanup_and_exit 1
419         icecc_vers=(`shopt -s nullglob; echo $BUILD_ROOT/var/run/icecream/*.tar.{bz2,gz}`)
420         icecc_vers=${icecc_vers//$BUILD_ROOT/}
421     else
422         echo "reusing existing icecream environment $icecc_vers"
423     fi
424     if [ -n "$icecc_vers" ]; then
425       echo "export ICECC_VERSION=$icecc_vers" >> "$BUILD_ROOT"/etc/profile.d/build_icecream.sh
426     fi
427 }
428
429 setmemorylimit()
430 {
431     if [ -n "$VM_IMAGE" -o -n "$RUNNING_IN_VM" ]; then
432         return
433     fi
434     local mem
435     while read mem; do
436         case "$mem" in
437             MemTotal:*)
438                 set -- $mem
439                 eval "mem=\$(($2/3*4))"
440                 ulimit -v $mem
441                 echo "Memory limit set to ${mem}KB"
442                 break;
443             ;;
444         esac
445     done < <(cat /proc/meminfo) # cat for proc stuff
446 }
447
448 create_baselibs()
449 {
450     local pkgs=()
451
452     BASELIBS_CFG=
453
454     if test "$BUILDTYPE" == "dsc" ; then
455         pkgs=($DEBS)
456     else # spec and kiwi
457         if test -e $BUILD_ROOT$TOPDIR/SOURCES/baselibs.conf ; then
458             BASELIBS_CFG="-c $TOPDIR/SOURCES/baselibs.conf"
459         fi
460         if test -e $BUILD_ROOT/usr/lib/build/baselibs_global.conf; then
461             BASELIBS_GLOBAL="-c /usr/lib/build/baselibs_global.conf"
462         fi
463         pkgs=($RPMS)
464     fi
465
466     mount -n -tproc none $BUILD_ROOT/proc 2> /dev/null
467     # don't use -R as extracted sources, build root etc might be below $TOPDIR
468     chown "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT$TOPDIR"/* "$BUILD_ROOT$TOPDIR"/RPMS/* || true
469
470     local mkbaselibs="/usr/lib/build/mkbaselibs"
471     local whichone=''
472     # $BUILD_DIR is set to /.build when using a vm. So we need to
473     # hardcode /usr/lib/build instead of $BUILD_DIR to prefer
474     # mkbaselibs from the distro.
475     if test -f $BUILD_ROOT$mkbaselibs; then
476         if test -z "$BASELIBS_CFG" -a -e $BUILD_ROOT/usr/lib/build/baselibs.conf ; then
477             BASELIBS_CFG="-c /usr/lib/build/baselibs.conf"
478         fi
479     else
480         if test "$CREATE_BASELIBS" = 'internal'; then
481             echo "Warning: mkbaselibs missing in build root, skipping baselibs"
482             return
483         fi
484         # use external version
485         whichone=" (external)"
486         mkbaselibs="/.mkbaselibs/mkbaselibs"
487         rm -rf $BUILD_ROOT/.mkbaselibs
488         mkdir -p $BUILD_ROOT/.mkbaselibs
489         cp -f $BUILD_DIR/mkbaselibs $BUILD_ROOT/.mkbaselibs/
490         if test "$BUILDTYPE" == "dsc" ; then
491             cp -f $BUILD_DIR/baselibs_global-deb.conf $BUILD_ROOT/.mkbaselibs/baselibs_g.conf
492             cp -f $BUILD_ROOT$TOPDIR/SOURCES/baselibs-deb.conf $BUILD_ROOT/.mkbaselibs/baselibs-deb.conf
493             BASELIBS_CFG="-c /.mkbaselibs/baselibs-deb.conf"
494         else
495             cp -f $BUILD_DIR/baselibs_global.conf $BUILD_ROOT/.mkbaselibs/baselibs_g.conf
496             if test -z "$BASELIBS_CFG" -a -e $BUILD_DIR/baselibs.conf; then
497                 cp -f $BUILD_DIR/baselibs.conf $BUILD_ROOT/.mkbaselibs/baselibs.conf
498                 BASELIBS_CFG="-c /.mkbaselibs/baselibs.conf"
499             fi
500         fi
501         if test -e $BUILD_ROOT/.mkbaselibs/baselibs_g.conf; then
502             BASELIBS_GLOBAL="-c /.mkbaselibs/baselibs_g.conf"
503         fi
504     fi
505     echo "... creating baselibs$whichone"
506     chroot $BUILD_ROOT su -c "$mkbaselibs $BASELIBS_GLOBAL $BASELIBS_CFG ${pkgs[*]#$BUILD_ROOT}" - $BUILD_USER || cleanup_and_exit 1
507     rm -rf $BUILD_ROOT/.mkbaselibs
508 }
509
510 copy_oldpackages()
511 {
512     local i=0
513     local d
514     local dest
515     [ -z "$RUNNING_IN_VM" ] || return 0
516     if [ -z "$old_packages" ]; then
517         rm -rf "$BUILD_ROOT"/.build.oldpackages*
518         return 0
519     fi
520     for d in "${old_packages[@]}"; do
521         dest="$BUILD_ROOT/.build.oldpackages"
522         test "$i" = 0 || dest="$dest$i"
523         if [ -d "$d" -a "$d" != "$dest" ] ; then
524             rm -rf "$dest"
525             mkdir -p "$dest"
526             cp -L $d/* "$dest"
527             : $((++i))
528         fi
529     done
530 }
531
532 vm_img_mkfs()
533 {
534     local fs="$1"
535     local img="$2"
536     local mkfs tunefs
537     eval "mkfs=\"\$vm_img_mkfs_${fs}\""
538     eval "tunefs=\"\$vm_img_tunefs_${fs}\""
539
540     if test -z "$mkfs"; then
541         echo "filesystem \"$fs\" isn't supported"
542         cleanup_and_exit 3
543     fi
544
545
546     echo "Creating $fs filesystem on $img"
547     $mkfs "$img"
548     if test -n "$tunefs" ; then
549         $tunefs "$img" || cleanup_and_exit 3
550     fi
551
552 }
553
554 detect_vm_2nd_stage()
555 {
556     if ! test "$0" = "/.build/build" ; then
557         return 1
558     fi
559     if test $$ -eq 1 ; then
560         # ignore special init signals if we're init
561         # we're using ' ' instead of '' so that the signal handlers
562         # are reset in the child processes
563         trap ' ' HUP TERM
564         $0 "$@"
565         cleanup_and_exit $?
566     fi
567     echo "2nd stage started in virtual machine"
568     BUILD_ROOT=/
569     BUILD_DIR=/.build
570     . $BUILD_DIR/build.data
571     echo "machine type: `uname -m`"
572     if test "$PERSONALITY" != 0 -a -z "$PERSONALITY_SET" ; then
573         export PERSONALITY_SET=true
574         echo "switching personality to $PERSONALITY..."
575         # this is 32bit perl/glibc, thus the 32bit syscall number
576         exec perl -e 'syscall(136, '$PERSONALITY') == -1 && warn("personality: $!\n");exec "/.build/build" || die("/.build/build: $!\n")'
577     fi
578     RUNNING_IN_VM=true
579     mount -orw -n -tproc none /proc
580     if test "$VM_TYPE" != 'lxc'; then
581         mount -n ${VMDISK_MOUNT_OPTIONS},remount,rw /
582     fi
583 # qemu inside of xen does not work, check again with kvm later before enabling this
584 #    if [ -e /dev/kqemu ]; then
585 #        # allow abuild user to run qemu
586 #        chmod 0666 /dev/kqemu
587 #    fi
588     if test -n "$VM_SWAP" ; then
589         for i in 1 2 3 4 5 6 7 8 9 10 ; do
590             test -e "$VM_SWAP" && break
591             test $i = 1 && echo "waiting for $VM_SWAP to appear"
592             echo -n .
593             sleep 1
594         done
595         test $i = 1 || echo
596         # recreate the swap device manually if it didn't exist for some
597         # reason, hardcoded to hda2 atm
598         if ! test -b "$VM_SWAP" ; then
599             rm -f "$VM_SWAP"
600             umask 027
601             mknod "$VM_SWAP" b 3 2
602             umask 022
603         fi
604         swapon -v "$VM_SWAP" || exit 1
605     fi
606     HOST="$MYHOSTNAME"
607
608     return 0
609 }
610
611 find_spec_files()
612 {
613     local spec files
614     if [ -z "$SPECFILES" ]; then
615         set -- "`pwd`"
616     else
617         set -- "${SPECFILES[@]}"
618     fi
619     SPECFILES=()
620     for spec in "$@"; do
621         if [ "$spec" = "${spec#/}" ]; then
622             spec="`pwd`/$spec"
623         fi
624
625         if [ -d "$spec" ]; then
626             specs=("$spec"/*.spec)
627             if [ -n "$specs" ]; then
628                 SPECFILES=("${SPECFILES[@]}" "${specs[@]}")
629             else
630                 specs=("$spec"/*.spec)
631                 if [ -n "$specs" ]; then
632                     SPECFILES=("${SPECFILES[@]}" "${specs[@]}")
633                 fi
634             fi
635         else
636             SPECFILES[${#SPECFILES[@]}]="$spec";
637         fi
638     done
639
640     if test -z "$SPECFILES"; then
641         echo no spec files or src rpms found in $@. exit...
642         cleanup_and_exit 1
643     fi
644 }
645
646 become_root_or_fail()
647 {
648     if [ ! -w /root ]; then
649         echo "You have to be root to use $0" >&2
650         exit 1
651     fi
652     cleanup_and_exit 1
653 }
654
655 mkdir_build_root()
656 {
657     if [ -d "$BUILD_ROOT" ]; then
658         # check if it is owned by root
659         if [ -z "$RUNNING_IN_VM" -a \! -O "$BUILD_ROOT" -a "`stat -c %u $BUILD_ROOT`" -ne 0 ]; then
660             echo "BUILD_ROOT=$BUILD_ROOT must be owned by root. Exit..."
661             cleanup_and_exit 1
662         fi
663     else
664         test "$BUILD_ROOT" != "${BUILD_ROOT%/*}" && mkdir -p "${BUILD_ROOT%/*}"
665         if ! mkdir $BUILD_ROOT; then
666             echo "can not create BUILD_ROOT=$BUILD_ROOT. Exit..."
667             cleanup_and_exit 1
668         fi
669     fi
670
671     if [ ! -w "$BUILD_ROOT" ]; then
672         echo "Error: BUILD_ROOT=$BUILD_ROOT not writeable, try --clean."
673         cleanup_and_exit 3
674     fi
675
676     rm -rf "$BUILD_ROOT"/.build.packages
677     if [ -z "$VM_TYPE" -a -z "$RUNNING_IN_VM" ]; then
678        # don't touch this in VM
679        rm -rf "$BUILD_ROOT"/.build
680        mkdir -p "$BUILD_ROOT"/.build
681     fi
682 }
683
684 linux64()
685 {
686         perl -e 'syscall('$PERSONALITY_SYSCALL', 0); exec(@ARGV) || die("$ARGV[0]: $!\n")' "$@"
687 }
688
689 check_for_ppc()
690 {
691     local uname
692
693     uname=$(uname -m)
694
695     if [ "$uname" != "ppc" -a "$uname" != "ppc64" ]; then
696         return
697     fi
698
699     export HOST_ARCH=ppc
700
701     # XXX is this ok for ppc32 hosts? do we care?
702     export kvm_bin="/usr/bin/qemu-system-ppc64"
703     export console=hvc0
704     # XXX check host CPU and adjust guest CPU accordingly
705     export KVM_OPTIONS="-enable-kvm -M pseries -cpu 970mp -m 512 -mem-path /hugetlbfs"
706     export VM_KERNEL=/root/obs_kernel/vmlinux
707     export VM_INITRD=/root/obs_kernel/initrd
708
709     # XXX complain when hugetlbfs is not mounted
710 }
711
712 #### main ####
713
714 trap fail_exit EXIT
715
716 case `perl -V:archname` in
717     *x86_64*) PERSONALITY_SYSCALL=135 ;;
718     *i?86*)   PERSONALITY_SYSCALL=136 ;;
719 esac
720
721 check_for_ppc
722
723 shopt -s nullglob
724
725 if detect_vm_2nd_stage ; then
726     set "/.build-srcdir/$SPECFILE"
727
728 fi
729
730 export PATH=$BUILD_DIR:/sbin:/usr/sbin:$PATH
731
732 . $BUILD_DIR/common_functions || exit 1
733
734 export HOST
735
736 needarg()
737 {
738   if [ -z "$ARG" ]; then
739     echo "$PARAM needs an agrument" >&2
740     cleanup_and_exit 1
741   fi
742 }
743
744 while test -n "$1"; do
745   PARAM="$1"
746   ARG="$2"
747   [ "$ARG" = "${ARG#-}" ] || ARG=""
748   shift
749   case $PARAM in
750     *-*=*)
751       ARG=${PARAM#*=}
752       PARAM=${PARAM%%=*}
753       set -- "----noarg=$PARAM" "$@"
754   esac
755   case $PARAM in
756       *-help|-h)
757         echo_help
758         cleanup_and_exit
759       ;;
760       *-no*init)
761         DO_INIT=false
762       ;;
763       *-no*checks)
764         DO_CHECKS=false
765       ;;
766       *-clean)
767         CLEAN_BUILD='--clean'
768       ;;
769       *-kill)
770         KILL=true
771       ;;
772       *-rpms)
773         needarg
774         BUILD_RPMS="$ARG"
775         shift
776       ;;
777       *-arch)
778         needarg
779         BUILD_ARCH="$ARG"
780         shift
781       ;;
782       *-verify)
783         export VERIFY_BUILD_SYSTEM=true
784       ;;
785       *-target)
786         needarg
787         ABUILD_TARGET="$ARG"
788         shift
789       ;;
790       *-jobs)
791         needarg
792         BUILD_JOBS="$ARG"
793         shift
794       ;;
795       *-extra*packs|-X)
796         needarg
797         BUILD_EXTRA_PACKS="$BUILD_EXTRA_PACKS $ARG"
798         shift
799       ;;
800       *-lint)
801         DO_LINT=true
802         ;;
803       *-baselibs)
804         CREATE_BASELIBS=true
805         ;;
806       *-baselibs-internal)
807         CREATE_BASELIBS=internal
808         ;;
809       *-root)
810         needarg
811         BUILD_ROOT="$ARG"
812         shift
813       ;;
814       *-cachedir)
815         needarg
816         CACHE_DIR="$ARG"
817         shift
818       ;;
819       *-oldpackages)
820         needarg
821         old_packages=("${old_packages[@]}" "$ARG")
822         shift
823       ;;
824       *-dist)
825         needarg
826         BUILD_DIST="$ARG"
827         shift
828       ;;
829       *-xen|*-kvm|--uml|--qemu)
830         VM_TYPE=${PARAM##*-}
831         if [ -n "$ARG" ]; then
832             VM_IMAGE="$ARG"
833             shift
834         else
835             VM_IMAGE=1
836         fi
837       ;;
838       --lxc)
839         VM_TYPE=${PARAM##*-}
840       ;;
841       --vm-type)
842         needarg
843         VM_TYPE="$ARG"
844         case "$VM_TYPE" in
845             xen|kvm|uml|qemu|lxc) ;;
846             none|chroot) VM_TYPE='' ;;
847             *)
848                 echo "VM $VM_TYPE not supported"
849                 cleanup_and_exit
850             ;;
851         esac
852         shift
853       ;;
854       --vm-disk)
855         needarg
856         VM_IMAGE="$ARG"
857         shift
858       ;;
859       *-xenswap|*-swap)
860         needarg
861         VM_SWAP="$ARG"
862         shift
863       ;;
864       *-xenmemory|*-memory)
865         needarg
866         MEMSIZE="$ARG"
867         shift
868       ;;
869       *-vm-kernel)
870         needarg
871         VM_KERNEL="$ARG"
872         shift
873       ;;
874       *-vm-initrd)
875         needarg
876         VM_INITRD="$ARG"
877         shift
878       ;;
879       *-vmdisk-rootsize|--vm-disk-size)
880         needarg
881         VMDISK_ROOTSIZE="$ARG"
882         shift
883       ;;
884       *-vmdisk-swapsize|--vm-swap-size)
885         needarg
886         VMDISK_SWAPSIZE="$ARG"
887         shift
888       ;;
889       *-vmdisk-filesystem|--vm-disk-filesystem)
890         needarg
891         VMDISK_FILESYSTEM="$ARG"
892         shift
893       ;;
894       *-rpmlist)
895         needarg
896         RPMLIST="--rpmlist $ARG"
897         BUILD_RPMS=
898         shift
899       ;;
900       *-release)
901         needarg
902         RELEASE="$ARG"
903         shift
904       ;;
905       *-logfile)
906         needarg
907         LOGFILE="$ARG"
908         shift
909       ;;
910       *-reason)
911         needarg
912         REASON="$ARG"
913         shift
914       ;;
915       *-norootforbuild)
916         NOROOTFORBUILD=true
917       ;;
918       *-stage)
919         needarg
920         BUILD_RPM_BUILD_STAGE="$ARG"
921         shift
922       ;;
923       *-useusedforbuild)
924         USEUSEDFORBUILD="--useusedforbuild"
925       ;;
926       *-list*state)
927         LIST_STATE=true
928       ;;
929       --define|--with|--without)
930         needarg
931         definesnstuff[${#definesnstuff[@]}]="$PARAM";
932         definesnstuff[${#definesnstuff[@]}]="$ARG";
933         shift
934       ;;
935       --repository|--repo)
936         needarg
937         repos[${#repos[@]}]="$PARAM";
938         repos[${#repos[@]}]="$ARG";
939         shift
940       ;;
941       --icecream)
942         needarg
943         icecream="$ARG"
944         if [ "$icecream" -gt 0 ]; then
945                 BUILD_JOBS="$ARG"
946         fi
947         shift
948       ;;
949       --ccache)
950         ccache=1
951       ;;
952       --debug)
953         BUILD_DEBUG=1
954       ;;
955       --incarnation)
956         needarg
957         INCARNATION=$ARG
958         shift
959       ;;
960       --disturl)
961         needarg
962         DISTURL=$ARG
963         shift
964       ;;
965       --linksources)
966         LINKSOURCES=true
967       ;;
968       ----noarg)
969         echo "$ARG does not take an argument"
970         cleanup_and_exit
971       ;;
972       *-changelog)
973         CHANGELOG=true
974       ;;
975       --overlay)
976         needarg
977         OVERLAY=$ARG
978         shift
979       ;;
980       --rsync-src)
981         needarg
982         RSYNCSRC=$ARG
983         shift
984       ;;
985       --rsync-dest)
986         needarg
987         RSYNCDEST=$ARG
988         shift
989       ;;
990       --uid)
991         needarg
992         ABUILD_ID="$ARG"
993         if test -n "${ABUILD_ID//[0-9:]/}"; then
994             echo "--uid argument must be uid:gid"
995             cleanup_and_exit
996         fi
997         ABUILD_UID=${ABUILD_ID%:*}
998         ABUILD_GID=${ABUILD_ID#*:}
999         shift
1000       ;;
1001       --shell)
1002           shell=1
1003           shift
1004       ;;
1005       --signdummy)
1006         SIGNDUMMY=1
1007       ;;
1008       -*)
1009         echo Unknown Option "$PARAM". Exit.
1010         cleanup_and_exit 1
1011       ;;
1012       *)
1013         SPECFILES[${#SPECFILES[@]}]="$PARAM";
1014       ;;
1015     esac
1016 done
1017
1018 if test "$VM_TYPE" = "lxc"; then
1019     VM_IMAGE=''
1020     VM_SWAP=''
1021 fi
1022
1023 if test -n "$KILL" ; then
1024     test -z "$SRCDIR" || usage
1025     if test -n "$VM_IMAGE" -a -n "$VM_SWAP" -a -n "$VM_TYPE"; then
1026         # mark job as failed so that we don't extract packages
1027         echo -n "BUILDSTATUS1" >"$VM_SWAP"
1028     fi
1029     (set -C; > "$BUILD_ROOT/exit" 2>/dev/null || true)
1030     if test "$VM_TYPE" = 'lxc'; then
1031         LXCID=${BUILD_ROOT##*/}
1032         lxc-stop -n "$LXCID" || true
1033         lxc-destroy -n "$LXCID"
1034     elif test -z "$VM_IMAGE" ; then
1035         if ! $BUILD_DIR/killchroot -s 9 $BUILD_ROOT ; then
1036             echo "could not kill build in $BUILD_ROOT"
1037             cleanup_and_exit 1
1038         fi
1039     elif test "$VM_TYPE" = 'xen'; then
1040         XENID="${VM_IMAGE%/root}"
1041         XENID="${XENID%/tmpfs}"
1042         XENID="${XENID##*/}"
1043         XENID="${XENID#root_}"
1044         if xm list "build_$XENID" >/dev/null 2>&1 ; then
1045             if ! xm destroy "build_$XENID" ; then
1046                 echo "could not kill xen build $XENID"
1047                 cleanup_and_exit 1
1048             fi
1049         fi
1050     elif test -n "$VM_TYPE"; then
1051         if ! fuser -k -TERM "$VM_IMAGE"; then
1052             echo "could not kill build in $VM_IMAGE"
1053             cleanup_and_exit 1
1054         fi
1055     else
1056         echo "don't know how to kill this build job"
1057         cleanup_and_exit 1
1058     fi
1059     cleanup_and_exit 0
1060 fi
1061
1062 if [ "$VM_TYPE" = 'xen' -a -z "$RUNNING_IN_VM" ]; then
1063     # XXX: merge with kvm path?
1064     if [ -n "$VM_KERNEL" ]; then
1065         vm_kernel="$VM_KERNEL"
1066     elif [ -e "/boot/vmlinuz-xen" ]; then
1067         vm_kernel="/boot/vmlinuz-xen"
1068     fi
1069     if [ -n "$VM_INITRD" ]; then
1070         vm_initrd="$VM_INITRD"
1071     elif [ -e "/boot/initrd-xen" ]; then
1072         vm_initrd="/boot/initrd-xen"
1073     fi
1074 fi
1075
1076 if [ "$VM_TYPE" = 'kvm' -a -z "$RUNNING_IN_VM" ]; then
1077     if [ ! -r /dev/kvm -o ! -x "$kvm_bin" ]; then
1078         echo "host doesn't support kvm"
1079         echo "either the kvm kernel-module is not loaded or kvm is not installed or hardware virtualization is deactivated in the BIOS."
1080         cleanup_and_exit 3
1081     fi
1082     qemu_bin="$kvm_bin"
1083     if [ -n "$VM_KERNEL" ]; then
1084         vm_kernel="$VM_KERNEL"
1085     fi
1086
1087     # check if a SUSE system with virtio initrd is running
1088     if [ -z "$VM_INITRD" -a -e /etc/sysconfig/kernel ]; then
1089        a=$( source /etc/sysconfig/kernel; echo $INITRD_MODULES )
1090        have_virtio_pci=""
1091        have_virtio_blk=""
1092        for i in $a; do
1093           [ "$i" == "virtio_pci" ] && have_virtio_pci="1"
1094           [ "$i" == "virtio_blk" ] && have_virtio_blk="1"
1095        done
1096        [ -n "$have_virtio_pci" -a -n "$have_virtio_blk" ] && VM_INITRD="/boot/initrd"
1097     fi
1098
1099     if [ -n "$VM_INITRD" ]; then
1100         vm_initrd="$VM_INITRD"
1101         kvm_virtio=1
1102     elif [ -e "${vm_initrd}-build" ]; then
1103         vm_initrd="${vm_initrd}-build"
1104         kvm_virtio=1
1105     else
1106         if [ -L "$vm_initrd" ]; then
1107             vm_initrd=`readlink -f "$vm_initrd"` || cleanup_and_exit 3
1108         fi
1109         vm_initrd_virtio="${vm_initrd}-virtio"
1110
1111         if [ ! -e ${vm_initrd_virtio} -o $vm_kernel -nt ${vm_initrd_virtio} ]; then
1112             mkinitrd_virtio_cmd=(env rootfstype="$VMDISK_FILESYSTEM" \
1113                     mkinitrd -d /dev/null \
1114                     -m "ext3 ext4 btrfs reiserfs binfmt_misc virtio_pci virtio_blk" \
1115                     -k $vm_kernel \
1116                     -i ${vm_initrd_virtio})
1117             if [ ! -w /root -o -n "$RPMLIST" ]; then
1118                 echo "No initrd that provides virtio support found. virtio accelleration disabled."
1119                 echo "Run the following command as root to enable virtio:"
1120                 shellquote "${mkinitrd_virtio_cmd[@]}"
1121                 echo
1122             elif /sbin/modinfo virtio_pci >/dev/null 2>&1; then
1123                 echo "creating $vm_initrd_virtio"
1124                 "${mkinitrd_virtio_cmd[@]}" || cleanup_and_exit 1
1125                 kvm_virtio=1
1126                 vm_initrd="${vm_initrd_virtio}"
1127             fi
1128         else
1129             kvm_virtio=1
1130             vm_initrd="${vm_initrd_virtio}"
1131         fi
1132     fi
1133
1134     if [ "$HOST_ARCH" = ppc ]; then
1135         # KVM on PPC can not run virtio yet, so we need to use the default vio
1136         kvm_virtio=
1137     fi
1138
1139     if [ "$kvm_virtio" = 1 ]; then
1140         VM_SWAPDEV=/dev/vdb
1141         qemu_rootdev=/dev/vda
1142     else
1143         VM_SWAPDEV=/dev/sdb
1144         qemu_rootdev=/dev/sda
1145     fi
1146 fi
1147
1148 if [ "$VM_TYPE" = 'qemu' ]; then
1149     VM_SWAPDEV=/dev/sdb
1150     qemu_rootdev=/dev/sda
1151 fi
1152
1153 if [ -z "$RPMLIST" -a -z "$RUNNING_IN_VM" ]; then
1154     if [ -z "$repos" -a -z "$BUILD_RPMS" ]; then
1155         repos=(--repository 'zypp://')
1156     fi
1157 else
1158     repos=()
1159 fi
1160
1161 set_build_arch
1162
1163 if [ -n "$CLEAN_BUILD" ]; then
1164     DO_INIT=true
1165 fi
1166
1167 find_spec_files
1168
1169 if test -n "$LIST_STATE" ; then
1170     BUILD_ROOT=`mktemp -d /var/tmp/build-list-state-XXXXXX`
1171     test -d "$BUILD_ROOT" || cleanup_and_exit 3
1172     SPECFILE=$SPECFILES # only one specified anyways
1173     if test "$SPECFILE" != "${SPECFILE%.src.rpm}" ; then
1174        rm -rf $BUILD_ROOT/usr/src/packages
1175        mkdir -p $BUILD_ROOT/usr/src/packages/SOURCES $BUILD_ROOT/usr/src/packages/SPECS
1176        rpm -i --nodigest --nosignature --root $BUILD_ROOT $SPECFILE || {
1177            echo "could not install $SPECFILE." 2>&1
1178            rm -rf $BUILD_ROOT
1179            cleanup_and_exit 3
1180        }
1181        for SPECFILE in $BUILD_ROOT/usr/src/packages/SPECS/*.spec ; do : ; done
1182     fi
1183     init_buildsystem --cachedir "$CACHE_DIR" --list-state "${definesnstuff[@]}" "${repos[@]}" $USEUSEDFORBUILD $SPECFILE $BUILD_EXTRA_PACKS
1184     ERR=$?
1185     rm -rf $BUILD_ROOT
1186     cleanup_and_exit $ERR
1187 fi
1188
1189 if test -z "$RUNNING_IN_VM" ; then
1190     if test -n "$VM_IMAGE" ; then
1191         if test "$VM_IMAGE" = 1 ; then
1192             VM_IMAGE="$BUILD_ROOT.img"
1193             echo "using $VM_IMAGE as vm image"
1194             if test -z "$VM_SWAP"; then
1195                 VM_SWAP="$BUILD_ROOT.swap"
1196                 echo "using $VM_SWAP as vm swap"
1197             fi
1198         fi
1199         if [ "$VM_TYPE" = 'xen' ]; then
1200             # this should not be needed, but sometimes a xen instance got lost
1201             XENID="${VM_IMAGE%/root}"
1202             XENID="${XENID%/tmpfs}"
1203             XENID="${XENID##*/}"
1204             XENID="${XENID#root_}"
1205             xm destroy "build_$XENID" >/dev/null 2>&1
1206         fi
1207         if test ! -e "$VM_IMAGE"; then
1208             echo "Creating $VM_IMAGE (${VMDISK_ROOTSIZE}M)"
1209             mkdir -p "${VM_IMAGE%/*}"
1210             dd if=/dev/zero of="$VM_IMAGE" bs=1M count=0 seek="$VMDISK_ROOTSIZE" || cleanup_and_exit 3
1211             if test -z "$CLEAN_BUILD" ; then
1212                 vm_img_mkfs "$VMDISK_FILESYSTEM" "$VM_IMAGE" || cleanup_and_exit 3
1213             fi
1214         fi
1215         if test -n "$VM_SWAP" -a ! -e "$VM_SWAP"; then
1216             # setup VM_SWAP
1217             echo "Creating $VM_SWAP (${VMDISK_SWAPSIZE}M)"
1218             mkdir -p "${VM_SWAP%/*}"
1219             dd if=/dev/zero of="$VM_SWAP" bs=1M count=0 seek="$VMDISK_SWAPSIZE" || cleanup_and_exit 3
1220         fi
1221         if test ! -e "$VM_IMAGE" ; then
1222             echo "you need to create $VM_IMAGE first"
1223             cleanup_and_exit 3
1224         fi
1225         if test -n "$CLEAN_BUILD" ; then
1226             vm_img_mkfs "$VMDISK_FILESYSTEM" "$VM_IMAGE" || cleanup_and_exit 3
1227         fi
1228         mkdir_build_root
1229         if [ -w /root ]; then
1230             if [ -b $VM_IMAGE ]; then
1231                 # mount device directly
1232                 mount $VMDISK_MOUNT_OPTIONS $VM_IMAGE $BUILD_ROOT || cleanup_and_exit 3
1233             else
1234                 mount ${VMDISK_MOUNT_OPTIONS},loop $VM_IMAGE $BUILD_ROOT || cleanup_and_exit 3
1235             fi
1236         else
1237             if ! mount $BUILD_ROOT; then
1238                 echo "mounting the build root failed. An fstab entry is probably missing or incorrect."
1239                 echo "/etc/fstab should contain an entry like this:"
1240                 echo "$VM_IMAGE $BUILD_ROOT auto noauto,user,loop 0 0"
1241                 cleanup_and_exit 3
1242             fi
1243         fi
1244     else
1245         test -w /root || become_root_or_fail
1246     fi
1247     if test -n "$VM_SWAP" ; then
1248         dd if=/dev/zero of="$VM_SWAP" bs=12 count=1 conv=notrunc 2>/dev/null
1249         echo "mkswap $VM_SWAP"
1250         mkswap "$VM_SWAP"
1251     fi
1252 fi
1253
1254 mkdir_build_root
1255
1256 if [ "$BUILD_ROOT" = / ]; then
1257     read dummy dummy browner dummy < <(ls -ld /)
1258 fi
1259
1260 rm -f $BUILD_ROOT/exit
1261
1262 if [ -w /root ]; then
1263     mkdir -p $BUILD_ROOT/proc
1264     mkdir -p $BUILD_ROOT/dev/pts
1265     mount -n -tproc none $BUILD_ROOT/proc || true
1266     mount -n -tdevpts none $BUILD_ROOT/dev/pts
1267 fi
1268
1269 if test -z "$VM_IMAGE" -a -z "$LOGFILE"; then
1270     LOGFILE="$BUILD_ROOT/.build.log"
1271 fi
1272
1273 if test -n "$LOGFILE" -a -z "$shell" ; then
1274     echo  logging output to $LOGFILE...
1275     rm -f $LOGFILE
1276     touch $LOGFILE
1277     if test -n "$VM_IMAGE" ; then
1278         exec 1> >(exec -a 'build logging tee' perl -e 'open(F,">>",$ARGV[0])||die("$ARGV[0]: $!\n");$|=1;select(F);$|=1;while(<STDIN>){print STDOUT;s/^\r//s;s/\r\n/\n/gs;print F}' $LOGFILE) 2>&1
1279     else
1280         exec 1> >(exec -a 'build logging tee' tee -a $LOGFILE) 2>&1
1281     fi
1282 fi
1283
1284 setmemorylimit
1285
1286 #
1287 # say hello
1288 #
1289 test -z "$HOST" && HOST=`hostname`
1290
1291 if [ -z "$RUNNING_IN_VM" ]; then
1292     echo Using BUILD_ROOT=$BUILD_ROOT
1293     test -n "$BUILD_RPMS" && echo Using BUILD_RPMS=$BUILD_RPMS
1294     echo Using BUILD_ARCH=$BUILD_ARCH
1295     test -n "$VM_TYPE" && echo "Doing $VM_TYPE build${VM_IMAGE:+ in $VM_IMAGE}"
1296     echo
1297 fi
1298
1299 test "$BUILD_ARCH" = all && BUILD_ARCH=
1300 BUILD_USER_ABUILD_USED=
1301
1302 for SPECFILE in "${SPECFILES[@]}" ; do
1303
1304     SRCDIR="${SPECFILE%/*}"
1305     SPECFILE="${SPECFILE##*/}"
1306
1307     BUILDTYPE=
1308     case $SPECFILE in
1309       *.spec|*.src.rpm) BUILDTYPE=spec ;;
1310       *.dsc) BUILDTYPE=dsc ;;
1311       *.kiwi) BUILDTYPE=kiwi ;;
1312     esac
1313     if test -z "$BUILDTYPE" ; then
1314        echo "don't know how to build $SPECFILE"
1315        cleanup_and_exit 1
1316     fi
1317
1318     cd "$SRCDIR"
1319
1320     if [ -z "$RUNNING_IN_VM" ]; then
1321         echo
1322         echo "$HOST started \"build $SPECFILE\" at `date --utc`."
1323         echo
1324         test -n "$REASON" && echo "$REASON"
1325         echo
1326     fi
1327
1328     #
1329     # first setup building directory...
1330     #
1331     test -s "$SPECFILE" || {
1332        echo "$SPECFILE" is empty.  This should not happen...
1333        cleanup_and_exit 1
1334     }
1335
1336     if test "$SPECFILE" != "${SPECFILE%.src.rpm}" ; then
1337         echo processing src rpm $SRCDIR/$SPECFILE ...
1338         MYSRCDIR=$BUILD_ROOT/.build-srcdir
1339         rm -rf $MYSRCDIR
1340         mkdir -p $MYSRCDIR
1341         cd $MYSRCDIR || cleanup_and_exit 1
1342         $BUILD_DIR/unrpm -q $SRCDIR/$SPECFILE || {
1343             echo "could not install $SPECFILE."
1344             cleanup_and_exit 1
1345         }
1346         for SPECFILE in *.spec ; do : ; done
1347     else
1348         MYSRCDIR="$SRCDIR"
1349     fi
1350
1351     # FIX to work with baselibs_$PROJ etc
1352     if test "$BUILDTYPE" == "dsc" -a -e ${SRCDIR}/baselibs-deb.conf ; then
1353         # Set CREATE_BASELIBS if not set
1354         echo "dsc build and baselibs-deb.conf present: forcing --baselibs to true"
1355         CREATE_BASELIBS=true
1356     fi
1357
1358 # Currently local osc build does not allow extra .deb packages to be
1359 # specified on the command line. Both init_buildsystem and expanddeps
1360 # need to handle .deb dependencies first
1361 #    if test -n "$CREATE_BASELIBS" ; then
1362 #        case $BUILDTYPE in
1363 #            spec) ;;
1364 #            dsc) BUILD_EXTRA_PACKS="$BUILD_EXTRA_PACKS libparse-debcontrol-perl" ;;
1365 #        esac
1366 #    fi
1367
1368     echo processing specfile $MYSRCDIR/$SPECFILE ...
1369
1370     ADDITIONAL_PACKS=""
1371     test -z "$BUILD_EXTRA_PACKS" || ADDITIONAL_PACKS="$ADDITIONAL_PACKS $BUILD_EXTRA_PACKS"
1372     test -z "$CREATE_BASELIBS" || ADDITIONAL_PACKS="$ADDITIONAL_PACKS build"
1373     test "$ccache" = '0' || ADDITIONAL_PACKS="$ADDITIONAL_PACKS ccache"
1374     test "$icecream" = 0 || ADDITIONAL_PACKS="$ADDITIONAL_PACKS icecream gcc-c++"
1375     test -z "$DO_LINT" || ADDITIONAL_PACKS="$ADDITIONAL_PACKS rpmlint-Factory"
1376
1377     if test -n "$CHANGELOG" -a -z "$RUNNING_IN_VM" ; then
1378         rm -f $BUILD_ROOT/.build-changelog
1379         case $SPECFILE in
1380           *.dsc) CFFORMAT=debian ;;
1381           *) CFFORMAT=rpm ;;
1382         esac
1383         echo "running changelog2spec --target $CFFORMAT --file $MYSRCDIR/$SPECFILE"
1384         if ! $BUILD_DIR/changelog2spec --target $CFFORMAT --file "$MYSRCDIR/$SPECFILE" > $BUILD_ROOT/.build-changelog ; then
1385             rm -f $BUILD_ROOT/.build-changelog
1386         fi
1387     fi
1388
1389     if test -n "$VM_TYPE" -a -z "$RUNNING_IN_VM"; then
1390         rm -rf $BUILD_ROOT/.build
1391         mkdir -p $BUILD_ROOT/.build
1392         if test "$DO_INIT" = true ; then
1393             # do fist stage of init_buildsystem
1394             rm -f $BUILD_ROOT/.build.success
1395             set -- init_buildsystem --cachedir "$CACHE_DIR" --prepare "${definesnstuff[@]}" "${repos[@]}" $CLEAN_BUILD $USEUSEDFORBUILD $RPMLIST "$MYSRCDIR/$SPECFILE" $ADDITIONAL_PACKS
1396             echo "$* ..."
1397             "$@" || cleanup_and_exit 1
1398             check_exit
1399             if [ ! -w /root ]; then
1400                 # remove setuid bit if files belong to user to make e.g. mount work
1401                 find $BUILD_ROOT/{bin,sbin,usr/bin,usr/sbin} -type f -uid $UID -perm +4000 -print0 | xargs -0 --no-run-if-empty chmod -s
1402             fi
1403             copy_oldpackages
1404         fi
1405         # start up xen, rerun ourself
1406         cp -a $BUILD_DIR/. $BUILD_ROOT/.build
1407         if ! test "$MYSRCDIR" = $BUILD_ROOT/.build-srcdir ; then
1408             rm -rf $BUILD_ROOT/.build-srcdir
1409             mkdir $BUILD_ROOT/.build-srcdir
1410             if test "$BUILDTYPE" = kiwi ; then
1411                 cp -pRL "$MYSRCDIR"/* $BUILD_ROOT/.build-srcdir
1412             else
1413                 cp -p "$MYSRCDIR"/* $BUILD_ROOT/.build-srcdir
1414             fi
1415             MYSRCDIR=$BUILD_ROOT/.build-srcdir
1416         else
1417             # cwd is at $BUILD_ROOT/.build-srcdir which we want to
1418             # umount later so step aside
1419             cd "$SRCDIR"
1420         fi
1421         Q="'\''"
1422         echo "SPECFILE='${SPECFILE//"'"/$Q}'" > $BUILD_ROOT/.build/build.data
1423         echo "BUILD_JOBS='${BUILD_JOBS//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1424         echo "BUILD_ARCH='${BUILD_ARCH//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1425         echo "BUILD_RPMS='${BUILD_RPMS//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1426         case $BUILD_DIST in
1427             */*)
1428                 cp $BUILD_DIST $BUILD_ROOT/.build/build.dist
1429                 BUILD_DIST=/.build/build.dist
1430                 ;;
1431         esac
1432         echo "BUILD_DIST='${BUILD_DIST//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1433         echo "RELEASE='${RELEASE//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1434         echo "BUILD_DEBUG='${BUILD_DEBUG//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1435         echo "SIGNDUMMY='${SIGNDUMMY//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1436         echo "DO_LINT='${DO_LINT//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1437         echo "DO_CHECKS='${DO_CHECKS//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1438         echo "NOROOTFORBUILD='${NOROOTFORBUILD//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1439         echo "CREATE_BASELIBS='$CREATE_BASELIBS'" >> $BUILD_ROOT/.build/build.data
1440         echo "REASON='${REASON//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1441         echo "CHANGELOG='${CHANGELOG//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1442         echo "INCARNATION='${INCARNATION//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1443         echo "DISTURL='${DISTURL//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1444         echo "DO_INIT='${DO_INIT//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1445         # FIXME: this depends on the kernel and vm.
1446         # could be hda2, sda2 for xen or hdb/sdb for qemu
1447         test -n "$VM_SWAP" && echo "VM_SWAP='${VM_SWAPDEV:-/dev/hda2}'" >> $BUILD_ROOT/.build/build.data
1448         PERSONALITY=0
1449         if test "$VM_TYPE" != 'lxc'; then
1450             test -n "$PERSONALITY_SYSCALL" && PERSONALITY=`perl -e 'print syscall('$PERSONALITY_SYSCALL', 0)."\n"'`
1451         fi
1452         echo "PERSONALITY='$PERSONALITY'" >> $BUILD_ROOT/.build/build.data
1453         echo "MYHOSTNAME='`hostname`'" >> $BUILD_ROOT/.build/build.data
1454         echo -n "definesnstuff=(" >> $BUILD_ROOT/.build/build.data
1455         shellquote "${definesnstuff[@]}" >> $BUILD_ROOT/.build/build.data
1456         echo ")" >> $BUILD_ROOT/.build/build.data
1457         echo -n "repos=(" >> $BUILD_ROOT/.build/build.data
1458         shellquote "${repos[@]}" >> $BUILD_ROOT/.build/build.data
1459         echo ")" >> $BUILD_ROOT/.build/build.data
1460         echo "VM_TYPE='$VM_TYPE'" >> $BUILD_ROOT/.build/build.data
1461         echo "shell='$shell'" >> $BUILD_ROOT/.build/build.data
1462         umount -n $BUILD_ROOT/proc/sys/fs/binfmt_misc 2> /dev/null || true
1463         umount -n $BUILD_ROOT/proc 2> /dev/null || true
1464         umount -n $BUILD_ROOT/dev/pts 2> /dev/null || true
1465         umount -n $BUILD_ROOT/mnt 2> /dev/null || true
1466
1467         if [ -n "$VM_IMAGE" ]; then
1468             check_exit
1469             # needs to work otherwise we have a corrupted file system
1470             umount $BUILD_ROOT || cleanup_and_exit 1
1471         fi
1472
1473         if check_use_emulator; then
1474             if [ -x "$BUILD_DIR/initvm" -a -e "$BUILD_DIR/qemu-reg" ]; then
1475                 vm_init_script="/.build/initvm"
1476             elif [ -e $BUILD_DIR/initscript_qemu_vm ]; then
1477                 vm_init_script="/.build/initscript_qemu_vm"
1478             else
1479                 echo "Warning: can't find initscript to register binfmts"
1480             fi
1481         else
1482             vm_init_script="/.build/build"
1483         fi
1484
1485         if [ "$VM_TYPE" = 'xen' ]; then
1486                 XMROOT="file:$(readlink -f $VM_IMAGE)"
1487                 XMROOT=${XMROOT/#file:\/dev/phy:/dev}
1488                 XMROOT="disk=$XMROOT,hda1,w"
1489                 XMSWAP=
1490                 if test -n "$VM_SWAP" ; then
1491                     XMSWAP="file:$(readlink -f $VM_SWAP)"
1492                     XMSWAP=${XMSWAP/#file:\/dev/phy:/dev}
1493                     XMSWAP="disk=$XMSWAP,hda2,w"
1494                 fi
1495                 XENID="${VM_IMAGE%/root}"
1496                 XENID="${XENID%/tmpfs}"
1497                 XENID="${XENID##*/}"
1498                 XENID="${XENID#root_}"
1499
1500                 echo "booting XEN kernel ..."
1501                 if xm list "build_$XENID" >/dev/null 2>&1 ; then
1502                    echo "Instance already exist, something really went wrong..."
1503                    echo "Please report to your server admin, there might be multiple services running for same domain"
1504                    cleanup_and_exit 3
1505                 fi
1506                 XEN_CONF_FILE=`mktemp /var/tmp/build.xen.conf-XXXXXXXXX` || cleanup_and_exit 3
1507                 echo "kernel = \"$vm_kernel\""                                           >  $XEN_CONF_FILE
1508                 echo "ramdisk = \"$vm_initrd\""                                          >> $XEN_CONF_FILE
1509                 echo "memory = ${MEMSIZE:-64}"                                           >> $XEN_CONF_FILE
1510                 echo "vcpus = $BUILD_JOBS"                                               >> $XEN_CONF_FILE
1511                 echo "root = \"/dev/hda1 ro\""                                           >> $XEN_CONF_FILE
1512                 echo "extra = \"init=/bin/bash console=ttyS0 panic=1 udev_timeout=360\"" >> $XEN_CONF_FILE
1513                 echo "on_poweroff = 'destroy'"                                           >> $XEN_CONF_FILE
1514                 echo "on_reboot = 'destroy'"                                             >> $XEN_CONF_FILE
1515                 echo "on_crash = 'destroy'"                                              >> $XEN_CONF_FILE
1516                 set -- xm create -c $XEN_CONF_FILE name="build_$XENID" $XMROOT $XMSWAP extra="quiet init="$vm_init_script" elevator=noop panic=1 console=ttyS0"
1517                 if test "$PERSONALITY" != 0 ; then
1518                     # have to switch back to PER_LINUX to make xm work
1519                     set -- linux64 "$@"
1520                 fi
1521                 echo "$@"
1522                 "$@" || cleanup_and_exit 3
1523                 rm "$XEN_CONF_FILE"
1524         elif [ "$VM_TYPE" = 'uml' ]; then
1525                 echo "booting UML kernel ..."
1526                 set -- $uml_kernel initrd=$uml_initrd root=/ubda init="$vm_init_script" panic=1 elevator=noop quiet ubd0=$VM_IMAGE ${MEMSIZE:+mem=$MEMSIZE}
1527                 echo "$@"
1528                 "$@"
1529         elif [ "$VM_TYPE" = 'qemu' -o "$VM_TYPE" = 'kvm' ]; then
1530                 echo "booting $VM_TYPE ..."
1531                 if [ "$VM_TYPE" = 'kvm' -a -b "$VM_IMAGE" ]; then
1532                   # speed optimization when using kvm with raw devices
1533                   CACHE=",cache=none"
1534                 else
1535                   # speed optimization when using kvm with raw files
1536                   CACHE=",cache=unsafe"
1537                 fi
1538                 if [ "$kvm_virtio" = 1 ]; then
1539                     qemu_args=(-drive file="$VM_IMAGE",if=virtio$CACHE -drive file="$VM_IMAGE",if=ide,index=0$CACHE)
1540                     if [ -n "$VM_SWAP" ]; then
1541                         qemu_args=("${qemu_args[@]}" "-drive")
1542                         qemu_args=("${qemu_args[@]}" "file=$VM_SWAP,if=virtio$CACHE")
1543                     fi
1544                 else
1545                     qemu_args=(-hda "$VM_IMAGE")
1546                     if [ -n "$VM_SWAP" ]; then
1547                         qemu_args=("${qemu_args[@]}" "-drive")
1548                         qemu_args=("${qemu_args[@]}" "file=$VM_SWAP,if=ide,index=1$CACHE")
1549                     fi
1550                 fi
1551                 if [ -n "$BUILD_JOBS" -a "$icecream" = 0 ]; then
1552                     qemu_args=("${qemu_args[@]}" "-smp" "$BUILD_JOBS")
1553                 fi
1554                 # cpuid is not set correctly in kvm without this
1555                 KVM_OPTIONS=""
1556                 if [ "$VM_TYPE" = 'kvm' ]; then
1557                   KVM_OPTIONS="-cpu host"
1558                 fi
1559
1560                 set -- $qemu_bin -no-reboot -nographic -net none $KVM_OPTIONS \
1561                     -kernel $vm_kernel \
1562                     -initrd $vm_initrd \
1563                     -append "root=$qemu_rootdev panic=1 quiet no-kvmclock nmi_watchdog=0 rw elevator=noop console=$console init=$vm_init_script" \
1564                     ${MEMSIZE:+-m $MEMSIZE} \
1565                     "${qemu_args[@]}"
1566
1567                 if test "$PERSONALITY" != 0 ; then
1568                     # have to switch back to PER_LINUX to make qemu work
1569                     set -- linux64 "$@"
1570                 fi
1571                 echo "$@"
1572                 "$@"
1573         elif [ "$VM_TYPE" = 'lxc' ]; then
1574                 echo "booting $VM_TYPE ..."
1575                 LXCCONF="$BUILD_ROOT/.build.lxc.conf"
1576                 rm -f "$LXCCONF"
1577                 cat $BUILD_DIR/lxc.conf > "$LXCCONF"
1578                 cat >> "$LXCCONF" <<-EOF
1579                 lxc.rootfs = $BUILD_ROOT
1580                 EOF
1581                 # XXX: do this always instead of leaking the hosts' one?
1582                 echo "rootfs / rootfs rw 0 0" > $BUILD_ROOT/etc/mtab
1583                 LXCID=${BUILD_ROOT##*/}
1584                 lxc-destroy -n "$LXCID" >/dev/null 2>&1 || true
1585                 lxc-create -n "$LXCID" -f "$LXCCONF" || cleanup_and_exit 1
1586                 lxc-start -n "$LXCID" "$vm_init_script"
1587                 BUILDSTATUS="$?"
1588                 test "$BUILDSTATUS" != 255 || BUILDSTATUS=3
1589                 cleanup_and_exit "$BUILDSTATUS"
1590         fi
1591         if test -n "$VM_SWAP" ; then
1592             BUILDSTATUS=`dd if="$VM_SWAP" bs=12 count=1 2>/dev/null`
1593             case $BUILDSTATUS in
1594               BUILDSTATUS[02])
1595                 mkdir -p $BUILD_ROOT/.build.packages
1596                 cd $BUILD_ROOT/.build.packages || cleanup_and_exit 1
1597                 echo "build_ extracting built packages..."
1598                 extractbuild --disk "$VM_IMAGE" --input "$VM_SWAP" --skip 512 -v || cleanup_and_exit 3
1599                 # create same layout as with plain chroot
1600                 if test "$BUILDTYPE" = spec ; then
1601                     mkdir -p SRPMS
1602                     for i in *src.rpm *.desktopfiles ; do
1603                         test -e "$i" || continue
1604                         mv "$i" SRPMS/
1605                     done
1606                     for i in *.rpm ; do
1607                         test -e "$i" || continue
1608                         arch=${i%.rpm}
1609                         arch=${i%.delta}
1610                         arch=${arch##*\.}
1611                         mkdir -p RPMS/$arch
1612                         mv "$i" RPMS/$arch/
1613                     done
1614                 elif test "$BUILDTYPE" = dsc ; then
1615                     mkdir -p DEBS
1616                     find . -type f | while read i; do mv "$i" DEBS/; done
1617                 else
1618                     mkdir -p KIWI
1619                     find . -type f | while read i; do mv "$i" KIWI/; done
1620                 fi
1621                 for i in * ; do
1622                     test -f "$i" || continue
1623                     case $i in
1624                         _*|.*) ;;
1625                         *) mkdir -p OTHER ; mv $i OTHER/ ;;
1626                     esac
1627                 done
1628                 cleanup_and_exit ${BUILDSTATUS#BUILDSTATUS}
1629                 ;;
1630               BUILDSTATUS*)
1631                 cleanup_and_exit ${BUILDSTATUS#BUILDSTATUS}
1632                 ;;
1633               *)
1634                 echo "No buildstatus set, either the packager broke the base system (glibc/bash/perl) or the build host has a kernel or hardware problem, OBS server will retry..."
1635                 cleanup_and_exit 3
1636                 ;;
1637             esac
1638             cleanup_and_exit 1
1639         fi
1640         cleanup_and_exit 0
1641     fi
1642
1643     if test "$DO_INIT" = true ; then
1644         #
1645         # create legacy .buildenv file
1646         #
1647         test -z "$INCARNATION" && INCARNATION=0
1648         echo "BUILD_INCARNATION=$INCARNATION" > $BUILD_ROOT/.buildenv
1649         CREATE_BUILD_BINARIES=
1650         egrep '^#[       ]*needsbinariesforbuild[       ]*$' >/dev/null <$MYSRCDIR/$SPECFILE && CREATE_BUILD_BINARIES=--create-build-binaries
1651         set -- init_buildsystem --cachedir "$CACHE_DIR" "${definesnstuff[@]}" "${repos[@]}" $CLEAN_BUILD $USEUSEDFORBUILD $CREATE_BUILD_BINARIES $RPMLIST "$MYSRCDIR/$SPECFILE" $ADDITIONAL_PACKS
1652         echo "$* ..."
1653         "$@" || cleanup_and_exit 1
1654         check_exit
1655         if df $BUILD_ROOT 2>/dev/null | grep -q "100%"; then
1656             df -h $BUILD_ROOT
1657             echo "build does not work on a completely full filesystem"
1658             cleanup_and_exit 1
1659         fi
1660         mount -n -tproc none $BUILD_ROOT/proc || true
1661         mount -n -tdevpts none $BUILD_ROOT/dev/pts
1662
1663         copy_oldpackages
1664     fi
1665
1666     if test -z "$BUILD_DIST" -a -e "$BUILD_ROOT/.guessed_dist" ; then
1667         read BUILD_DIST < $BUILD_ROOT/.guessed_dist
1668     fi
1669
1670     #
1671     # fix rpmrc if we are compiling for i686
1672     #
1673     test -f $BUILD_ROOT/usr/lib/rpm/rpmrc_i586 && mv $BUILD_ROOT/usr/lib/rpm/rpmrc_i586 $BUILD_ROOT/usr/lib/rpm/rpmrc
1674     if test -e $BUILD_ROOT/usr/lib/rpm/rpmrc -a "$BUILD_ARCH" != "${BUILD_ARCH#i686}" ; then
1675         mv $BUILD_ROOT/usr/lib/rpm/rpmrc $BUILD_ROOT/usr/lib/rpm/rpmrc_i586
1676         sed -e 's/^buildarchtranslate: athlon.*/buildarchtranslate: athlon: i686/' -e 's/^buildarchtranslate: i686.*/buildarchtranslate: i686: i686/' < $BUILD_ROOT/usr/lib/rpm/rpmrc_i586 > $BUILD_ROOT/usr/lib/rpm/rpmrc
1677     fi
1678
1679     #
1680     # install dummy sign program if needed
1681     #
1682     test -f $BUILD_ROOT/usr/bin/sign_installed && mv $BUILD_ROOT/usr/bin/sign_installed $BUILD_ROOT/usr/bin/sign
1683     if test -n "$SIGNDUMMY" ; then
1684         test -f $BUILD_ROOT/usr/bin/sign && mv $BUILD_ROOT/usr/bin/sign $BUILD_ROOT/usr/bin/sign_installed
1685         cp $BUILD_DIR/signdummy $BUILD_ROOT/usr/bin/sign
1686         chmod 755 $BUILD_ROOT/usr/bin/sign
1687     fi
1688
1689     #
1690     # check if we want to build with the abuild user
1691     #
1692     BUILD_USER=abuild
1693     if test -x $BUILD_ROOT/bin/rpm ; then
1694         SUSE_VERSION=`chroot $BUILD_ROOT /bin/rpm --eval '%{?suse_version}' 2>/dev/null`
1695         if test -n "$SUSE_VERSION" && test "$SUSE_VERSION" -le 1020 ; then
1696             BUILD_USER=root
1697         fi
1698     fi
1699     if test "$BUILD_USER" = abuild ; then
1700         egrep '^#[       ]*needsrootforbuild[       ]*$' >/dev/null <$SPECFILE && BUILD_USER=root
1701     else
1702         egrep '^#[       ]*norootforbuild[       ]*$' >/dev/null <$SPECFILE && BUILD_USER=abuild
1703     fi
1704     test -n "$NOROOTFORBUILD" && BUILD_USER=abuild
1705
1706     if test $BUILD_USER = abuild ; then
1707         if ! egrep '^abuild:' >/dev/null <$BUILD_ROOT/etc/passwd ; then
1708             echo "abuild::${ABUILD_UID}:${ABUILD_GID}:Autobuild:/home/abuild:/bin/bash" >>$BUILD_ROOT/etc/passwd
1709             echo 'abuild:*:::::::' >>$BUILD_ROOT/etc/shadow # This is needed on Mandriva 2009
1710             echo 'abuild:*::' >>$BUILD_ROOT/etc/gshadow # This is needed on Ubuntu
1711             echo "abuild::${ABUILD_GID}:" >>$BUILD_ROOT/etc/group
1712             mkdir -p $BUILD_ROOT/home/abuild
1713             chown "$ABUILD_UID:$ABUILD_GID" $BUILD_ROOT/home/abuild
1714         else
1715             if ! egrep "^abuild:x?:${ABUILD_UID}:${ABUILD_GID}" >/dev/null <$BUILD_ROOT/etc/passwd ; then
1716                 echo "abuild user present in the buildroot ($BUILD_ROOT) but uid:gid does not match"
1717                 echo "buildroot currently using:"
1718                 egrep "^abuild:" <$BUILD_ROOT/etc/passwd
1719                 echo "build script attempting to use:"
1720                 echo "abuild::${ABUILD_UID}:${ABUILD_GID}:..."
1721                 echo "build aborting"
1722                 cleanup_and_exit 1
1723             fi
1724         fi
1725         if test -f $BUILD_ROOT/etc/shadow ; then
1726             sed -e "s@^root::@root:*:@" < $BUILD_ROOT/etc/shadow > $BUILD_ROOT/etc/shadow.t && mv $BUILD_ROOT/etc/shadow.t $BUILD_ROOT/etc/shadow
1727         fi
1728         if test -f $BUILD_ROOT/etc/gshadow ; then
1729             sed -e "s@^root::@root:*:@" < $BUILD_ROOT/etc/gshadow > $BUILD_ROOT/etc/gshadow.t && mv $BUILD_ROOT/etc/gshadow.t $BUILD_ROOT/etc/gshadow
1730         fi
1731         BUILD_USER_ABUILD_USED=true
1732     else
1733         # building as root
1734         ABUILD_UID=0
1735         ABUILD_GID=0
1736         if egrep '^abuild:' >/dev/null <$BUILD_ROOT/etc/passwd ; then
1737             rm -rf $BUILD_ROOT/home/abuild
1738             egrep -v '^abuild:' <$BUILD_ROOT/etc/passwd >$BUILD_ROOT/etc/passwd.new
1739             mv $BUILD_ROOT/etc/passwd.new $BUILD_ROOT/etc/passwd
1740             egrep -v '^abuild:' <$BUILD_ROOT/etc/group >$BUILD_ROOT/etc/group.new
1741             mv $BUILD_ROOT/etc/group.new $BUILD_ROOT/etc/group
1742             if test -f $BUILD_ROOT/etc/shadow ; then
1743               egrep -v '^abuild:' <$BUILD_ROOT/etc/shadow >$BUILD_ROOT/etc/shadow.new
1744               mv $BUILD_ROOT/etc/shadow.new $BUILD_ROOT/etc/shadow
1745             fi
1746             if test -f $BUILD_ROOT/etc/gshadow ; then
1747               egrep -v '^abuild:' <$BUILD_ROOT/etc/gshadow >$BUILD_ROOT/etc/gshadow.new
1748               mv $BUILD_ROOT/etc/gshadow.new $BUILD_ROOT/etc/gshadow
1749             fi
1750         fi
1751     fi
1752
1753     if test "$BUILDTYPE" = spec ; then
1754         TOPDIR=`chroot $BUILD_ROOT su -c "rpm --eval '%_topdir'" - $BUILD_USER`
1755         if test -z "$TOPDIR"; then
1756             echo "Error: TOPDIR empty"
1757             cleanup_and_exit 1
1758         fi
1759     else
1760         TOPDIR=/usr/src/packages
1761         mkdir -p $BUILD_ROOT$TOPDIR
1762     fi
1763
1764     rm -f $BUILD_ROOT/.build.packages
1765     ln -s ${TOPDIR#/} $BUILD_ROOT/.build.packages
1766
1767     mount -n -tproc none $BUILD_ROOT/proc 2> /dev/null
1768     mount -n -tdevpts none $BUILD_ROOT/dev/pts 2> /dev/null
1769
1770     setupicecream
1771
1772     setupccache
1773
1774     # nasty hack to prevent rpath on known paths
1775     # FIXME: do this only for suse
1776     if test -d "$BUILD_ROOT/etc/profile.d" ; then
1777         echo "export SUSE_IGNORED_RPATHS=/etc/ld.so.conf" > "$BUILD_ROOT/etc/profile.d/buildsystem.sh"
1778     fi
1779
1780     #
1781     # now clean up RPM building directories
1782     #
1783     rm -rf $BUILD_ROOT$TOPDIR
1784     for i in BUILD RPMS/`uname -m` RPMS/i386 RPMS/noarch SOURCES SPECS SRPMS BUILDROOT OTHER ; do
1785         mkdir -p $BUILD_ROOT$TOPDIR/$i
1786     done
1787     chown -R "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT$TOPDIR"
1788     check_exit
1789
1790     mkdir -p $BUILD_ROOT$TOPDIR/SOURCES
1791     if test "$BUILDTYPE" = kiwi ; then
1792         mkdir -p $BUILD_ROOT$TOPDIR/KIWI
1793         if test "$MYSRCDIR" = $BUILD_ROOT/.build-srcdir ; then
1794             mv "$MYSRCDIR"/* $BUILD_ROOT$TOPDIR/SOURCES/
1795         else
1796             if test -z "$LINKSOURCES" ; then
1797                 cp -dLR "$MYSRCDIR"/* $BUILD_ROOT$TOPDIR/SOURCES/
1798             else
1799                 cp -lR "$MYSRCDIR"/* $BUILD_ROOT$TOPDIR/SOURCES/
1800             fi
1801             if test "$?" != 0 ; then
1802                 echo "source copy failed"
1803                 cleanup_and_exit 1
1804             fi
1805         fi
1806     else
1807         cp -p "$MYSRCDIR"/* $BUILD_ROOT$TOPDIR/SOURCES/
1808     fi
1809     # strip prefix from autogenerated files of source services.
1810     for i in $BUILD_ROOT$TOPDIR/SOURCES/_service\:*; do
1811       mv "$i" "${i%/*}/${i##*:}"
1812     done
1813     SPECFILE="${SPECFILE##*:}"
1814
1815     test "$MYSRCDIR" = $BUILD_ROOT/.build-srcdir && rm -rf "$MYSRCDIR"
1816     CHANGELOGARGS=
1817     test -n "$CHANGELOG" -a -f "$BUILD_ROOT/.build-changelog" && CHANGELOGARGS="--changelog $BUILD_ROOT/.build-changelog"
1818
1819     if test "$BUILDTYPE" = spec ; then
1820         # do buildrequires/release substitution
1821         args=()
1822         if test -n "$RELEASE"; then
1823                 args=(--release "$RELEASE")
1824         fi
1825         substitutedeps "${args[@]}" --root "$BUILD_ROOT" --dist "$BUILD_DIST" --archpath "$BUILD_ARCH" --configdir "$BUILD_DIR/configs" $CHANGELOGARGS "$BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE" "$BUILD_ROOT/.spec.new" || cleanup_and_exit 1
1826         # extract macros from configuration
1827         getmacros --dist "$BUILD_DIST" --archpath "$BUILD_ARCH" --configdir "$BUILD_DIR/configs" > $BUILD_ROOT/root/.rpmmacros
1828         if test -n "$BUILD_DEBUG" ; then
1829             echo '
1830 %prep %{?!_suse_insert_debug_package_seen:%?_suse_insert_debug_package}%%prep
1831 %package %{?!_suse_insert_debug_package_seen:%?_suse_insert_debug_package}%%package
1832 %suse_insert_debug_package \
1833   %global _suse_insert_debug_package \\\
1834     %%global _suse_insert_debug_package_seen 1 \\\
1835     %%debug_package
1836
1837 ' >> $BUILD_ROOT/root/.rpmmacros
1838         fi
1839
1840         if [ -n "$BUILD_JOBS" ]; then
1841                 cat >> $BUILD_ROOT/root/.rpmmacros <<-EOF
1842                 %jobs $BUILD_JOBS
1843                 %_smp_mflags -j$BUILD_JOBS
1844                 EOF
1845         fi
1846         test $BUILD_USER = abuild && cp -p $BUILD_ROOT/root/.rpmmacros $BUILD_ROOT/home/abuild/.rpmmacros
1847         # extract optflags from configuration
1848         getoptflags --dist "$BUILD_DIST" --configdir "$BUILD_DIR/configs" --archpath "$BUILD_ARCH" ${BUILD_DEBUG:+--debug} > $BUILD_ROOT/root/.rpmrc
1849         test $BUILD_USER = abuild && cp -p $BUILD_ROOT/root/.rpmrc $BUILD_ROOT/home/abuild/.rpmrc
1850         if test -z "$ABUILD_TARGET"; then
1851             ABUILD_TARGET=$(getchangetarget --dist "$BUILD_DIST" --configdir "$BUILD_DIR/configs" --archpath "$BUILD_ARCH" )
1852             test -z "$ABUILD_TARGET" || echo "build target is $ABUILD_TARGET"
1853         fi
1854     fi
1855     if test -f $BUILD_ROOT/.spec.new ; then
1856         if ! cmp -s $BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE $BUILD_ROOT/.spec.new ; then
1857             echo -----------------------------------------------------------------
1858             echo I have the following modifications for $SPECFILE:
1859             sed -e "/^%changelog/q" $BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE > $BUILD_ROOT/.spec.t1
1860             sed -e "/^%changelog/q" $BUILD_ROOT/.spec.new > $BUILD_ROOT/.spec.t2
1861             diff $BUILD_ROOT/.spec.t1 $BUILD_ROOT/.spec.t2
1862             rm -f $BUILD_ROOT/.spec.t1 $BUILD_ROOT/.spec.t2
1863             mv $BUILD_ROOT/.spec.new $BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE
1864         else
1865             rm -f $BUILD_ROOT/.spec.new
1866         fi
1867     fi
1868
1869     if test "$BUILDTYPE" = dsc ; then
1870         rm -rf $BUILD_ROOT$TOPDIR/BUILD
1871         mkdir -p $BUILD_ROOT$TOPDIR/SOURCES.DEB
1872         chown -R "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT$TOPDIR"
1873         DEB_TRANSFORM=
1874         DEB_SOURCEDIR=$TOPDIR/SOURCES
1875         DEB_DSCFILE=$SPECFILE
1876         for f in $BUILD_ROOT$TOPDIR/SOURCES/debian.* ; do
1877             test -f $f && DEB_TRANSFORM=true
1878         done
1879         if test -n "$DEB_TRANSFORM" ; then
1880             echo "running debian transformer..."
1881             if ! debtransform $CHANGELOGARGS $BUILD_ROOT$TOPDIR/SOURCES $BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE $BUILD_ROOT$TOPDIR/SOURCES.DEB ; then
1882                 echo "debian transforming failed."
1883                 cleanup_and_exit 1
1884             fi
1885             DEB_SOURCEDIR=$TOPDIR/SOURCES.DEB
1886             for DEB_DSCFILE in $BUILD_ROOT/$DEB_SOURCEDIR/*.dsc ; do : ; done
1887             DEB_DSCFILE="${DEB_DSCFILE##*/}"
1888         fi
1889         chroot $BUILD_ROOT su -c "dpkg-source -x $DEB_SOURCEDIR/$DEB_DSCFILE $TOPDIR/BUILD" - $BUILD_USER
1890     fi
1891
1892     chown -R "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT$TOPDIR"
1893     cd $BUILD_ROOT$TOPDIR/SOURCES || cleanup_and_exit 1
1894
1895     echo -----------------------------------------------------------------
1896     if test "$BUILD_USER" = root ; then
1897         echo ----- building $SPECFILE
1898     else
1899         echo ----- building $SPECFILE "(user $BUILD_USER)"
1900     fi
1901     echo -----------------------------------------------------------------
1902     echo -----------------------------------------------------------------
1903     if [ -n "$RUNNING_IN_VM" ]; then
1904         if [ -x /sbin/ip ]; then
1905             ip addr add 127.0.0.1/8 dev lo
1906             ip link set lo up
1907         else
1908             ifconfig lo 127.0.0.1 up
1909         fi
1910         if [ -n "$MYHOSTNAME" ]; then
1911             hostname "$MYHOSTNAME"
1912         fi
1913     fi
1914
1915     BUILD_SUCCEEDED=false
1916
1917     if test -n "$OVERLAY" ; then
1918         if test -d "$OVERLAY"; then
1919             pushd $OVERLAY
1920             echo "Copying overlay to BUILD_ROOT"
1921             tar -cpf - . | (cd $BUILD_ROOT ; tar -xvf -)
1922             popd
1923         else
1924             echo "OVERLAY ($OVERLAY) is no directory - skipping"
1925         fi
1926     fi
1927
1928     if test -n "$RSYNCSRC" ; then
1929         if test -n "$RSYNCDEST"; then
1930             if test -d "$RSYNCSRC"; then
1931                 if ! test -d "$BUILD_ROOT/$RSYNCDEST"; then
1932                     echo "ATTENTION! Creating target directory ($BUILD_ROOT/$RSYNCDEST) as its not there."
1933                     mkdir -p $BUILD_ROOT/$RSYNCDEST
1934                 fi
1935                 echo "Running rsync ..."
1936                 rsync -av $RSYNCSRC/* $BUILD_ROOT/$RSYNCDEST/
1937                 chown -R "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT/$RSYNCDEST"
1938                 RSYNCDONE=true
1939                 echo "... done"
1940             else
1941                 echo "RSYNCSRC is no directory - skipping"
1942             fi
1943         else
1944             echo "RSYNCSRC given, but not RSYNCDEST - skipping"
1945         fi
1946     fi
1947
1948     if test "$BUILDTYPE" = spec ; then
1949         test -z "$BUILD_RPM_BUILD_STAGE" && BUILD_RPM_BUILD_STAGE=-ba
1950
1951         # XXX: move _srcdefattr to macro file?
1952         rpmbopts=("$BUILD_RPM_BUILD_STAGE" "--define" "_srcdefattr (-,root,root)")
1953         if [ -n "$ABUILD_TARGET" ]; then
1954                 rpmbopts[${#rpmbopts[@]}]="--target=$ABUILD_TARGET"
1955         fi
1956         if [ -n "$DISTURL" ]; then
1957                 rpmbopts[${#rpmbopts[@]}]='--define'
1958                 rpmbopts[${#rpmbopts[@]}]="disturl $DISTURL"
1959         fi
1960         if test -s "$BUILD_ROOT/usr/lib/rpm/mandriva/macros" ; then
1961                 rpmbopts[${#rpmbopts[@]}]='--eval'
1962                 rpmbopts[${#rpmbopts[@]}]="%undefine _enable_debug_packages"
1963         fi
1964         if [ -n "$BUILD_DEBUG" ]; then
1965                 rpmbopts[${#rpmbopts[@]}]='--eval'
1966                 rpmbopts[${#rpmbopts[@]}]="%suse_insert_debug_package"
1967         fi
1968         if [ -n "$RSYNCDONE" ] ; then
1969                 rpmbopts[${#rpmbopts[@]}]='--define'
1970                 rpmbopts[${#rpmbopts[@]}]="RSYNCDONE 1"
1971         fi
1972
1973         rpmbuild=rpmbuild
1974
1975         test -x $BUILD_ROOT/usr/bin/rpmbuild || rpmbuild=rpm
1976         # su involves a shell which would require even more
1977         # complicated quoting to bypass than this
1978         toshellscript $rpmbuild \
1979                 "${definesnstuff[@]}" \
1980                 "${rpmbopts[@]}" \
1981                 "$TOPDIR/SOURCES/$SPECFILE" \
1982                 > $BUILD_ROOT/.build.command
1983         chmod 755 $BUILD_ROOT/.build.command
1984         check_exit
1985         if test -n "$shell"; then
1986             chroot $BUILD_ROOT su -
1987         else
1988             chroot $BUILD_ROOT su -c /.build.command - $BUILD_USER < /dev/null && BUILD_SUCCEEDED=true
1989         fi
1990     fi
1991
1992     if test "$BUILDTYPE" = dsc ; then
1993         # Checks to see if a build script should be used
1994         # this allows the build environment to be manipulated
1995         # and alternate build commands can be used
1996 # Debian policy requires to build with single CPU by default
1997 #       if [ -n "$BUILD_JOBS" ]; then
1998 #           DSC_BUILD_JOBS="-j$BUILD_JOBS"
1999 #       fi
2000         DSC_BUILD_CMD="dpkg-buildpackage -us -uc -rfakeroot-tcp $DSC_BUILD_JOBS"
2001         if test -e $BUILD_ROOT/$TOPDIR/SOURCES/build.script ; then
2002             echo "Sourcing build.script to build - it should normally run 'dpkg-buildpackage -us -uc -rfakeroot-tcp'"
2003             DSC_BUILD_CMD="source $TOPDIR/SOURCES/build.script"
2004             chmod +x $BUILD_ROOT/$TOPDIR/SOURCES/build.script
2005         fi
2006
2007         if test -n "$shell"; then
2008             chroot $BUILD_ROOT su -
2009         else
2010             chroot $BUILD_ROOT su -c "cd $TOPDIR/BUILD && $DSC_BUILD_CMD" - $BUILD_USER < /dev/null && BUILD_SUCCEEDED=true
2011         fi
2012
2013         mkdir -p $BUILD_ROOT/$TOPDIR/DEBS
2014         for DEB in $BUILD_ROOT/$TOPDIR/*.deb ; do
2015             test -e "$DEB" && mv "$DEB" "$BUILD_ROOT/$TOPDIR/DEBS"
2016         done
2017         # link sources over
2018         ln $BUILD_ROOT/$DEB_SOURCEDIR/$DEB_DSCFILE $BUILD_ROOT/$TOPDIR/DEBS/
2019         while read f ; do
2020             ln $BUILD_ROOT/$DEB_SOURCEDIR/$f $BUILD_ROOT/$TOPDIR/DEBS/
2021         done < <(sed -ne '/^Files:/,$s/^ ................................ [0-9][0-9]* //p' < $BUILD_ROOT/$DEB_SOURCEDIR/$DEB_DSCFILE)
2022     fi
2023
2024     if test "$BUILDTYPE" = kiwi ; then
2025         . $BUILD_DIR/build_kiwi.sh
2026         run_kiwi
2027     fi
2028
2029     test "$BUILD_SUCCEEDED" = true || cleanup_and_exit 1
2030     test -d "$SRCDIR" && cd "$SRCDIR"
2031 done
2032
2033 RPMS=`find $BUILD_ROOT/$TOPDIR/RPMS -type f -name "*.rpm" 2>/dev/null || true`
2034 DEBS=`find $BUILD_ROOT/$TOPDIR/DEBS -type f -name "*.deb" 2>/dev/null || true`
2035
2036 if test -n "$RPMS" -a -n "$BUILD_USER_ABUILD_USED" ; then
2037     echo "... checking for files with abuild user/group"
2038     BADFILE=
2039     while read un gn fn ; do
2040         if test "$un" = abuild -o "$gn" = abuild -o "$un" = ${ABUILD_UID} -o "$gn" = ${ABUILD_GID} ; then
2041             echo "  $un $gn $fn"
2042             BADFILE=true
2043         fi
2044     done < <(rpm -qp --qf '[%{FILEUSERNAME} %{FILEGROUPNAME} %{FILENAMES}\n]' $RPMS)
2045     if test -n "$BADFILE" ; then
2046         echo "please fix your filelist (e.g. add defattr)"
2047         cleanup_and_exit 1
2048     fi
2049 fi
2050
2051 if test -n "$RPMS" -a -d "$BUILD_ROOT/usr/lib/build/checks" ; then
2052     export PNAME=""
2053     export DO_RPM_REMOVE=true
2054     for SRPM in $BUILD_ROOT/$TOPDIR/SRPMS/*src.rpm ; do
2055         test -f "$SRPM" && PNAME=`rpm --nodigest --nosignature -qp --qf "%{NAME}" $SRPM`
2056     done
2057     for CHECKSCRIPT in $BUILD_ROOT/usr/lib/build/checks/* ; do
2058         echo "... running `basename $CHECKSCRIPT`"
2059         $CHECKSCRIPT || cleanup_and_exit 1
2060     done
2061 fi
2062
2063 if test -n "$RPMS" -a "$DO_CHECKS" != "false" -a -x "$BUILD_ROOT/opt/testing/bin/rpmlint" ; then
2064     LINT_RPM_FILE_LIST=($(find $BUILD_ROOT/$TOPDIR/RPMS \
2065         \( -name "*-debuginfo-*" -o -name "*-debugsource-*" \
2066         -o -name "*-32bit-*" -o -name "*-64bit-*" \
2067         -o -name "*-x86-*" -o -name "*-ia32-*" \) -prune \
2068         -o -type f -name '*.rpm' -print))
2069     SRPM_FILE_LIST=($(find $BUILD_ROOT/$TOPDIR/SRPMS -type f -name "*.rpm"))
2070     echo
2071     echo "RPMLINT report:"
2072     echo "==============="
2073     rpmlint_logfile=$TOPDIR/OTHER/rpmlint.log
2074     rm -f "$BUILD_ROOT$rpmlint_logfile"
2075     ret=0
2076     chroot $BUILD_ROOT su -s /opt/testing/bin/rpmlint "$BUILD_USER" -- \
2077             --info ${LINT_RPM_FILE_LIST[*]#$BUILD_ROOT} \
2078             ${SRPM_FILE_LIST[*]#$BUILD_ROOT} > "$BUILD_ROOT$rpmlint_logfile" || ret=1
2079             cat "$BUILD_ROOT$rpmlint_logfile"
2080             echo
2081     if test "$ret" = 1; then
2082         cleanup_and_exit 1
2083     fi
2084 fi
2085
2086 if test \( -n "$RPMS" -o -n "$DEBS" \) -a -n "$CREATE_BASELIBS"; then
2087     create_baselibs
2088 fi
2089
2090 exitcode=0
2091 # post build scripts
2092 # TODO: don't hardcode. instead run scripts in a directory as it's done for the checks
2093 if test -n "$RPMS" \
2094         -a -d "$BUILD_ROOT/$TOPDIR/RPMS" \
2095         -a -d "$BUILD_ROOT/.build.oldpackages" \
2096         ; then
2097     if test -x "$BUILD_ROOT/usr/lib/build/same-build-result.sh" ; then
2098         echo "... comparing built packages with the former built"
2099         mount -n -tproc none $BUILD_ROOT/proc 2> /dev/null
2100         if chroot $BUILD_ROOT /usr/lib/build/same-build-result.sh /.build.oldpackages "$TOPDIR/RPMS" "$TOPDIR/SRPMS"; then
2101             chroot $BUILD_ROOT touch /.build/.same_result_marker
2102             # XXX: dirty build service hack. fix bs_worker. Search for
2103             # 'same_result_marker' for traces of a first try to get rid of this
2104             if test -n "$REASON" -a -n "$DISTURL"; then
2105                 exitcode=2
2106             fi
2107         fi
2108     fi
2109     if test ! -e $BUILD_ROOT/.build/.same_result_marker \
2110         -a -x "$BUILD_ROOT/usr/bin/makedeltarpm" \
2111         -a -x $BUILD_ROOT/usr/lib/build/mkdrpms; then
2112         echo "... creating delta rpms"
2113         ds=("$BUILD_ROOT/$TOPDIR"/RPMS/* "$BUILD_ROOT$TOPDIR/SRPMS")
2114         chroot $BUILD_ROOT /usr/lib/build/mkdrpms /.build.oldpackages "${ds[@]#$BUILD_ROOT}"
2115     fi
2116 fi
2117
2118 if test -n "$RUNNING_IN_VM" -a -n "$VM_SWAP"; then
2119     echo "... saving built packages"
2120     swapoff "$VM_SWAP"
2121     args="--padstart 512 --padend 512 -v"
2122     case "$BUILDTYPE" in
2123         spec)
2124             computeblocklists $args $TOPDIR/RPMS/*/*.{d,}rpm $TOPDIR/SRPMS/* $TOPDIR/OTHER/* > "$VM_SWAP"
2125             ;;
2126         dsc)
2127             computeblocklists $args $TOPDIR/DEBS/*.deb $TOPDIR/SOURCES.DEB/* $TOPDIR/OTHER/* > "$VM_SWAP"
2128             ;;
2129         kiwi)
2130             computeblocklists $args $TOPDIR/KIWI/* $TOPDIR/OTHER/* > "$VM_SWAP"
2131             ;;
2132     esac || cleanup_and_exit 1
2133 fi
2134
2135 echo
2136 echo "$HOST finished \"build $SPECFILE\" at `date --utc`."
2137 echo
2138
2139 cleanup_and_exit "$exitcode"