#! /bin/sh
set -x
# check in y2image to /work/src/done/PPC
# it creates the initrd, used in k_deflt etc.
# call from the installation-images directory

ver=`cat VERSION`
y2image_tmpdir=/tmp/y2image-$ver
work_done=/work/src/done/PPC/y2image
work_SRC=/work/SRC/arch/ppc/y2image

if [ "$ver" = "" ] ; then
  echo "no version info?"
  exit 1
fi

echo "going to check in y2image version $ver..."

make clean
[ -e $y2image_tmpdir ] && rm -rf $y2image_tmpdir
mkdir $y2image_tmpdir || exit 1
tar -cf - * | tar -C $y2image_tmpdir -xf -
cd $y2image_tmpdir
find . -depth -name CVS -exec rm -r {} \;
find . -depth -name .cvsignore -exec rm -r {} \;
rm -rf bin/ci_* MAINTAINER cache data/boot/linux.loopc
cd /tmp

tar -jcf $y2image_tmpdir.tar.bz2 y2image-$ver

if [ "$1" = test ] ; then
  echo "y2image directory tree: $y2image_tmpdir"
  exit
fi

if mkdir $work_done ; then
  cd $work_done
  cp $y2image_tmpdir.tar.bz2 ${work_SRC}/y2image.{changes,spec} .
  [ -f ${work_SRC}/config-dist.sh ] && cp ${work_SRC}/config-dist.sh .
  perl -pi -e 's/^(Version:\s+)\S+/${1}'$ver'/' ${work_done}/y2image.spec
  perl -pi -e 's/^(Source.+-)\S+?(\.tar\.bz2)/${1}'$ver'${2}/' ${work_done}/y2image.spec
  sleep 2
  . /work/src/bin/.profile
  vc y2image
  rm -fv ${work_done}/*~
  pwd
  check_if_valid_source_dir
  echo "ok"
else
  echo oops
  exit 1
fi
