#!/bin/sh
#=============================================================================#
#                         Release package                                     #
#=============================================================================#
# (c) Denis Smirnov <ds@seiros.ru>                               06 Feb 2007  #
#=============================================================================#
set +e
if [ ! -d .git ]; then
    echo "Yuo must run this script from root of git repo"
    exit -1
fi

# Add changelog to spec-file if not added before
cl-add *.spec
# 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

