#!/bin/bash

if [ x"${ScriptInstallDir}" = x ] ; then
    echo "Environment variable ScriptInstallDir is not set!"
    exit 1
fi

execname=$1
shift

exectest=0
if [ x"$1" = x"--exectest" ] ; then
    exectest=1
    shift
fi

exec=
hardware=`uname -i`
if [ x"${hardware}" = x'i386' ] ; then
    execpath="${ScriptInstallDir}/bin/afni/linux_gcc32/$execname"
elif [ x"${hardware}" = x'x86_64' ] ; then
    execpath="${ScriptInstallDir}/bin/afni/linux_gcc33_64/$execname"
fi

if [ ! -f "${execpath}" ] ; then
    exit 2
fi
if [ ! -x "${execpath}" ] ; then
    exit 3
fi

if [ $exectest = 0 ] ; then
    exec "${execpath}" "$@"
else
    "${execpath}" "$@" >/dev/null 2>&1
    exit $?
fi

exit 1
