#! /bin/bash
set -e
tarball="$1"
if [ -z "$tarball" ];  then
  echo "tarball <gap_nopackages.zip>" 1>&2
  exit 1
fi
mkdir gap
unzip $tarball -d gap
cd gap
version=$(grep VERSIONNUMBER gap*/doc/versiondata | sed -e 's/^<!ENTITY VERSIONNUMBER "\([0-9]\).\([0-9]\).\([0-9]\)">/\1r\2p\3/')
test -z $version && echo "GAP version not found" && exit 1
echo "GAP version: $version"
mv gap* gap-$version
cd gap-$version
tar xf etc/tools.tar.gz
rm etc/tools.tar.gz
rm doc/gapmacrodoc.pdf
rm -r bin
rm extern/*.gz
mkdir ../gap-gdat-$version ../gap-gdat
mkdir ../gap-gdat/gap
mv prim small trans ../gap-gdat/gap
mkdir prim small trans
cp ../gap-gdat/gap/prim/*.gd prim
cp ../gap-gdat/gap/small/*.gd small
cp ../gap-gdat/gap/trans/*.gd trans
cd ..
tar zcf gap-gdat-$version/gap-gdat.tar.gz -C gap-gdat gap
tar zcf gap-gdat_$version.orig.tar.gz gap-gdat-$version
tar zcf gap_$version.orig.tar.gz gap-$version
