change the date
[tools/build.git] / build-recipe-kiwi
1 #
2 # KIWI specific functions. Handle with care.
3 #
4 ################################################################
5 #
6 # Copyright (c) 1995-2014 SUSE Linux Products GmbH
7 #
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License version 2 or 3 as
10 # published by the Free Software Foundation.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program (see the file COPYING); if not, write to the
19 # Free Software Foundation, Inc.,
20 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
21 #
22 ################################################################
23
24
25 ############################################################
26
27 # post scriptlet generation functions
28
29 kiwi_post_oem() {
30     cat <<-EOF
31         echo "compressing oem images... "
32         cd /$TOPDIR/KIWI-oem
33         # do not store compressed file _and_ uncompressed one
34         [ -e "$imageout.gz" ] && rm -f "$imageout"
35         if [ -e "$imageout.iso" ]; then
36             echo "take iso file and create sha256..."
37             mv "$imageout.iso" "/$TOPDIR/KIWI/$imageout$buildnum.iso"
38             pushd /$TOPDIR/KIWI
39             if [ -x /usr/bin/sha256sum ]; then
40                 /usr/bin/sha256sum "$imageout$buildnum.iso" > "$imageout$buildnum.iso.sha256"
41             fi
42             popd
43         fi
44         if [ -e "$imageout.install.iso" ]; then
45             echo "take install.iso file and create sha256..."
46             mv "$imageout.install.iso" "/$TOPDIR/KIWI/$imageout$buildnum.install.iso"
47             pushd /$TOPDIR/KIWI
48             if [ -x /usr/bin/sha256sum ]; then
49                 /usr/bin/sha256sum "$imageout$buildnum.install.iso" > "$imageout$buildnum.install.iso.sha256"
50             fi
51             popd
52         fi
53         if [ -e "$imageout.qcow2" ]; then
54             mv "$imageout.qcow2" "/$TOPDIR/KIWI/$imageout$buildnum.qcow2"
55             pushd /$TOPDIR/KIWI
56             if [ -x /usr/bin/sha256sum ]; then
57                 echo "Create sha256 file..."
58                 /usr/bin/sha256sum "$imageout$buildnum.qcow2" > "$imageout$buildnum.qcow2.sha256"
59             fi
60             popd
61         fi
62         if [ -e "$imageout.raw.install.raw" ]; then
63             compress_tool="bzip2"
64             compress_suffix="bz2"
65             if [ -x /usr/bin/xz ]; then
66                 # take xz to get support for sparse files
67                 compress_tool="xz -2"
68                 compress_suffix="xz"
69             fi
70             mv "$imageout.raw.install.raw" "/$TOPDIR/KIWI/$imageout$buildnum.raw.install.raw"
71             pushd /$TOPDIR/KIWI
72             echo "\$compress_tool raw.install.raw file..."
73             \$compress_tool "$imageout$buildnum.raw.install.raw"
74             if [ -x /usr/bin/sha256sum ]; then
75                 echo "Create sha256 file..."
76                 /usr/bin/sha256sum "$imageout$buildnum.raw.install.raw.\${compress_suffix}" > "$imageout$buildnum.raw.install.raw.\${compress_suffix}.sha256"
77             fi
78             popd
79         fi
80         if [ -e "$imageout.raw" ]; then
81             compress_tool="bzip2"
82             compress_suffix="bz2"
83             if [ -x /usr/bin/xz ]; then
84                 # take xz to get support for sparse files
85                 compress_tool="xz -2"
86                 compress_suffix="xz"
87             fi
88             mv "$imageout.raw" "/$TOPDIR/KIWI/$imageout$buildnum.raw"
89             pushd /$TOPDIR/KIWI
90             echo "\$compress_tool raw file..."
91             \$compress_tool "$imageout$buildnum.raw"
92             if [ -x /usr/bin/sha256sum ]; then
93                 echo "Create sha256 file..."
94                 /usr/bin/sha256sum "$imageout$buildnum.raw.\${compress_suffix}" > "$imageout$buildnum.raw.\${compress_suffix}.sha256"
95             fi
96             popd
97         fi
98         EOF
99 }
100
101 kiwi_post_vmx() {
102     cat <<-EOF
103         echo "compressing vmx images... "
104         cd /$TOPDIR/KIWI-vmx
105         compress_tool="bzip2"
106         compress_suffix="bz2"
107         if [ -x /usr/bin/xz ]; then
108             # take xz to get support for sparse files
109             compress_tool="xz -2"
110             compress_suffix="xz"
111         fi
112         VMXFILES=""
113         SHAFILES=""
114         for suffix in "ovf" "qcow2" "ova" "tar" "vhdfixed" "vhd"; do
115             if [ -e "$imageout.\$suffix" ]; then
116                 if [ "\$suffix" == "vhd" -o "\$suffix" == "vhdfixed" ]; then 
117                     mv "$imageout.\$suffix" "/$TOPDIR/KIWI/$imageout$buildnum.\$suffix"
118                     pushd /$TOPDIR/KIWI
119                     echo "\$compress_tool \$suffix file..."
120                     \$compress_tool "$imageout$buildnum.\$suffix"
121                     SHAFILES="\$SHAFILES $imageout$buildnum.\$suffix.\${compress_suffix}"
122                     popd
123                 elif [ "\$suffix" == "ovf" ]; then 
124                     mv "$imageout.\${suffix}/$imageout.\$suffix" "/$TOPDIR/KIWI/$imageout$buildnum.\$suffix"
125                     SHAFILES="\$SHAFILES $imageout$buildnum.\$suffix"
126                 else 
127                     mv "$imageout.\$suffix" "/$TOPDIR/KIWI/$imageout$buildnum.\$suffix"
128                     SHAFILES="\$SHAFILES $imageout$buildnum.\$suffix"
129                 fi
130             fi
131         done
132         # This option has a number of format parameters
133         for i in "$imageout.vmx" "$imageout.vmdk" "$imageout-disk*.vmdk"; do
134             test -e \$i && VMXFILES="\$VMXFILES \$i"
135         done
136         # take raw files as fallback
137         if [ -n "\$VMXFILES" ]; then
138             tar cvjfS "/$TOPDIR/KIWI/$imageout$buildnum-vmx.tar.bz2" \$VMXFILES
139             SHAFILES="\$SHAFILES $imageout$buildnum-vmx.tar.bz2"
140         elif [ -z "\$SHAFILES" -a -e  "$imageout.raw" ]; then
141             mv "$imageout.raw" "/$TOPDIR/KIWI/$imageout$buildnum-vmx.raw"
142             pushd /$TOPDIR/KIWI
143             echo "\$compress_tool raw file..."
144             \$compress_tool "$imageout$buildnum-vmx.raw"
145             SHAFILES="\$SHAFILES $imageout$buildnum-vmx.raw.\${compress_suffix}"
146             popd
147         fi
148         if [ -e "$imageout.box" ]; then
149             tar cvjfS "/$TOPDIR/KIWI/$imageout$buildnum-vmx-box.tar.bz2" $imageout.box $imageout.json
150             SHAFILES="\$SHAFILES $imageout$buildnum-vmx-box.tar.bz2"
151         fi
152         if [ -e "$imageout.xenconfig" ]; then
153             tar cvjfS "/$TOPDIR/KIWI/$imageout$buildnum-vmx.tar.bz2" $imageout.xenconfig $imageout.raw initrd-*
154             SHAFILES="\$SHAFILES $imageout$buildnum-vmx.tar.bz2"
155         fi
156         # FIXME: do we need a single .raw file in any case ?
157
158         cd /$TOPDIR/KIWI
159         if [ -n "\$SHAFILES" -a -x /usr/bin/sha256sum ]; then
160             for i in \$SHAFILES; do
161                 echo "Create sha256 file..."
162                 /usr/bin/sha256sum "\$i" > "\$i.sha256"
163             done
164         fi
165         tar cvjfS "/$TOPDIR/KIWI/$imageout$buildnum-raw.tar.bz2" \
166             --exclude="$imageout.iso" --exclude="$imageout.raw" --exclude="$imageout.qcow2" *
167         cd /$TOPDIR/KIWI
168         if [ -x /usr/bin/sha256sum ]; then
169             /usr/bin/sha256sum "$imageout$buildnum-raw.tar.bz2" > "$imageout$buildnum-raw.tar.bz2.sha256"
170         fi
171         EOF
172 }
173
174 kiwi_post_xen() {
175     cat <<-EOF
176         echo "compressing xen images... "
177         cd /$TOPDIR/KIWI-xen
178         # do not store compressed file _and_ uncompressed one
179         [ -e "$imageout.gz" ] && rm -f "$imageout"
180         tar cvjfS "/$TOPDIR/KIWI/$imageout$buildnum-xen.tar.bz2" \
181                 `grep ^kernel $imageout.xenconfig | cut -d'"'  -f2` \
182                 `grep ^ramdisk $imageout.xenconfig | cut -d'"'  -f2` \
183                 initrd-* \
184                 "$imageout.xenconfig" \
185                 "$imageout"
186         if [ -x /usr/bin/sha256sum ]; then
187             echo "Create sha256 file..."
188             cd $TOPDIR/KIWI
189             /usr/bin/sha256sum "$imageout$buildnum-xen.tar.bz2" > "$imageout$buildnum-xen.tar.bz2.sha256"
190         fi
191         EOF
192 }
193
194 kiwi_post_pxe() {
195     cat <<-EOF
196         echo "compressing pxe images... "
197         cd /$TOPDIR/KIWI-pxe
198         # do not store compressed file _and_ uncompressed one
199         [ -e "$imageout.gz" ] && rm -f "$imageout"
200         tar cvjfS "/$TOPDIR/KIWI/$imageout$buildnum-pxe.tar.bz2" ${imageout}* initrd-*
201         if [ -x /usr/bin/sha256sum ]; then
202             echo "Create sha256 file..."
203             cd $TOPDIR/KIWI
204             /usr/bin/sha256sum "$imageout$buildnum-pxe.tar.bz2" > "$imageout$buildnum-pxe.tar.bz2.sha256"
205         fi
206         EOF
207 }
208
209 kiwi_post_iso() {
210     cat <<-EOF
211         cd /$TOPDIR/KIWI-iso
212         for i in *.iso; do
213             mv "\$i" "/$TOPDIR/KIWI/\${i%.iso}$buildnum.iso"
214         done
215         if [ -x /usr/bin/sha256sum ]; then
216             echo "creating sha256 sum for iso images... "
217             cd $TOPDIR/KIWI
218             for i in *.iso; do
219                 /usr/bin/sha256sum "\$i" > "\$i.sha256"
220             done
221         fi
222         EOF
223 }
224
225 kiwi_post_tbz() {
226     cat <<-EOF
227         cd /$TOPDIR/KIWI-tbz
228         for i in *.tbz; do
229             file=\$(readlink -f "\$i")
230             [ -z "\$file" ] && echo readlink failed for $i
231             mv "\$file" "/$TOPDIR/KIWI/\${i%.tbz}$buildnum.tbz"
232         done
233         if [ -x /usr/bin/sha256sum ]; then
234             echo "creating sha256 sum for tar balls... "
235             cd $TOPDIR/KIWI
236             for i in *.tbz; do
237                 /usr/bin/sha256sum "\$i" > "\$i.sha256"
238             done
239         fi
240         EOF
241 }
242
243 kiwi_post_unknown() {
244     cat <<-EOF
245         echo "compressing unkown images... "
246         cd /$TOPDIR/KIWI-$imgtype
247         # do not store compressed file _and_ uncompressed one
248         [ -e "$imageout.gz" ] && rm -f "$imageout"
249         tar cvjfS "/$TOPDIR/KIWI/$imageout$buildnum-$imgtype.tar.bz2" *
250         if [ -x /usr/bin/sha256sum ]; then
251             echo "Create sha256 file..."
252             cd /$TOPDIR/KIWI
253             /usr/bin/sha256sum "$imageout$buildnum-$imgtype.tar.bz2" > "$imageout$buildnum-$imgtype.tar.bz2.sha256"
254         fi
255         EOF
256 }
257
258 ############################################################
259
260 recipe_setup_kiwi() {
261     TOPDIR=/usr/src/packages
262     test "$DO_INIT_TOPDIR" = false || rm -rf "$BUILD_ROOT$TOPDIR"
263     mkdir -p "$BUILD_ROOT$TOPDIR"
264     mkdir -p "$BUILD_ROOT$TOPDIR/OTHER"
265     mkdir -p "$BUILD_ROOT$TOPDIR/SOURCES"
266     mkdir -p "$BUILD_ROOT$TOPDIR/KIWI"
267     # compat, older build versions did not clean TOPDIR ...
268     mkdir -p "$BUILD_ROOT$TOPDIR/BUILD"
269     mkdir -p "$BUILD_ROOT$TOPDIR/RPMS"
270     mkdir -p "$BUILD_ROOT$TOPDIR/SRPMS"
271     
272     chown -R "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT$TOPDIR"
273     if test "$MYSRCDIR" = $BUILD_ROOT/.build-srcdir ; then 
274         mv "$MYSRCDIR"/* $BUILD_ROOT$TOPDIR/SOURCES/
275     else
276         if test -z "$LINKSOURCES" ; then 
277             cp -dLR "$MYSRCDIR"/* $BUILD_ROOT$TOPDIR/SOURCES/
278         else
279             cp -lR "$MYSRCDIR"/* $BUILD_ROOT$TOPDIR/SOURCES/
280         fi
281         if test "$?" != 0 ; then 
282             echo "source copy failed"
283             cleanup_and_exit 1
284         fi
285     fi
286
287     # extract macros from configuration
288     # some post scripts might call rpm-build and rely on the macros
289     queryconfig rawmacros --dist "$BUILD_DIST" --archpath "$BUILD_ARCH" --configdir "$CONFIG_DIR" > $BUILD_ROOT/root/.rpmmacros
290 }
291
292 recipe_prepare_kiwi() {
293     :
294 }
295
296 ## obsolete with current kiwi versions, only needed for kiwi 3.01 version
297 run_suse_isolinux() {
298     for i in $BUILD_ROOT/$TOPDIR/KIWIROOT/main/* ; do
299         test -d "$i" || continue
300         i="${i##*/}"
301         test "$i" = scripts && continue
302         test "$i" != "${i%0}" && continue
303         chroot $BUILD_ROOT su -c "suse-isolinux $TOPDIR/KIWIROOT/main/$i $TOPDIR/KIWI/$i.iso" - $BUILD_USER
304     done
305 }
306
307 build_kiwi_product() {
308     echo "running kiwi --create-instsource..."
309     # runs always as abuild user
310     mkdir -p "$BUILD_ROOT/$TOPDIR/KIWIROOT"
311     # XXX: again?
312     chroot "$BUILD_ROOT" chown -R abuild.abuild "$TOPDIR"
313     chroot "$BUILD_ROOT" rm -rf "$TOPDIR/KIWIROOT"
314     ver=`chroot "$BUILD_ROOT" su -c "/usr/sbin/kiwi --version | sed -n 's,.*kiwi version v\(.*\),\1,p'"`
315     test -n "$ver" || ver=`chroot "$BUILD_ROOT" su -c "/usr/sbin/kiwi --version | sed -n 's,.* vnr: \(.*\),\1,p'"`
316     if test "${ver:0:1}" == "3" ; then
317         # old style kiwi 3 builds
318         chroot "$BUILD_ROOT" su -c "APPID=- LANG=POSIX /usr/sbin/kiwi --root $TOPDIR/KIWIROOT -v --logfile terminal -p $TOPDIR/SOURCES --instsource-local --create-instsource $TOPDIR/SOURCES" - abuild < /dev/null && BUILD_SUCCEEDED=true
319         test ${ver:2:2} == "01" && run_suse_isolinux
320     else
321         VERBOSE_OPTION="-v 2"
322         # broken kiwi version, not accepting verbose level
323         test "${ver:0:1}" == "4" -a "${ver:2:2}" -lt 90 && VERBOSE_OPTION="-v -v"
324         chroot "$BUILD_ROOT" su -c "APPID=- LANG=POSIX /usr/sbin/kiwi --root $TOPDIR/KIWIROOT $VERBOSE_OPTION --logfile terminal -p $TOPDIR/SOURCES --create-instsource $TOPDIR/SOURCES" - abuild < /dev/null && BUILD_SUCCEEDED=true
325     fi
326
327     # move created product to correct destination
328     pushd $BUILD_ROOT/$TOPDIR/KIWIROOT/main
329     for i in * ; do
330         test -e "$i" || continue
331         case $i in
332             *.iso) if [ -x /usr/bin/sha256sum ]; then
333                        /usr/bin/sha256sum "$i" > "$i.sha256"
334                        mv "$i.sha256" $BUILD_ROOT/$TOPDIR/KIWI/.
335                    fi
336                    mv "$i" $BUILD_ROOT/$TOPDIR/KIWI/. ;;
337             *.packages) mv $i $BUILD_ROOT/$TOPDIR/OTHER/. ;;
338             *.report) mv $i $BUILD_ROOT/$TOPDIR/OTHER/. ;;
339             scripts) ;;
340             *0) ;;
341             *) test -d $i -a "$drop_repo" != true  && mv $i $BUILD_ROOT/$TOPDIR/KIWI/. ;;
342         esac
343     done
344     popd
345 }
346
347 perform_image_build() {
348     local imgtype=$1
349     local legacy=$2
350     local prepare_call
351     local create_call
352     # When people test mixed build with legacy and new kiwi version
353     # The zypper cache was used in different ways. Therefore this
354     # needs a cleanup before the build starts
355     echo "Cleanup zypper image build cache"
356     if [ -d "$BUILD_ROOT/var/cache/kiwi/zypper" ];then
357         rm -rf $BUILD_ROOT/var/cache/kiwi/zypper
358     fi
359     echo "running kiwi --prepare for $imgtype..."
360     # Do not use $BUILD_USER here, since we always need root permissions
361     prepare_call="cd $TOPDIR/SOURCES && rm -rf $TOPDIR/KIWIROOT-$imgtype"
362     if [ "$legacy" = "true" ]; then
363         prepare_call="$prepare_call && /usr/sbin/kiwi --logfile terminal"
364     else
365         prepare_call="$prepare_call && LANG=en_US.UTF-8 /usr/bin/kiwi"
366         prepare_call="$prepare_call --compat -- --debug"
367     fi
368     prepare_call="$prepare_call --prepare $TOPDIR/SOURCES"
369     prepare_call="$prepare_call --root $TOPDIR/KIWIROOT-$imgtype"
370     prepare_call="$prepare_call $KIWI_PARAMETERS"
371     chroot $BUILD_ROOT \
372         su -c "$prepare_call" - root < /dev/null || cleanup_and_exit 1
373
374     echo "running kiwi --create for $imgtype..."
375     mkdir -p $BUILD_ROOT/$TOPDIR/KIWI-$imgtype
376     create_call="cd $TOPDIR/SOURCES"
377     if [ "$legacy" = "true" ]; then
378         create_call="$create_call && LANG=en_US.UTF-8 /usr/sbin/kiwi"
379         create_call="$create_call --logfile terminal"
380     else
381         create_call="$create_call && /usr/bin/kiwi --compat -- --debug"
382     fi
383     create_call="$create_call --create $TOPDIR/KIWIROOT-$imgtype"
384     create_call="$create_call --type $imgtype"
385     create_call="$create_call -d $TOPDIR/KIWI-$imgtype"
386     create_call="$create_call $KIWI_PARAMETERS"
387     chroot $BUILD_ROOT \
388         su -c "$create_call" - root < /dev/null || cleanup_and_exit 1
389
390     rm -rf "/$TOPDIR/KIWI.bundle"
391 }
392
393 perform_image_bundle() {
394     local imgtype=$1
395     local legacy=$2
396     local bundle_call
397     if [ "$legacy" = "true" ]; then
398         bundle_call="/usr/sbin/kiwi --bundle-build $TOPDIR/KIWI-$imgtype"
399         bundle_call="$bundle_call -d /$TOPDIR/KIWI.bundle/"
400         bundle_call="$bundle_call --bundle-id Build$RELEASE"
401     else
402         bundle_call="LANG=en_US.UTF-8 /usr/bin/kiwi result bundle"
403         bundle_call="$bundle_call --target-dir $TOPDIR/KIWI-$imgtype"
404         bundle_call="$bundle_call --id Build$RELEASE"
405         bundle_call="$bundle_call --bundle-dir /$TOPDIR/KIWI.bundle/"
406     fi
407     if chroot $BUILD_ROOT su -c "$bundle_call" - root < /dev/null; then
408         mv "$BUILD_ROOT/$TOPDIR/KIWI.bundle/"* \
409             "$BUILD_ROOT/$TOPDIR/KIWI/" || cleanup_and_exit 1
410         rmdir "$BUILD_ROOT/$TOPDIR/KIWI.bundle"
411         # success
412         return 0
413     fi
414     # need another way to bundle
415     return 1
416 }
417
418 is_legacy_kiwi() {
419     if [ -L "$BUILD_ROOT/usr/bin/kiwi" ];then
420         # The next generation of kiwi is installed to /usr/bin
421         # If this file is found we expect the new kiwi to be
422         # installed
423         return 1
424     fi
425     # in any other case stick to the legacy kiwi
426     return 0
427 }
428
429 build_kiwi_appliance() {
430     if test -z "$RUNNING_IN_VM" ; then
431         # NOTE: this must be done with the outer system, because it loads
432         # the dm-mod kernel modules, which needs to fit to the kernel.
433         echo "starting device mapper for kiwi..."
434         test -x /etc/init.d/boot.device-mapper && \
435             /etc/init.d/boot.device-mapper start
436     fi
437     KIWI_PROFILE=$(queryconfig \
438         --dist "$BUILD_DIST" --configdir "$CONFIG_DIR" \
439         --archpath "$BUILD_ARCH" buildflags kiwiprofile
440     )
441     if test -n "$KIWI_PROFILE"; then
442         KIWI_PARAMETERS="$KIWI_PARAMETERS --add-profile $KIWI_PROFILE"
443     fi
444     local legacy=false
445     if is_legacy_kiwi; then
446         legacy=true
447     fi
448     RUN_BUNDLE="true"
449     for imgtype in $imagetype ; do
450         perform_image_build $imagetype $legacy
451         if perform_image_bundle $imagetype $legacy; then
452             # bundling successful, skip alternative bundlers
453             unset RUN_BUNDLE
454         fi
455     done
456     BUILD_SUCCEEDED=true
457
458     if test -z "$RUN_BUNDLE"; then
459        # new kiwi has bundled our result already :)
460        return
461     fi
462
463     #
464     # Legacy bundling code for kiwi version below 5.06.106
465     #
466
467     # create tar.gz of images, in case it makes sense
468     buildnum=
469     if test -n "$RELEASE"; then
470         buildnum="-Build$RELEASE"
471     fi
472     imagearch=`uname -m`
473     imageout="$imagename.$imagearch-$imageversion"
474     for imgtype in $imagetype ; do
475         case "$imgtype" in
476             oem) kiwi_post_oem   > $BUILD_ROOT/kiwi_post.sh ;;
477             vmx) kiwi_post_vmx   > $BUILD_ROOT/kiwi_post.sh ;;
478             xen) kiwi_post_xen   > $BUILD_ROOT/kiwi_post.sh ;;
479             pxe) kiwi_post_pxe   > $BUILD_ROOT/kiwi_post.sh ;;
480             iso) kiwi_post_iso   > $BUILD_ROOT/kiwi_post.sh ;;
481             tbz) kiwi_post_tbz   > $BUILD_ROOT/kiwi_post.sh ;;
482             *) kiwi_post_unknown > $BUILD_ROOT/kiwi_post.sh ;;
483         esac
484         cat >> $BUILD_ROOT/kiwi_post.sh <<-EOF
485                 cd /$TOPDIR/KIWI-$imgtype
486                 if [ -e "$imageout.channel" ]; then
487                     echo "Found kiwi channel list file, exporting as well..."
488                     cp "$imageout.channel" "/$TOPDIR/OTHER/$imageout$buildnum-$imgtype.channel"
489                 fi
490                 if [ -e "$imageout.packages" ]; then
491                     echo "Found kiwi package list file, exporting as well..."
492                     cp "$imageout.packages" "/$TOPDIR/OTHER/$imageout$buildnum-$imgtype.packages"
493                 fi
494                 if [ -e "$imageout.verified" ]; then
495                     echo "Found rpm verification report, exporting as well..."
496                     cp "$imageout.verified" "/$TOPDIR/OTHER/$imageout$buildnum-$imgtype.verified"
497                 fi
498                 EOF
499         chroot $BUILD_ROOT su -c "sh -e /kiwi_post.sh" || cleanup_and_exit 1
500         rm -f $BUILD_ROOT/kiwi_post.sh
501     done
502 }
503
504 recipe_build_kiwi() {
505     imagetype=$(perl -I$BUILD_DIR -MBuild::Kiwi -e Build::Kiwi::show $BUILD_ROOT/$TOPDIR/SOURCES/$RECIPEFILE imagetype)
506     imagename=$(perl -I$BUILD_DIR -MBuild::Kiwi -e Build::Kiwi::show $BUILD_ROOT/$TOPDIR/SOURCES/$RECIPEFILE filename)
507     imageversion=$(perl -I$BUILD_DIR -MBuild::Kiwi -e Build::Kiwi::show $BUILD_ROOT/$TOPDIR/SOURCES/$RECIPEFILE version)
508     drop_repo=$(perl -I$BUILD_DIR -MBuild::Kiwi -e Build::Kiwi::show $BUILD_ROOT/$TOPDIR/SOURCES/$RECIPEFILE drop_repository)
509
510     # prepare rpms as source and createrepo on the repositories
511     ln -sf $TOPDIR/SOURCES/repos $BUILD_ROOT/repos
512     cd $BUILD_ROOT/$TOPDIR/SOURCES/repos
513     for r in *[^:]/* ; do
514         test -L $r && continue
515         test -d $r || continue
516         repo="$TOPDIR/SOURCES/repos/$r/"
517         # create compatibility link for old kiwi versions
518         rc="${r//:/:/}"
519         if test "$rc" != "$r" ; then
520             rl="${rc//[^\/]}"
521             rl="${rl//?/../}"
522             mkdir -p "${rc%/*}"
523             ln -s $rl$r "${rc%/*}/${rc##*/}"
524             repo="$TOPDIR/SOURCES/repos/${rc%/*}/${rc##*/}/"
525         fi
526         if test "$imagetype" != product -a "$DO_INIT" != "false" ; then
527             echo "creating repodata for $repo"
528             if chroot $BUILD_ROOT createrepo --no-database --simple-md-filenames --help >/dev/null 2>&1 ; then
529                 chroot $BUILD_ROOT createrepo --no-database --simple-md-filenames "$repo"
530             else
531                 chroot $BUILD_ROOT createrepo "$repo"
532             fi
533         fi
534     done
535
536     # unpack root tar
537     for t in $BUILD_ROOT/$TOPDIR/SOURCES/root.tar* ; do
538         test -f $t || continue
539         mkdir -p $BUILD_ROOT/$TOPDIR/SOURCES/root
540         chroot $BUILD_ROOT tar -C $TOPDIR/SOURCES/root -xf "$TOPDIR/SOURCES/${t##*/}"
541     done
542
543     # fix script permissions
544     chmod a+x $BUILD_ROOT/$TOPDIR/SOURCES/*.sh 2>/dev/null
545
546     # unpack tar files in image directories
547     if test -d $BUILD_ROOT/$TOPDIR/SOURCES/images ; then
548         (
549         cd $BUILD_ROOT/$TOPDIR/SOURCES/images
550         for r in */* ; do
551             test -L $r && continue
552             test -d $r || continue
553             for t in $r/root.tar* ; do
554                 test -f $t || continue
555                 mkdir -p $r/root
556                 chroot $BUILD_ROOT tar -C $TOPDIR/SOURCES/images/$r/root -xf "$TOPDIR/SOURCES/images/$r/${t##*/}"
557             done
558             # fix script permissions
559             chmod a+x $BUILD_ROOT/$TOPDIR/SOURCES/images/$r/*.sh 2>/dev/null
560             # create compatibility link for old kiwi versions
561             rc="${r//:/:/}"
562             if test "$rc" != "$r" ; then
563                 rl="${rc//[^\/]}"
564                 rl="${rl//?/../}"
565                 mkdir -p "${rc%/*}"
566                 ln -s $rl$r "${rc%/*}/${rc##*/}"
567             fi
568         done
569         )
570     fi
571
572     rm -f $BUILD_ROOT/$TOPDIR/SOURCES/config.xml
573     ln -s $RECIPEFILE $BUILD_ROOT/$TOPDIR/SOURCES/config.xml
574
575     if test "$imagetype" = product ; then
576         build_kiwi_product
577     else
578         build_kiwi_appliance
579     fi
580
581     # Hook for running post kiwi build scripts like QA scripts if installed
582     if test -x $BUILD_ROOT/usr/lib/build/kiwi_post_run ; then
583         chroot $BUILD_ROOT su -c /usr/lib/build/kiwi_post_run || cleanup_and_exit 1
584     fi
585 }
586
587 recipe_resultdirs_kiwi() {
588     echo KIWI
589 }