#!/bin/bash

VERSION=$1

if [[ -z $VERSION ]];then
    echo "Usage: tarver.sh [version]"
    exit 1
fi

dbf=$(fossil info|grep repository:|awk '{print $2}')

mkdir -p /tmp/$USER/mtbuild

pushd /tmp/$USER/mtbuild

if [[ -e $VERSION ]];then
    echo "Cleaning out old /tmp copy of Megatest $VERSION"
    rm -rf /tmp/$USER/mtbuild/$VERSION
fi

mkdir -p /tmp/$USER/mtbuild/$VERSION
cd /tmp/$USER/mtbuild/$VERSION

fossil open $dbf $VERSION

make megatest-fossil-hash.scm

cp .fslckout ../.fslckout-$VERSION
rm .fslckout
cd ..

tar cfvz megatest-$VERSION.tar.gz $VERSION
popd

cp /tmp/$USER/mtbuild/megatest-$VERSION.tar.gz .
fossil uv add megatest-$VERSION.tar.gz
rm megatest-$VERSION.tar.gz

