#!/bin/sh
set -x
set -e

export PATH=/usr/local/go/bin:$PATH

PACKAGE=github.com/dotcloud/docker

if [ $# -gt 1 ]; then
	echo "Usage: $0 [REVISION]"
	exit 1
fi

export REVISION=$1

if [ -z "$AWS_ID" -o -z "$AWS_KEY" ]; then
	echo "Warning: either AWS_ID or AWS_KEY environment variable not set. Won't upload to S3."
else
	/bin/echo -e "[default]\naccess_key = $AWS_ID\nsecret_key = $AWS_KEY\n" > /.s3cfg
fi

if [ -z "$GPG_KEY" ]; then
	echo "Warning: environment variable GPG_KEY is not set. Ubuntu package upload will not succeed."
	NO_UBUNTU=1
fi

rm -fr docker-release
git clone https://github.com/dotcloud/docker docker-release
cd docker-release
if [ -z "$REVISION" ]; then
	make release
else
	make release RELEASE_VERSION=$REVISION
fi

# Remove credentials from container
rm -f /.s3cfg

if [ -z "$NO_UBUNTU" ]; then
	export PATH=`echo $PATH | sed 's#/usr/local/go/bin:##g'`
	(cd packaging/ubuntu && make ubuntu)
fi
