force enable DO_CUMULATE
[platform/upstream/build.git] / build_kiwi.sh
index 36d7cb4..c480da6 100644 (file)
@@ -5,30 +5,30 @@ run_kiwi()
     imagename=$(perl -I$BUILD_DIR -MBuild::Kiwi -e Build::Kiwi::show $BUILD_ROOT/$TOPDIR/SOURCES/$SPECFILE filename)
     imageversion=$(perl -I$BUILD_DIR -MBuild::Kiwi -e Build::Kiwi::show $BUILD_ROOT/$TOPDIR/SOURCES/$SPECFILE version)
     # prepare rpms as source and createrepo on the repositories
-    if test -d $BUILD_ROOT/$TOPDIR/SOURCES/repos -a "$DO_INIT" != false ; then
-       (
-       ln -sf $TOPDIR/SOURCES/repos $BUILD_ROOT/repos
-       cd $BUILD_ROOT/$TOPDIR/SOURCES/repos
-       for r in */* ; do
-           test -L $r && continue
-           test -d $r || continue
-           repo="$TOPDIR/SOURCES/repos/$r/"
-           # create compatibility link for old kiwi versions
-           rc="${r//:/:/}"
-           if test "$rc" != "$r" ; then
-               rl="${rc//[^\/]}"
-               rl="${rl//?/../}"
-               mkdir -p "${rc%/*}"
-               ln -s $rl$r "${rc%/*}/${rc##*/}"
-               repo="$TOPDIR/SOURCES/repos/${rc%/*}/${rc##*/}/"
-           fi
-           if test "$imagetype" != product ; then
-               echo "creating repodata for $repo"
+    ln -sf $TOPDIR/SOURCES/repos $BUILD_ROOT/repos
+    cd $BUILD_ROOT/$TOPDIR/SOURCES/repos
+    for r in */* ; do
+        test -L $r && continue
+        test -d $r || continue
+        repo="$TOPDIR/SOURCES/repos/$r/"
+        # create compatibility link for old kiwi versions
+        rc="${r//:/:/}"
+        if test "$rc" != "$r" ; then
+       rl="${rc//[^\/]}"
+       rl="${rl//?/../}"
+       mkdir -p "${rc%/*}"
+       ln -s $rl$r "${rc%/*}/${rc##*/}"
+       repo="$TOPDIR/SOURCES/repos/${rc%/*}/${rc##*/}/"
+        fi
+        if test "$imagetype" != product -a "$DO_INIT" != "false" ; then
+           echo "creating repodata for $repo"
+           if chroot $BUILD_ROOT createrepo --simple-md-filenames --help >/dev/null 2>&1 ; then
+               chroot $BUILD_ROOT createrepo --simple-md-filenames "$repo"
+           else
                chroot $BUILD_ROOT createrepo "$repo"
            fi
-       done
-       )
-    fi
+        fi
+    done
     # unpack root tar
     for t in $BUILD_ROOT/$TOPDIR/SOURCES/root.tar* ; do
        test -f $t || continue
@@ -64,22 +64,34 @@ run_kiwi()
     fi
     rm -f $BUILD_ROOT/$TOPDIR/SOURCES/config.xml
     ln -s $SPECFILE $BUILD_ROOT/$TOPDIR/SOURCES/config.xml
-    chroot $BUILD_ROOT su -c "kiwi --version" -
     if test "$imagetype" = product ; then
        echo "running kiwi --create-instsource..."
        # runs always as abuild user
        mkdir -p "$BUILD_ROOT/$TOPDIR/KIWIROOT"
        chroot "$BUILD_ROOT" chown -R abuild.abuild "$TOPDIR"
