- also use --numeric-owner in bsdtar case
[platform/upstream/build.git] / build_kiwi.sh
index ee300f2..a825e16 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 ; 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
@@ -124,24 +124,32 @@ run_kiwi()
                    cat > $BUILD_ROOT/kiwi_post.sh << EOF
 echo "compressing oem images... "
 cd /$TOPDIR/KIWI-oem
-tar cvjfS "/$TOPDIR/KIWI/$imageout$buildnum-raw.tar.bz2" \
-       --exclude="$imageout.iso" --exclude="$imageout.raw" *
-
-cd /$TOPDIR/KIWI
-sha256sum "$imageout$buildnum-raw.tar.bz2" > "$imageout$buildnum-raw.tar.bz2.sha256"
-
 if [ -e "$imageout.iso" ]; then
        echo "take iso file and create sha256..."
        mv "$imageout.iso" "/$TOPDIR/KIWI/$imageout$buildnum.iso"
-       sha256sum "$imageout$buildnum.iso" > "$imageout$buildnum.iso.sha256"
+       pushd /$TOPDIR/KIWI
+       if [ -x /usr/bin/sha256sum ]; then
+           /usr/bin/sha256sum "$imageout$buildnum.iso" > "$imageout$buildnum.iso.sha256"
+        fi
+       popd
 fi
-
 if [ -e "$imageout.raw" ]; then
        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"
+       if [ -x /usr/bin/sha256sum ]; then
+           echo "Create sha256 file..."
+           /usr/bin/sha256sum "$imageout$buildnum.raw.bz2" > "$imageout$buildnum.raw.bz2.sha256"
+        fi
+       popd
+fi
+
+tar cvjfS "/$TOPDIR/KIWI/$imageout$buildnum-raw.tar.bz2" \
+       --exclude="$imageout.iso" --exclude="$imageout.raw" *
+cd /$TOPDIR/KIWI
+if [ -x /usr/bin/sha256sum ]; then
+   /usr/bin/sha256sum "$imageout$buildnum-raw.tar.bz2" > "$imageout$buildnum-raw.tar.bz2.sha256"
 fi
 EOF
                    ;;
@@ -150,17 +158,29 @@ EOF
 echo "compressing vmx images... "
 cd /$TOPDIR/KIWI-vmx
 # This option has a number of format parameters
-FILES=""
-for i in "$imageout.vmx" "$imageout.vmdk" "$imageout.ovf" "$imageout-disk*.vmdk" "$imageout.xenconfig" ; do
-       ls \$i >& /dev/null && FILES="\$FILES \$i"
+VMXFILES=""
+SHAFILES=""
+for i in "$imageout.vmx" "$imageout.vmdk" "$imageout-disk*.vmdk" "$imageout.ovf"; do
+       ls \$i >& /dev/null && VMXFILES="\$VMXFILES \$i"
 done
-# kiwi is not removing the .rar file, if a different output format is defined. Do not include it by default.
-[ -z "\$FILES" ] && FILES="$imageout.raw"
+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
+# FIXME: do we need a single .raw file in any case ?
 
 cd /$TOPDIR/KIWI
-tar cvjfS "$imageout$buildnum-vmx.tar.bz2" \$FILES
-echo "Create sha256 file..."
-sha256sum "$imageout$buildnum-vmx.tar.bz2" > "$imageout$buildnum-vmx.tar.bz2.sha256"
+if [ -n "\$SHAFILES" -a -x /usr/bin/sha256sum ]; then
+       for i in \$SHAFILES; do
+               echo "Create sha256 file..."
+               /usr/bin/sha256sum "\$i" > "\$i.sha256"
+       done
+fi
 EOF
                    ;;
                xen)
@@ -170,21 +190,26 @@ cd /$TOPDIR/KIWI-xen
 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"
+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)
@@ -193,11 +218,13 @@ 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"
-done
+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
                    ;;
                *)
@@ -205,13 +232,15 @@ EOF
 echo "compressing unkown images... "
 cd /$TOPDIR/KIWI-$imgtype
 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 -x -e /kiwi_post.sh" || cleanup_and_exit 1
            rm -f $BUILD_ROOT/kiwi_post.sh
        done
     fi