#!/bin/sh
# $Id$
#
# y2tool - Start a YaST2 tool from the YaST2 tool path
#
# Author: Stefan Hundhammer <sh@suse.de>
# (c) SuSE GmbH 2001
#

self=`basename $0`

if [ "$1" = "--prefix" -o "$1" = "-p" ]; then
    shift
    PREFIX="$1"
    shift
fi

# run the tools that are in the same prefix as we are
if [ -z "$PREFIX" ]; then
    PREFIX=${0%/bin/$self}
fi

y2toolpath=${PREFIX}/share/YaST2/data/devtools/bin
if [ `dirname $0` = "." ]; then
    y2toolpath=.
# another bootstrapping yuck. *hack*
elif [ "$0" = "devtools/bin/y2tool" ]; then
    y2toolpath=devtools/bin
fi

cmd=$1
shift

if [ "$cmd" = "--help" -o "$cmd" = "-h" ]; then
    cd $y2toolpath
    ls
    exit 0
fi

if [ -z $cmd ]; then
    echo ""							>&2
    echo "Usage: ${self} [--prefix <prefix>] [--help] <command> [<arg> ...]">&2
    echo ""							>&2
    echo "Starts a YaST2 tool from '$y2toolpath'."		>&2
    echo ""							>&2
    exit 1
fi


if [ -x $y2toolpath/$cmd ]; then
    $y2toolpath/$cmd "$@"
else
    echo "${self}: Can't find \"$cmd\" in $y2toolpath"	>&2
    exit 1
fi
