#!/bin/sh

version=$2
orig_tgz=$(basename $3)
newdir=$(echo $orig_tgz | sed -e 's/.orig.tar.gz//' -e 's/_/-/')

wd=$(pwd)
cd ..
tar xzf $orig_tgz
mv SEELablet-$version $newdir

cd $newdir
# download the latest version of seelablet-apps
echo "Downloading applications"
wget https://github.com/jithinbp/SEELablet-apps/archive/master.tar.gz
tar xzf master.tar.gz
rm -f master.tar.gz
cd ..

rm $orig_tgz v${version}.tar.gz

orig_xz=$(echo $orig_tgz| sed 's/gz$/xz/')

tar cJf $orig_xz $newdir

echo "Created ../$orig_xz and ../$newdir"
