- use bsdtar if possible
[opensuse:build.git] / init_buildsystem
1 #!/bin/bash
2 # Script to create a complete system to build packages in a chroot
3 # environment.  This script ensures, that all packages given as
4 # parameter are installed. All other packges will be deleted.
5 #
6 # BUILD_ROOT  here the packages will be installed/deleted
7 # BUILD_RPMS  here we get our packages to install
8 # BUILD_ARCH  path of the architectures we try
9 #
10 # (c) 1997-2005 SuSE GmbH Nuernberg, Germany
11
12 #
13 # needed globals variables
14 #
15 export SRC
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
21 browner=0
22 definesnstuff=()
23 repos=()
24
25 . $BUILD_DIR/common_functions || exit 1
26
27 # should RPMs be installed with --force ?
28 USE_FORCE=false
29
30 BUILD_IS_RUNNING=$BUILD_ROOT/not-ready
31 TMPFILE=$BUILD_ROOT/tmpfile
32 #buildhost removed so that id can be generated from repo files
33 #RPMIDFMT="%{NAME}-%{VERSION}-%{RELEASE} %{BUILDHOST}-%{BUILDTIME}\n"
34 RPMIDFMT="%{NAME}-%{VERSION}-%{RELEASE} %{BUILDTIME}\n"
35
36 PREPARE_VM=
37 USEUSEDFORBUILD=
38 LIST_STATE=
39 RPMLIST=
40 CLEAN_BUILD=
41 CREATE_BUILD_BINARIES=
42
43 while test -n "$1" ; do
44     case "$1" in
45         --prepare)
46             shift
47             PREPARE_VM=true
48             ;;
49         --create-build-binaries)
50             shift
51             CREATE_BUILD_BINARIES=true
52             ;;
53         --useusedforbuild)
54             shift
55             USEUSEDFORBUILD=--useusedforbuild
56             ;;
57         --list-state)
58             shift
59             LIST_STATE=true
60             ;;
61         --rpmlist)
62             shift
63             RPMLIST=$1
64             shift
65             ;;
66         --define|--with|--without)
67             definesnstuff[${#definesnstuff[@]}]="$1";
68             definesnstuff[${#definesnstuff[@]}]="$2";
69             shift 2
70             ;;
71         --repository|--repo)
72             repos[${#repos[@]}]="$2";
73             shift 2;
74             ;;
75         --clean)
76             CLEAN_BUILD="$1"
77             shift
78         ;;
79         --cachedir)
80             CACHE_DIR="$2"
81             shift 2
82             ;;
83         *)
84             break
85             ;;
86     esac
87 done
88 PKGS=("$@")
89
90 #
91 # needed functions
92 #
93
94 cleanup_and_exit()
95 {
96     trap EXIT
97     [ "$BUILD_ROOT" != / ] || chown $browner $BUILD_ROOT
98     # umount so init_buildsystem can be used standalone
99 # XXX: use stat -f /dev/pts/ -c %T  to check whether it's mounted and not suppress errors then?
100     umount -n $BUILD_ROOT/proc/sys/fs/binfmt_misc 2> /dev/null || true
101     umount -n $BUILD_ROOT/proc 2> /dev/null || true
102     umount -n $BUILD_ROOT/dev/pts 2> /dev/null || true
103     umount -n $BUILD_ROOT/mnt 2> /dev/null || true
104     exit ${1:-0}
105 }
106
107 clean_build_root()
108 {
109         test -n "$BUILD_ROOT" && {
110             umount -n $BUILD_ROOT/proc/sys/fs/binfmt_misc 2> /dev/null || true
111             umount -n $BUILD_ROOT/proc 2> /dev/null || true
112             umount -n $BUILD_ROOT/dev/pts 2> /dev/null || true
113             umount -n $BUILD_ROOT/mnt 2> /dev/null || true
114             rm -rf -- $BUILD_ROOT/*
115             rm -rf -- $BUILD_ROOT/.build
116             rm -rf -- $BUILD_ROOT/.root
117             rm -rf -- $BUILD_ROOT/.init_b_cache
118             mkdir -p $BUILD_ROOT/proc
119             mkdir -p $BUILD_ROOT/dev/pts
120             if [ "$UID" = '0' ]; then
121                     mount -n -tproc none $BUILD_ROOT/proc
122                     mount -n -tdevpts none $BUILD_ROOT/dev/pts
123             fi
124         }
125 }
126
127 preinstall()
128 {
129     check_exit
130     echo "preinstalling $1..."
131     cd $BUILD_ROOT || cleanup_and_exit 1
132     if test -x /usr/bin/bsdtar ; then
133         CPIO="/usr/bin/bsdtar --chroot -x -f-"
134         TAR="/usr/bin/bsdtar --chroot -x"
135     else
136         CPIO="cpio --extract --unconditional --preserve-modification-time --make-directories --no-absolute-filenames --quiet"
137         TAR="tar -x"
138     fi
139     if test -e "$BUILD_ROOT/.init_b_cache/rpms/$1.rpm" ; then
140         PAYLOADDECOMPRESS=cat
141         case `rpm -qp --nodigest --nosignature --qf "%{PAYLOADCOMPRESSOR}\n" "$BUILD_ROOT/.init_b_cache/rpms/$1.rpm"` in
142             lzma) rpm --showrc | grep PayloadIsLzma > /dev/null || PAYLOADDECOMPRESS="lzma -d" ;;
143             xz) rpm --showrc | grep PayloadIsXz > /dev/null || PAYLOADDECOMPRESS="xz -d" ;;
144         esac
145         if test "$PAYLOADDECOMPRESS" = "lzma -d" ; then
146             if ! lzma </dev/null >/dev/null 2>&1 ; then
147                 test -f "$BUILD_DIR/lzmadec.sh" && PAYLOADDECOMPRESS="bash $BUILD_DIR/lzmadec.sh"
148             fi
149         fi
150         if test "$PAYLOADDECOMPRESS" = "xz -d" ; then
151             if ! xz </dev/null >/dev/null 2>&1 ; then
152                 test -f "$BUILD_DIR/xzdec.sh" && PAYLOADDECOMPRESS="bash $BUILD_DIR/xzdec.sh"
153             fi
154         fi
155         if test "$PAYLOADDECOMPRESS" = cat ; then
156             rpm2cpio "$BUILD_ROOT/.init_b_cache/rpms/$1.rpm" | $CPIO
157         else
158             rpm2cpio "$BUILD_ROOT/.init_b_cache/rpms/$1.rpm" | $PAYLOADDECOMPRESS | $CPIO
159         fi
160         if test -e ".init_b_cache/scripts/$1.run" ; then
161             rpm -qp --nodigest --nosignature --qf "%{PREIN}" "$BUILD_ROOT/.init_b_cache/rpms/$1.rpm" > ".init_b_cache/scripts/$1.pre"
162             rpm -qp --nodigest --nosignature --qf "%{POSTIN}" "$BUILD_ROOT/.init_b_cache/rpms/$1.rpm" > ".init_b_cache/scripts/$1.post"
163             echo -n '(none)' > .init_b_cache/scripts/.none
164             cmp -s ".init_b_cache/scripts/$1.pre" .init_b_cache/scripts/.none && rm -f ".init_b_cache/scripts/$1.pre"
165             cmp -s ".init_b_cache/scripts/$1.post" .init_b_cache/scripts/.none && rm -f ".init_b_cache/scripts/$1.post"
166             rm -f .init_b_cache/scripts/.none
167         fi
168     elif test -e "$BUILD_ROOT/.init_b_cache/rpms/$1.deb" ; then
169         ar x "$BUILD_ROOT/.init_b_cache/rpms/$1.deb" control.tar.gz data.tar.gz
170         mkdir -p .init_b_cache/scripts/control
171         $TAR -C .init_b_cache/scripts/control -z -f control.tar.gz
172         $TAR -z -f data.tar.gz
173         if test -e ".init_b_cache/scripts/$1.run" ; then
174             test -e .init_b_cache/scripts/control/preinst && mv .init_b_cache/scripts/control/preinst ".init_b_cache/scripts/$1.pre"
175             test -e .init_b_cache/scripts/control/postinst && mv .init_b_cache/scripts/control/postinst ".init_b_cache/scripts/$1.post"
176         fi
177         rm -rf .init_b_cache/scripts/control control.tar.gz data.tar.gz
178     else
179         echo "warning: package $1 does not exist"
180     fi
181 }
182
183 run_pkg_scripts()
184 {
185     chroot $BUILD_ROOT /sbin/ldconfig 2>/dev/null
186     for PKG in $PACKAGES_TO_RUNSCRIPTS ; do
187         if test -e "$BUILD_ROOT/.init_b_cache/scripts/$PKG.pre" ; then
188             echo "running $PKG preinstall script"
189             if test -e "$BUILD_ROOT/.init_b_cache/rpms/$PKG.rpm" ; then
190                 chroot $BUILD_ROOT sh ".init_b_cache/scripts/$PKG.pre" 0
191             else
192                 chroot $BUILD_ROOT ".init_b_cache/scripts/$PKG.pre" install < /dev/null
193             fi
194             rm -f "$BUILD_ROOT/.init_b_cache/scripts/$PKG.pre"
195         fi
196         if test -e "$BUILD_ROOT/.init_b_cache/scripts/$PKG.post" ; then
197             echo "running $PKG postinstall script"
198             if test -e "$BUILD_ROOT/.init_b_cache/rpms/$PKG.rpm" ; then
199                 chroot $BUILD_ROOT sh ".init_b_cache/scripts/$PKG.post" 1
200             else
201                 chroot $BUILD_ROOT ".init_b_cache/scripts/$PKG.post" configure '' < /dev/null
202             fi
203             rm -f "$BUILD_ROOT/.init_b_cache/scripts/$PKG.post"
204         fi
205         check_exit
206     done
207 }
208
209 init_db()
210 {
211     if test $PSUF = rpm ; then
212         echo initializing rpm db...
213         chroot $BUILD_ROOT rpm --initdb || cleanup_and_exit 1
214         # hack: add nofsync to db config to speed up install
215         mkdir -p $BUILD_ROOT/root
216         echo '%__dbi_perms perms=0644 nofsync' > $BUILD_ROOT/.rpmmacros
217         echo '%__dbi_perms perms=0644 nofsync' > $BUILD_ROOT/root/.rpmmacros
218     else
219         # force dpkg into database to make epoch test work
220         if ! test "$BUILD_ROOT/.init_b_cache/rpms/dpkg.deb" -ef "$BUILD_ROOT/.init_b_cache/dpkg.deb" ; then
221             rm -f $BUILD_ROOT/.init_b_cache/dpkg.deb
222             cp $BUILD_ROOT/.init_b_cache/rpms/dpkg.deb $BUILD_ROOT/.init_b_cache/dpkg.deb || cleanup_and_exit 1
223         fi
224         chroot $BUILD_ROOT dpkg -i --force all .init_b_cache/dpkg.deb >/dev/null 2>&1
225     fi
226 }
227
228 reorder()
229 {
230     test -z "$*" && return
231     rm -f $BUILD_ROOT/.init_b_cache/order.manifest
232     for PKG in "$@" ; do
233         echo "$PKG" >> $BUILD_ROOT/.init_b_cache/order.manifest
234     done
235     $BUILD_DIR/order --dist "$BUILD_DIST" --archpath "$BUILD_ARCH" --configdir $BUILD_DIR/configs --manifest $BUILD_ROOT/.init_b_cache/order.manifest $BUILD_ROOT/.init_b_cache/rpms
236     rm -f $BUILD_ROOT/.init_b_cache/order.manifest
237 }
238
239 create_devs()
240 {
241     local com file mode arg
242
243     mkdir -m 755 -p $BUILD_ROOT/dev/pts
244     test -f $BUILD_ROOT/dev/shm && rm -f $BUILD_ROOT/dev/shm
245     mkdir -m 755 -p $BUILD_ROOT/dev/shm
246     while read com file mode arg ; do
247         rm -f $BUILD_ROOT/dev/$file
248         if test $com = ln ; then
249             ln -s $arg $BUILD_ROOT/dev/$file
250             continue
251         fi
252         $com -m $mode $BUILD_ROOT/dev/$file $arg
253     done << DEVLIST
254         mknod null    666 c 1 3
255         mknod zero    666 c 1 5
256         mknod full    622 c 1 7
257         mknod random  666 c 1 8
258         mknod urandom 644 c 1 9
259         mknod tty     666 c 5 0
260         mknod ptmx    666 c 5 2
261         mknod loop0   640 b 7 0
262         mknod loop1   640 b 7 1
263         mknod loop2   640 b 7 2
264         mknod loop3   640 b 7 3
265         ln    fd      777 /proc/self/fd
266         ln    stdin   777 fd/0
267         ln    stdout  777 fd/1
268         ln    stderr  777 fd/2
269 DEVLIST
270 }
271
272 # check whether the repo list contains a plain "zypp://". Add all
273 # enabled zypp repos in this case
274 maybe_add_all_zypp_repos()
275 {
276     local i j
277     r=()
278     for i in "${repos[@]}"; do
279         if [ "$i" = "zypp://" ]; then
280             while read j; do
281                 j="${j#/etc/zypp/repos.d/}"
282                 r=("${r[@]}" "zypp://${j%.repo}")
283             done < <(grep -l enabled=1 /etc/zypp/repos.d/*.repo)
284         else
285             r=("${r[@]}" "$i")
286         fi
287     done
288     repos=("${r[@]}")
289 }
290
291 validate_cache_file()
292 {
293     local findonly=''
294     maybe_add_all_zypp_repos
295     if ! test -f $CACHE_FILE || ! test -f $CACHE_FILE.id || \
296         test "${repos[*]} ${BUILD_RPMS//:/ /}" != "$(cat $CACHE_FILE.id 2>/dev/null)"; then
297         rm -f $CACHE_FILE.id
298     else
299         for SRC in "${repos[@]}" ${BUILD_RPMS//:/ /}; do
300             test -n "$SRC" || SRC=.
301             if [ "${SRC#zypp://}" != "$SRC" ]; then
302                 SRC="/var/cache/zypp/raw" # XXX can't use name here as we'd need to parse the file
303             fi
304             if test "$SRC" -nt $CACHE_FILE; then
305                 rm -f $CACHE_FILE.id
306                 break
307             fi
308         done
309     fi
310     if ! test -f $CACHE_FILE.id ; then
311         test -z "$LIST_STATE" && echo initializing $CACHE_FILE ...
312         for SRC in "${repos[@]}" -- ${BUILD_RPMS//:/ /}; do
313             if test "$SRC" = '--' ; then
314                 findonly=1
315                 continue
316             fi
317             test -z "$SRC" && SRC=`pwd`
318             if [ "${SRC#zypp://}" != "$SRC" ]; then
319                 set -- $BUILD_DIR/createrepomddeps "$SRC"
320             elif [ "${SRC#http://}" != "$SRC" -o "${SRC#https://}" != "$SRC" -o "${SRC#ftp://}" != "$SRC" -o "${SRC#ftps://}" != "$SRC" ]; then
321                 mkdir -p "$(getcachedir "$SRC")"
322                 set -- $BUILD_DIR/createrepomddeps --cachedir="$CACHE_DIR" "$SRC"
323             elif [ ! -e "$SRC" ]; then
324                 echo "*** $SRC does not exist" >&2
325                 cleanup_and_exit 1
326             elif [ -z "$findonly" -a -e "$SRC"/suse/setup/descr/packages -o -e "$SRC"/suse/setup/descr/packages.gz ]; then
327                 set -- $BUILD_DIR/createyastdeps "$SRC"
328             elif [ -z "$findonly" -a -e "$SRC"/repodata/repomd.xml ]; then
329                 set -- $BUILD_DIR/createrepomddeps "$SRC"
330             else
331                 set -- $BUILD_DIR/createrpmdeps "$SRC"
332             fi
333             echo "$@" >&2
334             "$@" || cleanup_and_exit 1
335             echo D:
336         done > $CACHE_FILE.new
337
338         mv $CACHE_FILE.new $CACHE_FILE
339         echo "${repos[*]} ${BUILD_RPMS//:/ /}" > $CACHE_FILE.id
340     fi
341 }
342
343 #
344 # Detect cross-build (fixed code) and copy qemus for cross-build emulation mode
345 # And copy also a static host binary shell to run the init scripts in the target chroot
346 #
347 copy_qemu()
348 {
349     echo "copying qemu"
350     mkdir -p  $BUILD_ROOT/usr/bin $BUILD_ROOT/usr/sbin
351     install -m755 /usr/bin/qemu-* $BUILD_ROOT/usr/bin
352     install -m755 /usr/sbin/qemu-binfmt-conf.sh $BUILD_ROOT/usr/sbin
353     # To initially run the init script, there needs to be also a
354     # static bash to register qemu in this chroot and to start up
355     # /.build/build
356     if [ -n "$PREPARE_VM" ]; then
357         mkdir -p  $BUILD_ROOT/bin
358         install -m755 /bin/bash-static $BUILD_ROOT/bin
359         install -m755 /bin/mount-static $BUILD_ROOT/bin
360     fi
361 }
362
363 check_binfmt_registered()
364 {
365     local arch
366     for arch in arm $EMULATOR_ARCHS; do
367         if test -e /proc/sys/fs/binfmt_misc/$arch; then
368             return 0
369         fi
370     done
371     return 1
372 }
373
374 fail_exit()
375 {
376   cleanup_and_exit 1
377 }
378
379 # modify $SRC
380 downloadpkg()
381 {
382     local url="$1"
383     local cachedir
384
385     if [ "${url:0:7}" == "zypp://" ] ; then
386         cachedir="/var/cache/zypp/packages/"
387         SRC="$cachedir${url#zypp://}"
388         mkdir -p "${SRC%/*}" || cleanup_and_exit 1
389     elif [ "${url:0:7}" == "http://" -o "${url:0:8}" == "https://" -o "${url:0:6}" == "ftp://" -o "${url:0:7}" == "ftps://" ] ; then
390         cachedir="$(getcachedir "$url")"
391         local name="$(basename "$url")"
392         SRC="$cachedir/$name"
393     else
394         echo "Invalid url: $url"
395         cleanup_and_exit 1
396     fi
397
398     if [ ! -e "$SRC" ]; then
399         local destdir="$cachedir/tmp"
400         mkdir -p "$destdir"
401         echo "downloading $url ... ";
402         $BUILD_DIR/download "$destdir" "$url" || cleanup_and_exit 1
403         local destfile="$destdir/${url##*/}"
404         if [ ! -e "$destfile" ]; then
405             echo "expected $destfile after download but it's missing" >&2
406             cleanup_and_exit 1
407         fi
408         rpm -K "$destfile" > $destfile.v || { echo "rpm verify failed" >&2; rm -rf "$destdir"; cleanup_and_exit 1; }
409         if grep "NOT OK" $destfile.v; then
410             rm -rf "$destdir"
411             cleanup_and_exit 1
412         fi
413         rm -f "$destfile.v"
414         mv "$destfile" "$SRC" || cleanup_and_exit 1
415     fi
416 }
417
418 getcachedir()
419 {
420     url=$1
421     for repo in "${repos[@]}" ; do
422         if [ "${url:0:${#repo}}" == "$repo" ] ; then
423             read repoid dummy < <(echo -n "$repo" | md5sum)
424             echo "$CACHE_DIR/$repoid"
425             break
426         fi
427     done
428 }
429
430 get_pkg_filename()
431 {
432     local url="$1"
433     local name=$(basename $url)
434     local cachedir=$(getcachedir $url)
435     local destfile="$cachedir/$name"
436     echo $destfile
437 }
438
439 set_build_arch
440
441 trap fail_exit EXIT
442
443 if [ "$BUILD_ROOT" = / ]; then
444     read dummy dummy browner dummy < <(ls -ld /)
445 fi
446
447 if [ -n "$CLEAN_BUILD" ]; then
448     clean_build_root
449 fi
450
451 #
452 # now test if there was an incomplete run
453 #
454 if test -e $BUILD_IS_RUNNING ; then
455     echo It seems that there was an incomplete setup of $BUILD_ROOT.
456     echo To be sure, we will build it again completely...
457     umount -n $BUILD_ROOT/proc/sys/fs/binfmt_misc 2> /dev/null || true
458     umount -n $BUILD_ROOT/proc 2> /dev/null
459     umount -n $BUILD_ROOT/dev/pts 2> /dev/null
460     umount -n $BUILD_ROOT/mnt 2> /dev/null
461     echo "Your build system is broken!! Shall I execute"
462     echo
463     echo "    rm -rf -- $BUILD_ROOT/*"
464     echo
465     echo "y - yes, cleanup the build root"
466     echo "N - No, abort build (default on enter)"
467     echo "c - Continue anyway with this build root"
468     echo -n "[y/N/c] "
469     read ANSWER
470     case "$ANSWER" in
471         c|C) rm -f $BUILD_IS_RUNNING ;;
472         y|Y) clean_build_root ;;
473         *) cleanup_and_exit 1 ;;
474     esac
475 fi
476
477 #
478 # store that we start to build system
479 #
480 mkdir -p $BUILD_ROOT
481 touch $BUILD_IS_RUNNING
482
483 if test -n "$PREPARE_VM" ; then
484     rm -f $BUILD_ROOT/.build/init_buildsystem.data
485 fi
486 if test -e $BUILD_ROOT/.build/init_buildsystem.data ; then
487     # vm continuation
488     . $BUILD_ROOT/.build/init_buildsystem.data
489     if ! test -e $BUILD_ROOT/.init_b_cache/preinstall_finished ; then
490         # finish preinstall
491         run_pkg_scripts
492         init_db
493         touch $BUILD_ROOT/.init_b_cache/preinstall_finished
494     fi
495 else
496     #
497     # now make sure that all the packages are installed.
498     #
499     rm -rf $BUILD_ROOT/.init_b_cache
500     mkdir -p $BUILD_ROOT/.init_b_cache/scripts
501
502     if test -z "$RPMLIST" ; then
503         #
504         # create rpmdeps file
505         #
506         CACHE_FILE=$BUILD_ROOT/.srcfiles.cache
507         validate_cache_file
508
509         #
510         # select and expand packages
511         #
512         RPMLIST=$BUILD_ROOT/.init_b_cache/rpmlist
513         test -z "$LIST_STATE" && echo "expanding package dependencies..."
514         if ! $BUILD_DIR/expanddeps $USEUSEDFORBUILD "${definesnstuff[@]}" --dist "$BUILD_DIST" --depfile "$CACHE_FILE" --archpath "$BUILD_ARCH" --configdir $BUILD_DIR/configs "${PKGS[@]}" > $RPMLIST ; then
515             rm -f $BUILD_IS_RUNNING
516             cleanup_and_exit 1
517         fi
518     fi
519
520     if test -n "$LIST_STATE" ; then
521         rm -f $BUILD_IS_RUNNING
522         while read PKG SRC ; do
523            test "$PKG" = "preinstall:" && continue
524            test "$PKG" = "runscripts:" && continue
525            test "$PKG" = "cbpreinstall:" && continue
526            test "$PKG" = "vminstall:" && continue
527            test "$PKG" = "dist:" && continue
528            test "$PKG" = "rpmid:" && continue
529            echo "${SRC##*/}"
530         done < $BUILD_ROOT/.init_b_cache/rpmlist
531         rm -rf $BUILD_ROOT/.init_b_cache
532         cleanup_and_exit 0
533     fi
534
535     #
536     # copy the QEMU emulator
537     #
538     if check_use_emulator; then
539         copy_qemu
540         if [ -z "$PREPARE_VM" ]; then
541             if ! check_binfmt_registered; then
542                 echo "registering binfmt handlers"
543                 /usr/sbin/qemu-binfmt-conf.sh
544             fi
545             read mmap_min_addr < /proc/sys/vm/mmap_min_addr
546             if [ "$mmap_min_addr" != 0 ]; then
547                 echo "Warning: mmap_min_addr is != 0. If programs fail at mmap this could be the reason"
548             fi
549         fi
550     fi
551
552     PACKAGES_TO_INSTALL=
553     PACKAGES_TO_PREINSTALL=
554     PACKAGES_TO_RUNSCRIPTS=
555     PACKAGES_TO_VMINSTALL=
556     PACKAGES_TO_CBPREINSTALL=
557     PACKAGES_TO_CBINSTALL=
558     RUNSCRIPTS_SEEN=
559     GUESSED_DIST=unknown
560     mkdir -p $BUILD_ROOT/.init_b_cache/rpms
561     while read PKG SRC ; do
562         if test "$PKG" = "preinstall:" ; then
563             PACKAGES_TO_PREINSTALL=$SRC
564             continue
565         fi
566         if test "$PKG" = "vminstall:" ; then
567             PACKAGES_TO_VMINSTALL=$SRC
568             continue
569         fi
570         # these additional preinstall / install values are only set for 
571         # emulated "CrossBuild" setups - thus CB(pre)install
572         if test "$PKG" = "cbpreinstall:" ; then
573             if is_emulator_arch ; then
574                 PACKAGES_TO_CBPREINSTALL=$SRC
575             fi
576             continue
577         fi
578         if test "$PKG" = "cbinstall:" ; then
579             if is_emulator_arch ; then
580                 PACKAGES_TO_CBINSTALL=$SRC
581             fi
582             continue
583         fi
584         if test "$PKG" = "runscripts:" ; then
585             RUNSCRIPTS_SEEN=true
586             PACKAGES_TO_RUNSCRIPTS=$SRC
587             continue
588         fi
589         if test "$PKG" = "dist:" ; then
590             GUESSED_DIST=$SRC
591             continue
592         fi
593         if test "$PKG" = "rpmid:" ; then
594             echo "${SRC#*:}" > $BUILD_ROOT/.init_b_cache/rpms/${SRC%%:*}.id
595             continue
596         fi
597         if test "$PKG" != "${PKG%:}"; then
598             echo "Warning: ignoring unsupported tag '$PKG'" >&2
599             continue
600         fi
601         if [ "${SRC#/}" = "$SRC" ]; then
602             url="$SRC"
603             case "$url" in
604                 zypp://* | http://* | https://* | ftp://* | ftps://*)
605                     downloadpkg "$url"
606                     ;;
607                 *)
608                     echo "unsupported url for '$PKG': $url" >&2
609                     cleanup_and_exit 1
610                     ;;
611             esac
612         fi
613         # downloadpkg modified $SRC, so it has a right name for use
614         ln -s "$SRC" "$BUILD_ROOT/.init_b_cache/rpms/$PKG.${SRC##*.}"
615         PACKAGES_TO_INSTALL="$PACKAGES_TO_INSTALL $PKG"
616     done < $RPMLIST
617
618     test -n "$PACKAGES_TO_CBPREINSTALL" && echo "cbpreinstall: $PACKAGES_TO_CBPREINSTALL"
619     test -n "$PACKAGES_TO_CBINSTALL" && echo "cbinstall   : $PACKAGES_TO_CBINSTALL"
620     # compatibility...
621     test -z "$RUNSCRIPTS_SEEN" && PACKAGES_TO_RUNSCRIPTS="$PACKAGES_TO_PREINSTALL"
622
623     echo "$GUESSED_DIST" > $BUILD_ROOT/.guessed_dist
624     test -n "$BUILD_DIST" || BUILD_DIST="$GUESSED_DIST"
625     PSUF=rpm
626     test -L $BUILD_ROOT/.init_b_cache/rpms/rpm.rpm || PSUF=deb
627 fi
628
629 #
630 # now test if there is already a build dir.
631 #
632 if test ! -f $BUILD_ROOT/var/lib/rpm/packages.rpm -a ! -f $BUILD_ROOT/var/lib/rpm/Packages ; then
633     mkdir -p $BUILD_ROOT/var/lib/rpm || cleanup_and_exit 1
634     mkdir -p $BUILD_ROOT/usr/src/packages/SOURCES || cleanup_and_exit 1
635     mkdir -p $BUILD_ROOT/etc || cleanup_and_exit 1
636     mkdir -p $BUILD_ROOT/proc || cleanup_and_exit 1
637     test -f $BUILD_ROOT/etc/HOSTNAME || hostname -f > $BUILD_ROOT/etc/HOSTNAME
638     if test $PSUF = deb ; then
639         mkdir -p $BUILD_ROOT/var/lib/dpkg
640         mkdir -p $BUILD_ROOT/var/log
641         mkdir -p $BUILD_ROOT/etc/default
642         :> $BUILD_ROOT/var/lib/dpkg/status
643         :> $BUILD_ROOT/var/lib/dpkg/available
644         :> $BUILD_ROOT/var/log/dpkg.log
645         :> $BUILD_ROOT/etc/ld.so.conf
646         :> $BUILD_ROOT/etc/default/rcS
647     fi
648     for PKG in $PACKAGES_TO_RUNSCRIPTS ; do
649         : > $BUILD_ROOT/.init_b_cache/scripts/$PKG.run
650     done
651     for PKG in $PACKAGES_TO_PREINSTALL ; do
652         preinstall ${PKG##*/}
653     done
654     if test -n "$PREPARE_VM" ; then
655         for PKG in $PACKAGES_TO_VMINSTALL ; do
656             preinstall ${PKG##*/}
657         done
658     fi
659     # add cbpreinstall if cross HOST != TARGET
660     for PKG in $PACKAGES_TO_CBPREINSTALL ; do
661         preinstall ${PKG##*/}
662     done
663     if [ -w /root ]; then
664             test -c $BUILD_ROOT/dev/null || create_devs
665     fi
666     test -e $BUILD_ROOT/etc/fstab || touch $BUILD_ROOT/etc/fstab
667     test -e $BUILD_ROOT/etc/ld.so.conf || cp $BUILD_ROOT/etc/ld.so.conf.in $BUILD_ROOT/etc/ld.so.conf
668     if test -z "$PREPARE_VM" ; then
669         run_pkg_scripts
670         init_db
671         touch $BUILD_ROOT/.init_b_cache/preinstall_finished
672     fi
673 fi
674
675 if test -n "$PREPARE_VM" ; then
676     mkdir -p $BUILD_ROOT/.build
677     echo "copying packages..."
678     for PKG in $PACKAGES_TO_INSTALL ; do
679         rm -f $BUILD_ROOT/.init_b_cache/$PKG.$PSUF
680         cp $BUILD_ROOT/.init_b_cache/rpms/$PKG.$PSUF $BUILD_ROOT/.init_b_cache/$PKG.$PSUF || cleanup_and_exit 1
681         ln -s -f ../$PKG.$PSUF $BUILD_ROOT/.init_b_cache/rpms/$PKG.$PSUF
682         check_exit
683     done
684     # alreadyinstalled check will not work, but we have to live with
685     # that...
686     echo -n 'reordering...'
687     PACKAGES_TO_INSTALL=`reorder $PACKAGES_TO_INSTALL`
688     echo 'done'
689     Q="'\''"
690     echo "PACKAGES_TO_INSTALL='${PACKAGES_TO_INSTALL//"'"/$Q}'" > $BUILD_ROOT/.build/init_buildsystem.data
691     echo "PACKAGES_TO_RUNSCRIPTS='${PACKAGES_TO_RUNSCRIPTS//"'"/$Q}'" >> $BUILD_ROOT/.build/init_buildsystem.data
692     echo "PSUF='$PSUF'" >> $BUILD_ROOT/.build/init_buildsystem.data
693     rm -f $BUILD_IS_RUNNING
694     cleanup_and_exit 0
695 fi
696
697 mkdir -p $BUILD_ROOT/proc
698 mkdir -p $BUILD_ROOT/dev/pts
699 mount -n -tproc none $BUILD_ROOT/proc 2>/dev/null || true
700 mount -n -tdevpts none $BUILD_ROOT/dev/pts 2>/dev/null || true
701
702 #
703 # create .build.binaries directory if requested
704 #
705 rm -rf $BUILD_ROOT/.build.binaries
706 if test -n "$CREATE_BUILD_BINARIES" ; then
707     echo "creating .build.binaries directory..."
708     mkdir -p "$BUILD_ROOT/.build.binaries"
709     for PKG in $PACKAGES_TO_INSTALL ; do
710         test -L "$BUILD_ROOT/.init_b_cache/rpms/$PKG.$PSUF" || continue
711         LPKG=`readlink -f "$BUILD_ROOT/.init_b_cache/rpms/$PKG.$PSUF"`
712         ln "$LPKG" "$BUILD_ROOT/.build.binaries/$PKG.$PSUF" 2>/dev/null
713         test -f "$BUILD_ROOT/.build.binaries/$PKG.$PSUF" && continue
714         cp "$LPKG" "$BUILD_ROOT/.build.binaries/$PKG.$PSUF"
715         check_exit
716     done
717 fi
718
719 #
720 # get list and ids of already installed rpms
721 #
722 mkdir -p $BUILD_ROOT/.init_b_cache/alreadyinstalled
723 if test -f $BUILD_ROOT/var/lib/rpm/packages.rpm -o -f $BUILD_ROOT/var/lib/rpm/Packages ; then
724     chroot $BUILD_ROOT rpm -qa --qf "%{NAME} $RPMIDFMT" | (
725         while read pp ii; do
726             echo "$ii" > "$BUILD_ROOT/.init_b_cache/alreadyinstalled/$pp"
727         done
728     )
729 fi
730
731 #
732 # reorder packages (already done in vm continuation)
733 #
734 if ! test -e $BUILD_ROOT/.build/init_buildsystem.data ; then
735     echo -n 'reordering...'
736     PACKAGES_TO_INSTALL_FIRST=`reorder $PACKAGES_TO_INSTALL_FIRST`
737     PACKAGES_TO_INSTALL=`reorder $PACKAGES_TO_INSTALL`
738     echo 'done'
739 fi
740
741 rpm_e()
742 {
743     chroot $BUILD_ROOT rpm --nodeps -e $PKG 2>&1 | \
744     while read line; do
745         case "$line" in
746
747             r*failed:\ No\ such\ file\ or\ directory) ;;
748             error:\ failed\ to\ stat\ *:\ No\ such\ file\ or\ directory) ;;
749             error:\ *scriptlet\ failed*)
750                 echo "$line"
751                 echo "re-try deleting $PKG using --noscripts"
752                 chroot $BUILD_ROOT rpm --nodeps --noscripts -e $PKG || true
753             ;;
754             *) echo "$line" ;;
755         esac
756     done
757 }
758
759 #
760 # delete all packages we don't want
761 #
762 mkdir -p $BUILD_ROOT/.init_b_cache/todelete
763 for PKG in $BUILD_ROOT/.init_b_cache/alreadyinstalled/* ; do
764     PKG=${PKG##*/}
765     test "$PKG" = "*" && continue
766     ln $BUILD_ROOT/.init_b_cache/alreadyinstalled/$PKG $BUILD_ROOT/.init_b_cache/todelete/$PKG
767 done
768 for PKG in $PACKAGES_TO_INSTALL_FIRST $PACKAGES_TO_INSTALL $PACKAGES_TO_CBINSTALL ; do
769     rm -f $BUILD_ROOT/.init_b_cache/todelete/$PKG
770 done
771 for PKG in $BUILD_ROOT/.init_b_cache/todelete/* ; do
772     PKG=${PKG##*/}
773     test "$PKG" = "*" && continue
774     echo "deleting $PKG"
775     rpm_e "$PKG"
776     check_exit
777 done
778 rm -rf $BUILD_ROOT/.init_b_cache/todelete
779
780 rm -rf $BUILD_ROOT/.init_b_cache/preinstalls
781 mkdir -p $BUILD_ROOT/.init_b_cache/preinstalls
782 for PKG in $PACKAGES_TO_PREINSTALL $PACKAGES_TO_CBPREINSTALL; do
783     touch "$BUILD_ROOT/.init_b_cache/preinstalls/$PKG"
784 done
785
786 rm -rf $BUILD_ROOT/installed-pkg
787 mkdir -p $BUILD_ROOT/installed-pkg
788
789 RPMCHECKOPTS=
790 RPMCHECKOPTS_HOST=
791 # on Fedora 10 rpmbuild is in a separate package so we need something else to
792 # detect rpm4
793 test -x $BUILD_ROOT/usr/bin/rpmsign && RPMCHECKOPTS="--nodigest --nosignature"
794 test -x /usr/bin/rpmsign && RPMCHECKOPTS_HOST="--nodigest --nosignature"
795
796 for PKG in $PACKAGES_TO_INSTALL_FIRST RUN_LDCONFIG $PACKAGES_TO_INSTALL $PACKAGES_TO_CBINSTALL; do
797
798     case $PKG in
799       RUN_LDCONFIG)
800         test -x $BUILD_ROOT/sbin/ldconfig && chroot $BUILD_ROOT /sbin/ldconfig 2>&1
801         continue
802       ;;
803     esac
804
805     test -f $BUILD_ROOT/installed-pkg/$PKG && continue
806
807     if test $PSUF = deb ; then
808         # debian world, install deb files
809         test -L $BUILD_ROOT/.init_b_cache/rpms/$PKG.deb || continue
810         if ! test "$BUILD_ROOT/.init_b_cache/rpms/$PKG.deb" -ef "$BUILD_ROOT/.init_b_cache/$PKG.deb" ; then
811             rm -f $BUILD_ROOT/.init_b_cache/$PKG.deb
812             cp $BUILD_ROOT/.init_b_cache/rpms/$PKG.deb $BUILD_ROOT/.init_b_cache/$PKG.deb || cleanup_and_exit 1
813         fi
814         PKGID=`readlink $BUILD_ROOT/.init_b_cache/rpms/$PKG.deb`
815         PKGID="${PKGID##*/}"
816         PKGID="${PKGID%.deb}"
817         echo "installing ${PKGID%_*}"
818         ( chroot $BUILD_ROOT dpkg --install --force all .init_b_cache/$PKG.deb 2>&1 || touch $BUILD_ROOT/exit ) | \
819             perl -ne '$|=1;/^(Configuration file|Installing new config file|Selecting previously deselected|\(Reading database|Unpacking |Setting up|Creating config file|Preparing to replace dpkg)/||/^$/||print'
820         check_exit
821         echo "$PKGID debian" > $BUILD_ROOT/installed-pkg/$PKG
822         # ugly workaround for upstart system. some packages (procps) try
823         # to start a service in their configure phase. As we don't have
824         # a running upstart, we just link the start binary to /bin/true
825         if test -e "$BUILD_ROOT/sbin/start"; then
826             if test "$BUILD_ROOT/sbin/start" -ef "$BUILD_ROOT/sbin/initctl" ; then
827                 echo "linking /sbin/start to /bin/true"
828                 mv "$BUILD_ROOT/sbin/start" "$BUILD_ROOT/sbin/start.disabled"
829                 ln -s "/bin/true" "$BUILD_ROOT/sbin/start"
830             fi
831         fi
832         continue
833     fi
834
835     test -L $BUILD_ROOT/.init_b_cache/rpms/$PKG.rpm || continue
836
837     if test -f $BUILD_ROOT/.init_b_cache/rpms/$PKG.id -a -f $BUILD_ROOT/.init_b_cache/alreadyinstalled/$PKG ; then
838         read PKGID < $BUILD_ROOT/.init_b_cache/rpms/$PKG.id
839         read OLDPKGID < $BUILD_ROOT/.init_b_cache/alreadyinstalled/$PKG
840         if test "$PKGID" = "$OLDPKGID" ; then
841             #echo "keeping ${PKGID%% *}"
842             echo "$PKGID" > $BUILD_ROOT/installed-pkg/$PKG
843             continue
844         fi
845     fi
846
847     PKGID=`rpm -qp --qf "$RPMIDFMT" $RPMCHECKOPTS_HOST $BUILD_ROOT/.init_b_cache/rpms/$PKG.rpm`
848
849     if test -f $BUILD_ROOT/.init_b_cache/alreadyinstalled/$PKG ; then
850         read OLDPKGID < $BUILD_ROOT/.init_b_cache/alreadyinstalled/$PKG
851         if test "$PKGID" != "$OLDPKGID" ; then
852             echo deleting unwanted ${OLDPKGID%% *}
853             rpm_e "$PKG"
854         elif test "$VERIFY_BUILD_SYSTEM" = true ; then
855             chroot $BUILD_ROOT rpm --verify $PKG 2>&1 | tee $TMPFILE
856             if grep ^missing $TMPFILE > /dev/null ; then
857                 echo deleting incomplete ${PKGID%% *}
858                 rpm_e "$PKG"
859             else
860                 #echo "keeping ${PKGID%% *}"
861                 echo "$PKGID" > $BUILD_ROOT/installed-pkg/$PKG
862                 continue
863             fi
864         else
865             #echo "keeping ${PKGID%% *}"
866             echo "$PKGID" > $BUILD_ROOT/installed-pkg/$PKG
867             continue
868         fi
869         if test -e "$BUILD_ROOT/.init_b_cache/preinstalls/$PKG" ; then
870             preinstall "$PKG"
871             # call for rpm-4.x and not rpm-devel
872             test -z "${PKG##rpm-[0-9]*}" && chroot $BUILD_ROOT rpm --rebuilddb
873             # also exec for exchanged rpm !  naming is rpm-x86-<target>-<ver>
874             test -z "${PKG##rpm-x86-*[0-9]*}" && chroot $BUILD_ROOT rpm --rebuilddb
875         fi
876     fi
877     export ADDITIONAL_PARAMS=
878     if test "$USE_FORCE" = true ; then
879         export ADDITIONAL_PARAMS="$ADDITIONAL_PARAMS --force"
880     fi
881     # work around for cross-build installs, we must not overwrite the running rpm
882     if test "$PKG" = rpm ; then
883         for i in $BUILD_ROOT/.init_b_cache/preinstalls/rpm-x86-* ; do
884             test -e "$i" && ADDITIONAL_PARAMS="$ADDITIONAL_PARAMS --justdb"
885         done
886     fi
887     echo "installing ${PKGID%% *}"
888     if ! test "$BUILD_ROOT/.init_b_cache/rpms/$PKG.rpm" -ef "$BUILD_ROOT/.init_b_cache/$PKG.rpm" ; then
889         rm -f $BUILD_ROOT/.init_b_cache/$PKG.rpm
890         cp $BUILD_ROOT/.init_b_cache/rpms/$PKG.rpm $BUILD_ROOT/.init_b_cache/$PKG.rpm || cleanup_and_exit 1
891     fi
892     ( chroot $BUILD_ROOT rpm --ignorearch --nodeps -U --oldpackage --ignoresize $RPMCHECKOPTS \
893                 $ADDITIONAL_PARAMS .init_b_cache/$PKG.rpm 2>&1 || \
894           touch $BUILD_ROOT/exit ) | \
895               grep -v "^warning:.*saved as.*rpmorig$"
896     # delete link so package is only installed once
897     rm -f $BUILD_ROOT/.init_b_cache/$PKG.rpm
898     check_exit
899     echo "$PKGID" > $BUILD_ROOT/installed-pkg/$PKG
900
901 done
902
903 if test $PSUF = deb ; then
904     echo "configure all installed packages..."
905     # configure all packages after complete installation, not for each package like rpm does
906     # We need to run this twice, because of cyclic dependencies as it does not succeed on most
907     # debian based distros in the first attempt.
908     if ! chroot $BUILD_ROOT dpkg --configure --pending  2>&1; then
909        echo "first configure attempt failed, trying again..."
910        chroot $BUILD_ROOT dpkg --configure --pending  2>&1 || touch $BUILD_ROOT/exit
911     fi
912 fi
913
914 # devices can vanish if devs got uninstalled
915 test -c $BUILD_ROOT/dev/null || create_devs
916
917 cd $BUILD_ROOT || cleanup_and_exit 1
918
919 #
920 # setup /etc/mtab
921 #
922 rm -f $BUILD_ROOT/etc/mtab
923 cp /proc/mounts $BUILD_ROOT/etc/mtab
924 chmod 644 $BUILD_ROOT/etc/mtab
925
926 #
927 # to be sure, path is set correctly, we have to source /etc/profile before
928 # starting rpm.
929 #
930 # XXX
931 #rm -f $BUILD_ROOT/bin/rpm.sh
932 #cp $BUILD_LIBDIR/lib/rpm.sh $BUILD_ROOT/bin/rpm.sh
933 #chmod 755 $BUILD_ROOT/bin/rpm.sh
934 #test -f $BUILD_ROOT/bin/rpm -a ! -L $BUILD_ROOT/bin/rpm && \
935 #    mv $BUILD_ROOT/bin/rpm $BUILD_ROOT/bin/rpm.bin
936 #rm -f $BUILD_ROOT/bin/rpm
937 #ln -s rpm.sh $BUILD_ROOT/bin/rpm
938
939 #
940 # some packages use uname -r to decide which kernel is used to build for.
941 # this does not work in autobuild always.  Here is a wrapper script, that
942 # gets Version from kernel sources.
943 #
944 # XXX
945 #rm -f $BUILD_ROOT/bin/uname.sh
946 #cp -v $BUILD_LIBDIR/lib/uname.sh $BUILD_ROOT/bin/uname.sh
947 #chmod 755 $BUILD_ROOT/bin/uname.sh
948 #test -f $BUILD_ROOT/bin/uname -a ! -L $BUILD_ROOT/bin/uname && \
949 #    mv $BUILD_ROOT/bin/uname $BUILD_ROOT/bin/uname.bin
950 #rm -f $BUILD_ROOT/bin/uname
951 #ln -s uname.sh $BUILD_ROOT/bin/uname
952
953 #
954 # some distributions have a /etc/rpmrc or /etc/rpm/macros and some not.
955 # make sure, that it is setup correctly.
956 #
957 # XXX
958 #rm -f $BUILD_ROOT/etc/rpmrc
959 #if test -e $BUILD_LIBDIR/lib/rpmrc.$BUILD_BASENAME ; then
960 #    cp -v $BUILD_LIBDIR/lib/rpmrc.$BUILD_BASENAME $BUILD_ROOT/etc/rpmrc
961 #elif test -e $BUILD_LIBDIR/lib/rpmrc ; then
962 #    cp -v $BUILD_LIBDIR/lib/rpmrc $BUILD_ROOT/etc/rpmrc
963 #fi
964
965 # XXX
966 #rm -f $BUILD_ROOT/etc/rpm/macros $BUILD_ROOT/etc/rpm/suse_macros
967 #mkdir -p $BUILD_ROOT/etc/rpm
968 #if test -e $BUILD_LIBDIR/lib/macros.$BUILD_BASENAME ; then
969 #    cp -v $BUILD_LIBDIR/lib/macros.$BUILD_BASENAME $BUILD_ROOT/etc/rpm/macros
970 #    cp -v $BUILD_LIBDIR/lib/macros.$BUILD_BASENAME $BUILD_ROOT/etc/rpm/suse_macros
971 #elif test -e $BUILD_LIBDIR/lib/macros ; then
972 #    cp -v $BUILD_LIBDIR/lib/macros $BUILD_ROOT/etc/rpm/macros
973 #    cp -v $BUILD_LIBDIR/lib/macros $BUILD_ROOT/etc/rpm/suse_macros
974 #fi
975
976 #
977 # make sure, that our nis is not present in the chroot system
978 #
979 test -e $BUILD_ROOT/etc/nsswitch.conf && {
980     echo removing nis flags from $BUILD_ROOT/etc/nsswitch.conf...
981     cat $BUILD_ROOT/etc/nsswitch.conf | sed -e"s:nis::g" > \
982         $BUILD_ROOT/etc/nsswitch.conf.tmp
983     mv $BUILD_ROOT/etc/nsswitch.conf.tmp $BUILD_ROOT/etc/nsswitch.conf
984 }
985
986 #
987 # creating some default directories
988 for DIR in /usr/share/doc/packages \
989            /usr/X11R6/include/X11/pixmaps \
990            /usr/X11R6/include/X11/bitmaps ; do
991     mkdir -p $BUILD_ROOT/$DIR
992 done
993
994 for FILE in /var/run/utmp /var/log/wtmp /etc/fstab ; do
995     touch $BUILD_ROOT/$FILE
996 done
997
998 echo now finalizing build dir...
999 CHROOT_RETURN="`chroot $BUILD_ROOT /sbin/ldconfig 2>&1`"
1000 case "$CHROOT_RETURN" in
1001     *warning:*)
1002       chroot $BUILD_ROOT /sbin/ldconfig
1003       echo
1004       echo chroot $BUILD_ROOT /sbin/ldconfig
1005       echo
1006       echo "$CHROOT_RETURN"
1007       echo
1008       echo "Problem with ldconfig.  It's better to reinit the build system..."
1009       echo
1010       cleanup_and_exit 1
1011     ;;
1012 esac
1013 test -x $BUILD_ROOT/usr/sbin/Check && chroot $BUILD_ROOT /usr/sbin/Check
1014
1015 mkdir -p $BUILD_ROOT/var/adm/packages
1016 touch $BUILD_ROOT/var/adm/packages
1017 if test -x $BUILD_ROOT/sbin/SuSEconfig ; then
1018     if grep norestarts $BUILD_ROOT/sbin/SuSEconfig > /dev/null ; then
1019         chroot $BUILD_ROOT /sbin/SuSEconfig --norestarts --force
1020     else
1021         chroot $BUILD_ROOT /sbin/SuSEconfig --force
1022     fi
1023 fi
1024
1025 if test -x $BUILD_ROOT/usr/X11R6/bin/switch2mesasoft ; then
1026     chroot $BUILD_ROOT /usr/X11R6/bin/switch2mesasoft
1027 fi
1028
1029 for PROG in /usr/bin/TeX/texhash /usr/bin/texhash ; do
1030     test -x $BUILD_ROOT/$PROG && \
1031         chroot $BUILD_ROOT bash -c ". /etc/profile ; $PROG"
1032 done
1033
1034 if test -e $BUILD_ROOT/usr/share/zoneinfo/UTC ; then
1035     chroot $BUILD_ROOT zic -l UTC
1036 fi
1037
1038 test -e $BUILD_ROOT/.build/init_buildsystem.data || HOST=`hostname`
1039 test -e $BUILD_ROOT/etc/hosts || echo "127.0.0.1 localhost" > $BUILD_ROOT/etc/hosts
1040 if ! grep -F "127.0.0.1 $HOST" $BUILD_ROOT/etc/hosts > /dev/null ; then
1041     # this makes a reverse lookup on 127.0.0.1 return the host name,
1042     # which is bad, but 127.0.0.2 does not work on all unix systems
1043     echo "127.0.0.1 $HOST" > $BUILD_ROOT/etc/hosts.new
1044     test -f $BUILD_ROOT/etc/hosts && cat $BUILD_ROOT/etc/hosts >> $BUILD_ROOT/etc/hosts.new
1045     mv $BUILD_ROOT/etc/hosts.new $BUILD_ROOT/etc/hosts
1046 fi
1047
1048 if test -x $BUILD_ROOT/bin/rpm -a ! -f $BUILD_ROOT/var/lib/rpm/packages.rpm -a ! -f $BUILD_ROOT/var/lib/rpm/Packages ; then
1049     echo "initializing rpm db..."
1050     chroot $BUILD_ROOT rpm --initdb || cleanup_and_exit 1
1051     # create provides index
1052     chroot $BUILD_ROOT rpm -q --whatprovides rpm >/dev/null 2>&1
1053 fi
1054
1055 # create modules.dep in kvm/xen
1056 # This can not work, until we use the native repository kernel
1057 #if [ $BUILD_ROOT = "/" -a -x /sbin/depmod ]; then
1058 #  /sbin/depmod -a
1059 #fi
1060
1061 rm -f $BUILD_ROOT/.rpmmacros $BUILD_ROOT/root/.rpmmacros
1062 rm -rf $BUILD_ROOT/.init_b_cache
1063 rm -f $BUILD_IS_RUNNING
1064 rm -f $TMPFILE
1065
1066 cleanup_and_exit 0