#! /usr/bin/env bash

if [ ! -r eternal_lands_license.txt ]
then
	echo "Please run from the elc directory"
	exit
fi

if [ -z "$1" ]
then
	echo "Specify package name string"
	exit
fi
packagename="$1"
if [ -z "$2" ]
then
	echo "Specify version string"
	exit
fi
version="$2"

# make a temporary copy
echo "Making temp copy..."
tar cfz ../temp.${version}.tar.gz .
cd ..
mkdir ${packagename}-${version}
cd ${packagename}-${version}
tar xfz ../temp.${version}.tar.gz
rm ../temp.${version}.tar.gz

# remove stuff that's not required
echo "Removing unwanted files from copy..."
make -f Makefile.linux clean
rm -rf books map_editor pawn pawn_scripts shaders skybox \
		eye_candy/textures .deps macosx .git dev-data-files
rm -f *.pl *.res *.dsp *.dsw .git*
rm -f Makefile.bsd* Makefile.osx Makefile.win make.conf
chmod -R -x *.{c,cpp,h,hpp}

# make the Debian tar ball, then delete the Debian files
echo "Making Debian tarball..."
tar cfz ../${packagename}-debian-${version}.tar.gz debian
rm -rf debian

# make the final tar ball
echo "Making client source tarball..."
cd ..
tar cfz ${packagename}-${version}.tar.gz ${packagename}-${version}
rm -rf ${packagename}-${version}


# optionall create digital signatures
read -p "Create digital signatures? (y/n) [n] : " opt
if [ "$opt" = "Y" -a "$opt" = "y" ]
then
	gpg --armor --sign --detach-sig ${packagename}-${version}.tar.gz
	gpg --armor --sign --detach-sig ${packagename}-debian-${version}.tar.gz
fi

ls -l ${packagename}-${version}.tar.gz* ${packagename}-debian-${version}.tar.gz*


