#!/bin/sh
dir="tennis-mixer"

VERSION="$1"

if [ -z "$VERSION" ] ; then
   echo "Error: no VERSION found"
   echo "usage:"
   echo "$0 version"
   echo "e.g."
   echo "$0 2.4"
   exit 1
else
   echo "VERSION: $VERSION"
fi

js="tm/tm-$VERSION.js"
css="tm/tm-$VERSION.css"

if [ ! -f "$css" ] ; then
   echo "Not existent: $css"
   echo "Quitting..."
   exit 1
fi

if [ ! -f "$js" ] ; then
   echo "Not existent: $js"
   echo "Quitting..."
   exit 1
fi

checkversion=`cat tm/tm-$VERSION.js | awk '/const VERSION = /{print $4}' | tr -d '";'`

if [ "$checkversion" != "$VERSION" ] ; then
   echo "But version in tm/tm-$VERSION is: $checkversion"
   echo "Quitting..."
   exit 1
fi

zipfile="$dir-$VERSION.zip"
echo "zip file: $zipfile"
rm -rf $dir
mkdir $dir
cp -r \
   autosize \
   jquery \
   makezip \
   jqueryprint \
   index.html \
   languages.js \
   tm \
   gettext \
   $dir

rm -f $zipfile
zip -r $zipfile $dir
rm -rf "$dir"

echo "zip file: $zipfile"
