#!/bin/bash
set -x

# NOTE: This is rather specific to my setup :)

REL_DOT=`grep 'ACESS_VERSION =' Makefile.Version.cfg | sed -r 's/.*([0-9]+\.[0-9]+).*/\1/'`
REL=`echo $REL_DOT | sed -r 's/\.//g'`

_RELDIR=/home/http/www/Downloads/Acess2/

./MakeReleaseSet x86 smp
./MakeReleaseSet x86_64
./MakeReleaseSet armv7 realview_pb
./MakeReleaseSet armv7 tegra2

rm -f Releases/*_armv7-*.img.gz
for f in Releases/*.gz; do
	newname=${f/latest/$REL}
	cp $f $newname
done
cp Releases/* ${_RELDIR}

if [[ $# -lt 2 ]] || [[ "$1" != "-n" ]]; then
	git archive --format=tar --prefix=Acess2/ HEAD | gzip > ${_RELDIR}Acess2_git.tar.gz
	git tag rel${REL_DOT}
fi

cd ${_RELDIR}
cp Acess2_git.tar.gz Acess2_${REL}.tar.gz
rm Acess2.img.gz; ln -s Acess2_${REL}_x86.img.gz Acess2.img.gz
rm Acess2.tar.gz; ln -s Acess2_${REL}.tar.gz Acess2.tar.gz
