#! /bin/sh
# $Id: rpm-wrap,v 1.3 2003/12/05 01:16:22 ensc Exp $

# Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
#  
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#  
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#  
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.


test -z "$DEBUG" || set -x

. /etc/sysconfig/fedora.us-build

{ echo "$@"; set ; } >/tmp/rpm-wrap.$$

root=
suffix=
function findRoot
{
    while test "$#" -gt 0; do
	case "$1" in
	    -r|--root)  root=$(basename $2); shift;;
	    -U*|-i*)	suffix=.i;;
	    --initdb)	suffix=.db;;
	    -q*)	suffix=.q;;
	esac
	shift
    done
}

findRoot "$@"

case "$root" in
    redhat-80*|redhat-7*)	prog=$PROGRAM_RPM73;;
    redhat-9*)			prog=$PROGRAM_RPM9;;
    *)				prog=
esac


for i in "${prog:+$prog$suffix}" "$prog"; do
    test -x "$i" || continue
    prog=$i
    break
done

exec ${prog:-rpm} "$@"
