#!/bin/sh

here="$(command -v "$0")" ; here="${here:-$0}" ; here="$(readlink -f "$here")" ; here="${here%/*}"
command="${0##*/}"

case "$(uname -m)" in
	i[3-6]86|x86) arch='i686' ;;
	amd64|x86_64) arch='amd64' ;;
	*) arch='i686'
	   printf 'Unsupported architecture "%s", %s\n' \
	          "$(uname -m)" "using $arch binaries!" >&2 ;;
esac

PATH="$here/bin/$arch:$here/bin:$PATH"
export PATH

scommand="$(printf '%s' "$command" | tr - _)"
eval ${scommand}_PATH='"$here"'
export ${scommand}_PATH
if [ "$0" = "$(readlink -f "$(command -v "$command")")" ]
	then eval ${scommand}_COMMAND='"$command"'
	else eval ${scommand}_COMMAND='"$0"'
fi
export ${scommand}_COMMAND

[ -x "$here/bin/$arch/$command" ] && exec "$here/bin/$arch/$command" "$@"
exec "$here/bin/$command" "$@"
