#!@l_prefix@/lib/openpkg/bash
##
##  openpkg.sh -- OpenPKG maintainance utility (frontend)
##
##  Copyright (c) 2000-2003 Cable & Wireless Deutschland GmbH
##  Copyright (c) 2000-2003 The OpenPKG Project <http://www.openpkg.org/>
##  Copyright (c) 2000-2003 Ralf S. Engelschall <rse@engelschall.com>
##
##  Permission to use, copy, modify, and distribute this software for
##  any purpose with or without fee is hereby granted, provided that
##  the above copyright notice and this permission notice appear in all
##  copies.
##
##  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
##  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
##  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
##  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
##  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
##  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
##  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
##  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
##  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
##  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
##  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
##  SUCH DAMAGE.
##

#   program information
progname="openpkg"
progvers="@version@"
l_prefix="@l_prefix@"

#   try to determine Perl interpreter
perl=""
for dir in $l_prefix/bin `echo $PATH | sed -e 's;:; ;g'` /bin /usr/bin /usr/local/bin; do
    if [ -f "$dir/perl" ]; then
        perl="$dir/perl"
        break
    fi
done

#   command line option parsing
if [ $# -eq 0 ]; then
    echo "$progname:USAGE: $progname index|build [options]"
    exit 0
fi
while [ ".$1" != . ]; do
    case "$1" in
        -h ) 
            echo "$progname:USAGE: $progname index|build [options]"
            exit 0
            ;;
        -v ) 
            echo "$progname $progvers (OpenPKG instance: $l_prefix)"
            exit 0
            ;;
        -* ) 
            echo "$progname:ERROR: invalid option \"$1\"" 1>&2
            exit 1 
            ;;
        *  ) 
            break 
            ;;
    esac
done

#   command dispatching
case "$1" in
    index ) 
        if [ ".$perl" = . ]; then
            echo "$progname:ERROR: \"index\" command requires a Perl interpreter" 1>&2
            exit 1
        fi
        shift
        exec $perl ${l_prefix}/lib/openpkg/openpkg-index.pl ${1+"$@"}
        ;;
    build ) 
        if [ ".$perl" = . ]; then
            echo "$progname:ERROR: \"build\" command requires a Perl interpreter" 1>&2
            exit 1
        fi
        shift
        exec $perl ${l_prefix}/lib/openpkg/openpkg-build.pl ${1+"$@"}
        ;;
    * ) 
        echo "$progname:ERROR: invalid command \"$1\"" 1>&2
        exit 1 
        ;;
esac

