#!/bin/sh
# Preparation :
# ===========
# This has to be done just ONCE: create an ~/.rpmmacros file with the following:
#    %_topdir /dev/shm/build
#    %debug_package %{nil}
#    %_signature gpg
#    %_gpg_name Convirture Corp (Key for package signing) <info@convirture.com>
#
# Where %_topdir is wherever you want your build tree to reside.
#
# To sign all rpms at location specfied by topdir location
#
# Usage : ./sign_rpms
#

# Sign using key if available
if [ "`grep _gpg_name ~/.rpmmacros`" != "" ]; then
  base=`dirname $0`
  RPM_LOC=`grep topdir ~/.rpmmacros | cut -d ' ' -f 2`
  VER=`grep Version $base/convirt.spec | cut -d ' ' -f 2`
  RPMS="$RPM_LOC/RPMS/*/convirt-$VER*.rpm $RPM_LOC/RPMS/*/convirt-kvm_only-$VER*.rpm"
  echo "Signing $RPMS"
  rpm --resign $RPMS
else
  echo 'ERROR : %_gpg_name not specified in ~/.rpmmacro file. RPMS not signed.'
  exit 1
fi
