#!/bin/bash -e
#=============================================================================#
#                         Release package                                     #
#=============================================================================#
# (c) Denis Smirnov <mithraen@freesource.info>                   06 Feb 2007  #
#=============================================================================#
ssh-alt
# TODO: add support for branch repos
if [ ! -d .git ]; then
    echo "You must run this script from root of git repo"
    exit -1
fi

# Add changelog to spec-file if not added before
cl-edit --add
# Commit this version
gear-commit -a

# Sync with this repo at alt
#git pull

# Get version
VERSION=`rpmbuild -bE *.spec | grep Version: | sed 's/Version:[[:space:]]*//' | head -n1`
RELEASE=`rpmbuild -bE *.spec | grep Release: | sed 's/Release:[[:space:]]*//' | head -n1`
PACKAGE=`rpmbuild -bE *.spec | grep Name: | sed 's/Name:[[:space:]]*//' | head -n1`

echo "$VERSION-$RELEASE $PACKAGE"
rpmbs *.spec
git tag -s -m "$PACKAGE/$VERSION-$RELEASE" "$PACKAGE/$VERSION-$RELEASE"
git push
git push --tags
git prune
git repack -a -d
