#!/bin/sh
# 2006, 2008 (c) Etersoft www.etersoft.ru
# Author: Vitaly Lipatov <lav@etersoft.ru>
# Public domain
# 
# Обновляет версию пакета, получает исходники,
# собирает, устанавливает на тестирование и выкладывает новую версию пакета:
# rpmrb спек версия [релиз]
# версия может быть указана как 2.6.1 (полная), 2.6 (major) или .1 (minor)

# load common functions, compatible with local and installed script
. `dirname $0`/../share/eterbuild/functions/common
load_mod spec git

REMOTE=
if [ "$1" = "-r" ] ; then
	REMOTE=$1
	shift
fi

set_girar_host $1 && shift

SPEC=$1
VER=$2
# need for rpmgs
GSSETRELEASE=$3
test -n "$GSSETRELEASE" || GSSETRELEASE=alt1
export GSSETRELEASE

if [ "$1" = "-h" ]; then
	echog "rpmrb - update spec to vermajor.verminor version, build %rel release"
	echog "Usage: rpmrb spec [vermajor][.verminor] [rel]"
	echog "Example: rpmrb name.spec 22.6 alt2"
	exit 0
fi

test -f "$SPEC" || SPEC=$(get_gear_spec)

$ETERBUILDBIN/rpmgs $SPEC $VER || fatal "Error with get source"
add_changelog_helper "- new version $(get_version $SPEC) (with rpmrb script)" $SPEC || echog "Changelog entry already exists"

if is_gear ; then
	#git diff $SPEC
	git_commit_ignore_nothing $SPEC -m "update spec to new build $(get_version $SPEC) (with rpmrb script)" || exit 1
fi

$ETERBUILDBIN/rpmbsh $REMOTE -i $SPEC || fatal "Error with build in hasher"
$ETERBUILDBIN/rpmbs $GIRARHOST -u $SPEC || fatal "Error with upload"
