1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
#!/bin/sh
# Runs a shell command (or interactive shell) using the binaries and
# libraries bundled with this app.
set -e
base="$(dirname "$0")"
if [ ! -d "$base" ]; then
echo "** cannot find base directory (I seem to be $0)" >&2
exit 1
fi
if [ ! -e "$base/bin/debug-me" ]; then
echo "** base directory $base does not contain bin/debug-me" >&2
exit 1
fi
# Get absolute path to base, to avoid breakage when things change directories.
orig="$(pwd)"
cd "$base"
base="$(pwd)"
cd "$orig"
# --library-path won't work if $base contains : or ;
# Detect this problem, and work around it by using a temp directory.
if echo "$base" | grep -q '[:;]'; then
tbase=$(mktemp -d -p /tmp debugmeshimXXXXXXXXX 2>/dev/null || true)
if [ -z "$tbase" ]; then
tbase="/tmp/debugmeshim.$$"
mkdir "$tbase"
fi
ln -s "$base" "$tbase/link"
base="$tbase/link"
cleanuptbase () {
rm -rf "$tbase"
}
trap cleanuptbase EXIT
fi
# Put our binaries first, to avoid issues with out of date or incompatible
# system binaries. Extra binaries come after system path.
ORIG_PATH="$PATH"
export ORIG_PATH
PATH="$base/bin:$PATH:$base/extra"
export PATH
# These env vars are used by the shim wrapper around each binary.
for lib in $(cat "$base/libdirs"); do
DEBUG_ME_LD_LIBRARY_PATH="$base/$lib:$DEBUG_ME_LD_LIBRARY_PATH"
done
export DEBUG_ME_LD_LIBRARY_PATH
DEBUG_ME_DIR="$base"
export DEBUG_ME_DIR
ORIG_GCONV_PATH="$GCONV_PATH"
export ORIG_GCONV_PATH
GCONV_PATH="$base/$(cat "$base/gconvdir")"
export GCONV_PATH
ORIG_MANPATH="$MANPATH"
export ORIG_MANPATH
MANPATH="$base/usr/share/man:$MANPATH"
export MANPATH
DEBUG_ME_EXE="$base/debug-me"
export DEBUG_ME_EXE
if [ "$1" ]; then
cmd="$1"
shift 1
if [ -z "$tbase" ]; then
exec "$cmd" "$@"
else
# allow EXIT trap to cleanup
"$cmd" "$@"
fi
else
sh
fi
|