#!/bin/sh
# Make a monolithic DaCHS distribution and put it on GAVO's software
# distribution page.
# This is probably not useful outside GAVO development.
# Call this from the root of a repo checkout.

is_release() {
	# return 0 if the argument just has a single dot, 1 else.
	if [ t$(echo "$1" | sed -e 's/[^.]//g') = 't.' ]; then
		return 0
	else
		return 1
	fi
}

DIST_SERVER=alnilam
SERVER_DIR=/var/www/soft/dist
LOCAL_PKG_DIR=~/gavo/tarballs

if [ ! -f setup.py ]; then
	echo "This must be called from the root of a repository checkout."
	exit 1
fi

distVersion=`python setup.py --version`
distName="gavodachs-${distVersion}.tar.gz"

python setup.py sdist
scp "dist/$distName" ${DIST_SERVER}:${SERVER_DIR}

# dump a gpb-ready tarball in $LOCAL_PKG_DIR/tarballs
if [ -d "$LOCAL_PKG_DIR" ]; then
	cp "dist/$distName" "$LOCAL_PKG_DIR"/gavodachs_${distVersion}.orig.tar.gz
fi

if is_release $distVersion; then
	ssh $DIST_SERVER "ln -sf $SERVER_DIR/$distName $SERVER_DIR/gavodachs-latest.tar.gz"
fi
