#!/bin/bash

MODE=$1
VERSION=`cat /source/VERSION`

cp -r /source/packaging/debian .
if [ $MODE = "snapshot" ]; then
	echo "Generating snapshot version in debian/"
	DEBEMAIL="dev@null" DEBFULLNAME="syslog-ng snapshot" debchange --newversion ${VERSION}-${MODE}+`date +%Y%m%dT%H%M%S` "Snapshot release based on ${GITREF}"
elif [ $MODE = "release" ]; then
	echo "Validating if your debian/ directory matches current version"
	DEB_VERSION=`dpkg-parsechangelog -S Version | cut -d - -f1`
	if [ "${DEB_VERSION}" != "${VERSION}" ]; then
		echo "The version numbers in debian/changelog do not match the current version number. Cannot generate a release tarball this way"
		exit 1
	fi
fi
