#!/bin/sh

repo="$1"
if test -z "$repo"; then
	echo "Usage: $0 git-repo [tag]"
	exit 1
fi
tag="$2"
dir="`basename $repo`"

test -z "$tag" || dir="$dir-$tag"

test -d "$dir" && exit 1
test -f "$dir.tbz2" && exit 1

git clone "$repo" "$dir"
cd "$dir"
git checkout -b "dist-`uuidgen`-$tag" "$tag"
cd -
rm -rf "$dir/.git"
tar cvjf "$dir.tbz2" "$dir"
rm -rf "$dir"

gpg --default-key BE8431FA -b -a "$dir.tbz2"

