#!/bin/sh
dir="multi-scheduler"

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="ts/ts-$VERSION.js"
css="ts/ts-$VERSION.css"
index="index-$VERSION.html"

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

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 ts/ts-$VERSION.js | awk '/const VERSION = /{print $4}' | tr -d '";'`

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

zipfile="$dir-$VERSION.zip"
echo "zip file: $zipfile"
rm -rf $dir
mkdir $dir
cp -r \
   autosize \
   css \
   jquery \
   LICENSE* \
   spinkit \
   licenses.txt \
   makezip \
   README.txt \
   simplepicker \
   simplepicker-1.0.1.js \
   jqueryprint \
   ts.html \
   index-"$VERSION".html \
   languages.js \
   gettext \
   po2json \
   *.po \
   makelanguages \
   $dir

mkdir "$dir/ts" || exit 1
cp ts/ts-"$VERSION".js "$dir/ts" || exit 1
cp ts/ts-"$VERSION".css "$dir/ts" || exit 1

cp $dir/index-"$VERSION".html $dir/index.html
cp $dir/index-"$VERSION".html $dir/ts.html
rm -f $zipfile
zip -r $zipfile $dir
rm -rf "$dir"

echo "zip file: $zipfile"
