#!/bin/sh

##
# Print an error and exit if the executable <code>$1</code> cannot be
# found.
#
# @param[in] $1 name of executable
verify_exec () {
    type "$1" 1>/dev/null 2>&1
    if [ $? -ne 0 ] ; then
        echo "***" 1>&2
        echo "*** $progname: Error: Unable to find \"$1\" in your path." 1>&2
        echo "***" 1>&2
        exit 1
    fi
}

#
# Script starts here.
#

# Set up the program name for error reporting.
progname="pathmgr"
verify_exec "basename"
progname=`basename "$0"`

# Make sure the other executables are available.
verify_exec "dirname"

PYTHON_EXEC="python"
for i in python3 python python2 python2.7 \
         python3.17 python3.16 python3.15 python3.14 \
         python3.13 python3.12 python3.11 python3.10 \
         python3.9 python3.8 python3.7 python3.6
do
    if type "$i" 1>/dev/null 2>&1 ; then
        PYTHON_EXEC="$i"
        break
    fi
done
verify_exec "$PYTHON_EXEC"

# Generate the path to the pathmgr python script.
top=`dirname "$0"`
script="$top/pathmgr.py"

# Execute the script.
exec "$PYTHON_EXEC" "$script" ${1+"$@"}
