# create patch bundle

#date=$(date +"%y%m%d")
date=100209
src=../..

if [ $# != 2 ]; then
  echo "usage: $0 arch build"
  exit
fi

arch=$1
build=$arch-$2
#list=$(cd $src && ls PE71-[0-9]*-README | cut -d"-" -f1-2)
list=$(cat xlist)

rm -rf $arch
mkdir $arch
for p in $list
do
  if [ -f $src/$p-$arch.tar.gz ]; then
    p_src=$src
    p_file=$p-$arch
  elif [ -f $src/$p-$build.tar.gz ]; then
    p_src=$src
    p_file=$p-$build
# use fallback to hpux-pa11 for hpux-pa20 patches (query3k)
  elif [ $build = "hpux-pa20" -a -f $src/$p-hpux-pa11.tar.gz ]; then
    p_src=$src
    p_file=$p-hpux-pa11
  else
    echo "$p -- not found"
    continue
  fi
  echo $p_file
  tar -C $arch -xzf $p_src/$p_file.tar.gz
done

target=PE71-B$date-$build.tar.gz
echo "creating $target ..."
cd $arch
tar -czf ../$target *
cd ..
rm -rf $arch
tar tzvf $target
