#!/bin/bash

MAJOR=`cat serial/major`
MINOR=`cat serial/minor`
RELEASE=`cat serial/release`
TOTRELEASE="$MAJOR.$MINOR.$RELEASE"

filebase="slt-$TOTRELEASE"
filename="$filebase.tar.gz"
outname="releases/$filename"
xmlname="releases/$filebase.xml"

mkdir -p releases

# First check if the named release exists already
if [ -f "$outname" ]; then
	echo "The file $outname existes already. Either remove the release from the folder manually or increase the release version."
	echo "Aborting."
	exit 1
fi

cp slt.tar.gz "$outname"

sha=$(sha512sum slt.tar.gz | cut -d' ' -f1)

export VERSION="$TOTRELEASE"
export FORMAT='tar.gz'
export DOWNLOAD_URL="\$DL_PREFIX/$filename"
export SUMS="<sha512>$sha</sha512>"

cat res/update.template | envsubst > "$xmlname"
