2015-08-22 13:39:42 +08:00
|
|
|
#!/bin/sh
|
2009-02-06 05:28:33 +08:00
|
|
|
|
2015-08-22 13:37:47 +08:00
|
|
|
getabsolutepath() {
|
2015-08-14 02:44:12 +08:00
|
|
|
[ -d "$1" ] && { cd "$1"; echo "$(pwd -P)"; } ||
|
|
|
|
{ cd "$(dirname "$1")"; echo "$(pwd -P)/$(basename "$1")"; }
|
|
|
|
}
|
2015-08-14 02:42:06 +08:00
|
|
|
|
2015-08-14 02:44:12 +08:00
|
|
|
pfx=$(getabsolutepath "$1")
|
2015-08-14 02:23:59 +08:00
|
|
|
|
2016-01-23 05:35:18 +08:00
|
|
|
if [ -z "$1" ]; then
|
2015-07-21 04:50:33 +08:00
|
|
|
echo "Usage: ./env.sh [destdir|prefix] [program]"
|
2011-07-19 18:52:51 +08:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2015-07-21 04:50:33 +08:00
|
|
|
if [ ! -d "$pfx" ]; then
|
|
|
|
echo "Cannot find $pfx directory"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Support DESTDIR
|
|
|
|
if [ -d "$pfx/usr/bin" ]; then
|
|
|
|
pfx="$pfx/usr"
|
|
|
|
fi
|
|
|
|
|
2009-02-06 05:28:33 +08:00
|
|
|
new_env='
|
2018-03-05 19:06:17 +08:00
|
|
|
R2_ENV_IS_SET=1
|
2018-08-08 04:14:54 +08:00
|
|
|
R2_LIBR_PLUGINS=${pfx}/lib/radare2
|
2011-07-19 18:52:51 +08:00
|
|
|
PATH=$pfx/bin:${PATH}
|
|
|
|
LD_LIBRARY_PATH=$pfx/lib:$LD_LIBRARY_PATH
|
2015-06-23 22:38:46 +08:00
|
|
|
DYLD_LIBRARY_PATH=$pfx/lib:$DYLD_LIBRARY_PATH
|
|
|
|
PKG_CONFIG_PATH=$pfx/lib/pkgconfig:$PKG_CONFIG_PATH
|
2009-02-06 05:28:33 +08:00
|
|
|
'
|
|
|
|
|
2015-07-21 04:50:33 +08:00
|
|
|
shift
|
2018-03-05 19:06:17 +08:00
|
|
|
if [ "$R2_ENV_IS_SET" = 1 ]; then
|
|
|
|
echo "Nested call"
|
|
|
|
exec $*
|
|
|
|
exit $?
|
|
|
|
fi
|
2009-02-06 05:28:33 +08:00
|
|
|
|
2015-07-21 04:50:33 +08:00
|
|
|
if [ -z "$*" ]; then
|
|
|
|
echo
|
|
|
|
echo "==> Entering radare2 environment shell..."
|
|
|
|
echo
|
|
|
|
echo $new_env $* \
|
|
|
|
| sed -e 's, ,\n,g' \
|
|
|
|
| sed -e 's,^, ,g' \
|
|
|
|
| sed -e 's,$, \\,'
|
|
|
|
echo
|
|
|
|
export PS1="r2env.sh$ "
|
|
|
|
eval $new_env $SHELL
|
|
|
|
echo
|
|
|
|
echo "==> Back to system shell..."
|
|
|
|
echo
|
|
|
|
else
|
2016-02-22 05:38:04 +08:00
|
|
|
if [ "$#" -gt 1 ]; then
|
2015-11-01 03:50:49 +08:00
|
|
|
par=""
|
2016-02-22 05:38:04 +08:00
|
|
|
p=0
|
|
|
|
while : ; do
|
|
|
|
p=$(($p+1))
|
|
|
|
[ $p -gt $# ] && break
|
2016-02-22 16:41:50 +08:00
|
|
|
a=`eval echo "\$\{$p\}"`
|
2016-02-25 20:33:17 +08:00
|
|
|
par="$par\"$a\" "
|
2016-02-22 05:38:04 +08:00
|
|
|
done
|
2016-02-25 20:33:17 +08:00
|
|
|
eval $new_env $par
|
2015-11-01 03:50:49 +08:00
|
|
|
else
|
|
|
|
eval $new_env $*
|
|
|
|
fi
|
2015-07-21 04:50:33 +08:00
|
|
|
fi
|