-       # --instsource-local is only needed for openSUSE 11.1 and SLE 11 SP0 kiwi.
-       chroot "$BUILD_ROOT" su -c "APPID=- LANG=POSIX /usr/sbin/kiwi --root $TOPDIR/KIWIROOT -v -v --logfile terminal -p $TOPDIR/SOURCES --instsource-local --create-instsource $TOPDIR/SOURCES" - abuild < /dev/null && BUILD_SUCCEEDED=true
-### This block is obsolete with current kiwi versions, only needed for kiwi 3.01 version
-#            for i in $BUILD_ROOT/$TOPDIR/KIWIROOT/main/* ; do
-#                test -d "$i" || continue
-#                n="${i##*/}"
-#                test "$n" = scripts && continue
-#                test "$n" != "${n%0}" && continue
-#                chroot $BUILD_ROOT su -c "suse-isolinux $TOPDIR/KIWIROOT/main/$n $TOPDIR/KIWI/$n.iso" - $BUILD_USER
-#            done
+       ver=`chroot "$BUILD_ROOT" su -c "/usr/sbin/kiwi --version | sed -n 's,.*kiwi version v\(.*\),\1,p'"`
+        if [ ${ver:0:1} == "3" ]; then
+          # old style kiwi 3 builds
+         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
+          if [ ${ver:2:2} == "01" ]; then
+            ## This block is obsolete with current kiwi versions, only needed for kiwi 3.01 version
+            for i in $BUILD_ROOT/$TOPDIR/KIWIROOT/main/* ; do
+                test -d "$i" || continue
+                n="${i##*/}"
+                test "$n" = scripts && continue
+                test "$n" != "${n%0}" && continue
+                chroot $BUILD_ROOT su -c "suse-isolinux $TOPDIR/KIWIROOT/main/$n $TOPDIR/KIWI/$n.iso" - $BUILD_USER
+            done
+          fi
+        else
+          if [ ${ver:0:1} == "4" -a ${ver:2:2} -lt 90 ]; then
+            # broken kiwi version, not accepting verbose level
+           chroot "$BUILD_ROOT" su -c "APPID=- LANG=POSIX /usr/sbin/kiwi --root $TOPDIR/KIWIROOT -v -v --logfile terminal -p $TOPDIR/SOURCES --create-instsource $TOPDIR/SOURCES" - abuild < /dev/null && BUILD_SUCCEEDED=true
+          else
+            # current default
+           chroot "$BUILD_ROOT" su -c "APPID=- LANG=POSIX /usr/sbin/kiwi --root $TOPDIR/KIWIROOT -v 2 --logfile terminal -p $TOPDIR/SOURCES --create-instsource $TOPDIR/SOURCES" - abuild < /dev/null && BUILD_SUCCEEDED=true
+          fi
+        fi
 
        # move created product to correct destination
        for i in $BUILD_ROOT/$TOPDIR/KIWIROOT/main/* ; do
@@ -124,58 +136,93 @@ run_kiwi()
                    cat > $BUILD_ROOT/kiwi_post.sh << EOF
 echo "compressing oem images... "
 cd /$TOPDIR/KIWI-oem
+# do not store compressed file _and_ uncompressed one
+[ -e "$imageout.gz" ] && rm -f "$imageout"
 if [ -e "$imageout.iso" ]; then
        echo "take iso file and create sha256..."
        mv "$imageout.iso" "/$TOPDIR/KIWI/$imageout$buildnum.iso"
        pushd /$TOPDIR/KIWI
-       sha256sum "$imageout$buildnum.iso" > "$imageout$buildnum.iso.sha256"
+       if [ -x /usr/bin/sha256sum ]; then
+           /usr/bin/sha256sum "$imageout$buildnum.iso" > "$imageout$buildnum.iso.sha256"
+        fi
+       popd
+fi
+if [ -e "$imageout.qcow2" ]; then
+       mv "$imageout.qcow2" "/$TOPDIR/KIWI/$imageout$buildnum.qcow2"
+       pushd /$TOPDIR/KIWI
+       if [ -x /usr/bin/sha256sum ]; then
+           echo "Create sha256 file..."
+           /usr/bin/sha256sum "$imageout$buildnum.qcow2" > "$imageout$buildnum.qcow2.sha256"
+        fi
        popd
 fi
 if [ -e "$imageout.raw" ]; then
+        compress_tool="bzip2"
+        compress_suffix="bz2"
+       if [ -x /usr/bin/xz ]; then
+            # take xz to get support for sparse files
+            compress_tool="xz -2"
+            compress_suffix="xz"
+        fi
        mv "$imageout.raw" "/$TOPDIR/KIWI/$imageout$buildnum.raw"
        pushd /$TOPDIR/KIWI
-       echo "bzip2 raw file..."
-       bzip2 "$imageout$buildnum.raw"
-       echo "Create sha256 file..."
-       sha256sum "$imageout$buildnum.raw.bz2" > "$imageout$buildnum.raw.bz2.sha256"
+       echo "\$compress_tool raw file..."
+       \$compress_tool "$imageout$buildnum.raw"
+       if [ -x /usr/bin/sha256sum ]; then
+           echo "Create sha256 file..."
+           /usr/bin/sha256sum "$imageout$buildnum.raw.\${compress_suffix}" > "$imageout$buildnum.raw.\${compress_suffix}.sha256"
+        fi
        popd
 fi
 
 tar cvjfS "/$TOPDIR/KIWI/$imageout$buildnum-raw.tar.bz2" \
-       --exclude="$imageout.iso" --exclude="$imageout.raw" *
+       --exclude="$imageout.iso" --exclude="$imageout.raw" --exclude="$imageout.qcow2" *
 cd /$TOPDIR/KIWI
-sha256sum "$imageout$buildnum-raw.tar.bz2" > "$imageout$buildnum-raw.tar.bz2.sha256"
+if [ -x /usr/bin/sha256sum ]; then
+   /usr/bin/sha256sum "$imageout$buildnum-raw.tar.bz2" > "$imageout$buildnum-raw.tar.bz2.sha256"
+fi
 EOF
                    ;;
                vmx)
                    cat > $BUILD_ROOT/kiwi_post.sh << EOF
 echo "compressing vmx images... "
 cd /$TOPDIR/KIWI-vmx
+for suffix in "ovf" "qcow2"; do
+  if [ -e "$imageout.\$suffix" ]; then
+       mv "$imageout.\$suffix" "/$TOPDIR/KIWI/$imageout$buildnum.\$suffix"
+       pushd /$TOPDIR/KIWI
+       if [ -x /usr/bin/sha256sum ]; then
+           echo "Create sha256 \$suffix file..."
+           /usr/bin/sha256sum "$imageout$buildnum.\$suffix" > "$imageout$buildnum.\$suffix.sha256"
+        fi
+       popd
+  fi
+done
 # This option has a number of format parameters
 VMXFILES=""
 SHAFILES=""
 for i in "$imageout.vmx" "$imageout.vmdk" "$imageout-disk*.vmdk"; do
-       ls \$i >& /dev/null && VMXFILES="\$VMXFILES \$i"
+       test -e \$i && VMXFILES="\$VMXFILES \$i"
 done
+# take raw files as fallback
+if [ -z "\$VMXFILES" ]; then
+       test -e "$imageout.raw" && VMXFILES="$imageout.raw"
+fi
 if [ -n "\$VMXFILES" ]; then
        tar cvjfS "/$TOPDIR/KIWI/$imageout$buildnum-vmx.tar.bz2" \$VMXFILES
        SHAFILES="\$SHAFILES $imageout$buildnum-vmx.tar.bz2"
 fi
-
 if [ -e "$imageout.xenconfig" ]; then
        tar cvjfS "/$TOPDIR/KIWI/$imageout$buildnum-vmx.tar.bz2" $imageout.xenconfig $imageout.raw initrd-*
        SHAFILES="\$SHAFILES $imageout$buildnum-vmx.tar.bz2"
 fi
-for i in "$imageout.ovf"; do
-       [ -e \$i ] && SHAFILES="\$SHAFILES \$i"
-done
 # FIXME: do we need a single .raw file in any case ?
 
 cd /$TOPDIR/KIWI
-if [ -n "\$SHAFILES" ]; then
+if [ -n "\$SHAFILES" -a -x /usr/bin/sha256sum ]; then
        for i in \$SHAFILES; do
                echo "Create sha256 file..."
-               sha256sum "\$i" > "\$i.sha256"
+               /usr/bin/sha256sum "\$i" > "\$i.sha256"
        done
 fi
 EOF
@@ -184,25 +231,33 @@ EOF
                    cat > $BUILD_ROOT/kiwi_post.sh << EOF
 echo "compressing xen images... "
 cd /$TOPDIR/KIWI-xen
+# do not store compressed file _and_ uncompressed one
+[ -e "$imageout.gz" ] && rm -f "$imageout"
 tar cvjfS "/$TOPDIR/KIWI/$imageout$buildnum-xen.tar.bz2" \
        `grep ^kernel $imageout.xenconfig | cut -d'"'  -f2` \
        `grep ^ramdisk $imageout.xenconfig | cut -d'"'  -f2` \
        initrd-* \
        "$imageout.xenconfig" \
        "$imageout"
-echo "Create sha256 file..."
-cd $TOPDIR/KIWI
-sha256sum "$imageout$buildnum-xen.tar.bz2" > "$imageout$buildnum-xen.tar.bz2.sha256"
+if [ -x /usr/bin/sha256sum ]; then
+   echo "Create sha256 file..."
+   cd $TOPDIR/KIWI
+   /usr/bin/sha256sum "$imageout$buildnum-xen.tar.bz2" > "$imageout$buildnum-xen.tar.bz2.sha256"
+fi
 EOF
                    ;;
                pxe)
                    cat > $BUILD_ROOT/kiwi_post.sh << EOF
 echo "compressing pxe images... "
 cd /$TOPDIR/KIWI-pxe
-tar cvjfS "/$TOPDIR/KIWI/$imageout$buildnum-pxe.tar.bz2" "$imageout"* initrd-*"
-echo "Create sha256 file..."
-cd $TOPDIR/KIWI
-sha256sum "$imageout$buildnum-pxe.tar.bz2" > "$imageout$buildnum-pxe.tar.bz2.sha256"
+# do not store compressed file _and_ uncompressed one
+[ -e "$imageout.gz" ] && rm -f "$imageout"
+tar cvjfS "/$TOPDIR/KIWI/$imageout$buildnum-pxe.tar.bz2" ${imageout}* initrd-*
+if [ -x /usr/bin/sha256sum ]; then
+   echo "Create sha256 file..."
+   cd $TOPDIR/KIWI
+   /usr/bin/sha256sum "$imageout$buildnum-pxe.tar.bz2" > "$imageout$buildnum-pxe.tar.bz2.sha256"
+fi
 EOF
                    ;;
                iso)
@@ -211,26 +266,53 @@ cd /$TOPDIR/KIWI-iso
 for i in *.iso; do
        mv "\$i" "/$TOPDIR/KIWI/\${i%.iso}$buildnum.iso"
 done
-echo "creating sha256 sum for iso images... "
-cd $TOPDIR/KIWI
-for i in *.iso; do
-       sha256sum "\$i" > "\$i.sha256"
+if [ -x /usr/bin/sha256sum ]; then
+   echo "creating sha256 sum for iso images... "
+   cd $TOPDIR/KIWI
+   for i in *.iso; do
+       /usr/bin/sha256sum "\$i" > "\$i.sha256"
+   done
+fi
+EOF
+                   ;;
+               tbz)
+                   cat > $BUILD_ROOT/kiwi_post.sh << EOF
+cd /$TOPDIR/KIWI-tbz
+for i in *.tbz; do
+        file=\$(readlink -f "\$i")
+        [ -z "\$file" ] && echo readlink failed for $i
+       mv "\$file" "/$TOPDIR/KIWI/\${i%.tbz}$buildnum.tbz"
 done
+if [ -x /usr/bin/sha256sum ]; then
+   echo "creating sha256 sum for tar balls... "
+   cd $TOPDIR/KIWI
+   for i in *.tbz; do
+       /usr/bin/sha256sum "\$i" > "\$i.sha256"
+   done
+fi
 EOF
                    ;;
                *)
                    cat > $BUILD_ROOT/kiwi_post.sh << EOF
 echo "compressing unkown images... "
 cd /$TOPDIR/KIWI-$imgtype
+# do not store compressed file _and_ uncompressed one
+[ -e "$imageout.gz" ] && rm -f "$imageout"
 tar cvjfS "/$TOPDIR/KIWI/$imageout$buildnum-$imgtype.tar.bz2" *
-echo "Create sha256 file..."
-cd /$TOPDIR/KIWI
-sha256sum "$imageout$buildnum-$imgtype.tar.bz2" > "$imageout$buildnum-$imgtype.tar.bz2.sha256"
+if [ -x /usr/bin/sha256sum ]; then
+   echo "Create sha256 file..."
+   cd /$TOPDIR/KIWI
+   /usr/bin/sha256sum "$imageout$buildnum-$imgtype.tar.bz2" > "$imageout$buildnum-$imgtype.tar.bz2.sha256"
+fi
 EOF
                    ;;
            esac
-           chroot $BUILD_ROOT su -c "sh -e -x /kiwi_post.sh" || cleanup_and_exit 1
+           chroot $BUILD_ROOT su -c "sh -e /kiwi_post.sh" || cleanup_and_exit 1
            rm -f $BUILD_ROOT/kiwi_post.sh
        done
     fi
+    # Hook for running post kiwi build scripts like QA scripts if installed
+    if [ -x $BUILD_ROOT/usr/lib/build/kiwi_post_run ]; then
+        chroot $BUILD_ROOT su -c /usr/lib/build/kiwi_post_run || cleanup_and_exit 1
+    fi
 }