#!/bin/sh

XR_BASE_PATH=/usr/share/xrecode4m/1.0
XR_LIB=$XR_BASE_PATH/lib

export XR_LIB

EXEC="$XR_BASE_PATH/xrecode4m"

if [ -n "$LD_LIBRARY_PATH" ]; then
export LD_LIBRARY_PATH="$XR_LIB:$LD_LIBRARY_PATH"
else
export LD_LIBRARY_PATH="$XR_LIB"
fi

#check to see if we have all of the shared libraries.
if ldd "$EXEC" | grep -q "not found" ; then
   echo Some Shared Libraries were not found
   ldd "$EXEC"
   exit 1
fi

########################################
# execute the program
ARGS="";
while [ "$#" -gt 0 ]; do
	ARGS=$ARGS" \"$1\""
	shift 1
done
/bin/bash -c "exec -a $0 $EXEC $ARGS > /dev/null 2>&1" $0

########################################
# set exit code / wait on existing instance
EXIT=$?
