File SLE_wrapper of Package product-builder.12532

#!/bin/bash

set -xe

case "$BUILD_FLAVOR" in
  SLES-cd-Packages-DVD-*)
    PP=""

    TOPDIR=/usr/src/packages/
    cd $TOPDIR/SOURCES/ || exit 1
    mkdir $TOPDIR/KIWIRESULTS

    # remove symlink, we cat into it
    rm config.xml
    BUILD=`sed -ne "s/.*name=\"BUILD_ID\">\([^<]*\)<.*/\1/p" $BUILD_FLAVOR.kiwi`
    BUILD=${BUILD##*-}
    # the worker expands obsrepositories:// only in the target kiwi so we need to apply this change to the modules
    perl -e '$in=0; while (<STDIN>) { $in=1 if /<instrepo /; print $_ if $in; $in=0 if m,</instrepo,; }' < $BUILD_FLAVOR.kiwi > expanded_instsources.include

    ARCH=${BUILD_FLAVOR/SLES-cd-Packages-DVD-}

    rm -rf $TOPDIR/KIWIALL
    mkdir $TOPDIR/KIWIALL
    ls -1
    for kiwi in *-$ARCH.kiwi; do
      MN=`sed -ne "s/.*name=\"MEDIUM_NAME\">\([^<]*\)<.*/\1/p" $kiwi`

      MN_SHORT=${MN%-POOL-*}
      ARCH=${MN#*-POOL-}
      case $MN in
        *-Product*) PP=${MN%-Product-*} ;;
        *-Module*) PP=${MN%-Module-*} ;;
      esac
      grep -qx $MN_SHORT packages-dvd.txt || continue

      # replace obsrepositories://
      perl -e '$in=0; while (<STDIN>) { $in=1 if /<instrepo /; print $_ unless $in; if (m,</instrepo,) { $in=0; system("cat expanded_instsources.include") }; }' < $kiwi > config.xml

      rm -rf $TOPDIR/KIWIROOT

      /usr/bin/product-builder.pl --root $TOPDIR/KIWIROOT/ -v 1 --logfile terminal --create-instsource . || exit 1
      mv $TOPDIR/KIWIROOT/main $TOPDIR/KIWIALL/$MN_SHORT
      rm -rf $TOPDIR/KIWIROOT
      for medfile in $TOPDIR/$MN_SHORT/*/media.?/media ; do
        test -f $medfile || continue
        test -n "$BUILD" || BUILD=`grep " " $medfile | sed -e "s@^.*\(-Build[0-9\.]*\)-.*@\1@"`
      done # medfile
    done # kiwiconf

    test -z "$BUILD" && BUILD="Build0000"

    # copy together
    mkdir $TOPDIR/KIWIROOT
    mkdir $TOPDIR/KIWIROOT/main
    for MEDIUM in 1 2 3 ; do
      ISODIR=$PP-Packages-$ARCH-$BUILD-Media$MEDIUM
      ISONAME=$ISODIR.iso
      mkdir $TOPDIR/KIWIROOT/main/$ISODIR
      mkdir $TOPDIR/KIWIROOT/main/$ISODIR/media.1
      {
        echo "SUSE - $ISONAME"
        echo "$ISONAME"
        echo "1"
      } > $TOPDIR/KIWIROOT/main/$ISODIR/media.1/media
      echo "<report>" > $TOPDIR/KIWIRESULTS/$ISODIR.report
      for MOD in `cat packages-dvd.txt` ; do
        MOD_X=${MOD#*-*-*-}
        test -d $TOPDIR/KIWIALL/$MOD || continue
        test -f $TOPDIR/KIWIALL/$MOD/$MOD-POOL-$ARCH$MEDIUM.report && \
          grep -vxE "</?report>" $TOPDIR/KIWIALL/$MOD/$MOD-POOL-$ARCH$MEDIUM.report \
          >> $TOPDIR/KIWIRESULTS/$ISODIR.report
        test -f $TOPDIR/KIWIALL/$MOD/$MOD-POOL-$ARCH$MEDIUM/repodata/repomd.xml || continue
        mv $TOPDIR/KIWIALL/$MOD/$MOD-POOL-$ARCH$MEDIUM $TOPDIR/KIWIROOT/main/$ISODIR/$MOD_X
        sed -e "s@^/@/$MOD_X@g" $TOPDIR/KIWIROOT/main/$ISODIR/$MOD_X/media.1/products \
          >> $TOPDIR/KIWIROOT/main/$ISODIR/media.1/products
      done # MOD
      echo "</report>" >> $TOPDIR/KIWIRESULTS/$ISODIR.report
      VOLID=$PP-Packages-$ARCH-$BUILD-Media$MEDIUM
      VOLID=${VOLID:0:32}
      ISO=$TOPDIR/KIWIRESULTS/$ISONAME
      MEDIA=$TOPDIR/KIWIROOT/main/$ISODIR
      mkisofs -quiet -p "CD-Team, http://bugs.opensuse.org/" -publisher "SUSE Linux GmbH" -r -pad -A "${ISONAME%.iso}" -V "$VOLID" -J -joliet-long -o $ISO $MEDIA
      tagmedia --digest sha256 $ISO
      pushd $TOPDIR/KIWIRESULTS >/dev/null 2>&1
      sha256sum $ISONAME > $ISONAME.sha256 || exit 1
      popd >/dev/null 2>&1
    done # MEDIUM

    rm -rf $TOPDIR/KIWIROOT
    mkdir $TOPDIR/KIWIROOT
    mkdir $TOPDIR/KIWIROOT/main
    mv $TOPDIR/KIWIRESULTS/* $TOPDIR/KIWIROOT/main

    exit 0
    ;;
  *)
    exec /usr/bin/product-builder.pl $@
    ;;
esac
openSUSE Build Service is sponsored by