#!/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