#!/bin/sh
#
# Copyright (c) 2002 Red Hat, Inc. All rights reserved.
#
# This software may be freely redistributed under the terms of the
# GNU General Public License.
#
# 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., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# Component of: Red Hat Database Administrator
#
# Simple wrapper for rhdb-admin
#
# Authors: Liam Stewart <liams@redhat.com> & Neil Padgett <npadgett@redhat.com>

cmd=./rhdb-admin.tcl
workdir=/usr/share/rhdb-admin
logfile=/dev/null
logstdout=no

while getopts ":l:" option
do
	case $option in
		l)
			if [ "$OPTARG" = "-" ];
			then
				logstdout=yes
			else
				# Roberto Mello for Debian:
				# Replaced the python call below with shell
				# equivalent to get rid of python dependence.
				#
				#logfile=`python -c "from os.path import abspath; print abspath(\"$OPTARG\")"`
				
				if [ `dirname $OPTARG` = "." ];
				then
					logfile="$PWD/$OPTARG"
				else
					logfile=$OPTARG
				fi
			fi
			;;
		*)
			echo "Invalid option: -$OPTARG"
			exit 1
			;;
	esac
done

# Roberto Mello - Removed calls to pushd and popd to be sh-compliant

if [ "$logstdout" = "yes" ];
then
	(cd $workdir; exec ${cmd} 2>&1)
else
	(cd $workdir; exec ${cmd} > ${logfile} 2>&1)
fi
