forked from radareorg/radare2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
env.sh
executable file
·69 lines (61 loc) · 1.17 KB
/
env.sh
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
#!/bin/sh
getabsolutepath() {
[ -d "$1" ] && { cd "$1"; echo "$(pwd -P)"; } ||
{ cd "$(dirname "$1")"; echo "$(pwd -P)/$(basename "$1")"; }
}
pfx=$(getabsolutepath "$1")
if [ -z "$1" ]; then
echo "Usage: ./env.sh [destdir|prefix] [program]"
exit 1
fi
if [ ! -d "$pfx" ]; then
echo "Cannot find $pfx directory"
exit 1
fi
# Support DESTDIR
if [ -d "$pfx/usr/bin" ]; then
pfx="$pfx/usr"
fi
new_env='
R2_ENV_IS_SET=1
LIBR_PLUGINS=${pfx}/lib/radare2
PATH=$pfx/bin:${PATH}
LD_LIBRARY_PATH=$pfx/lib:$LD_LIBRARY_PATH
DYLD_LIBRARY_PATH=$pfx/lib:$DYLD_LIBRARY_PATH
PKG_CONFIG_PATH=$pfx/lib/pkgconfig:$PKG_CONFIG_PATH
'
shift
if [ "$R2_ENV_IS_SET" = 1 ]; then
echo "Nested call"
exec $*
exit $?
fi
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
if [ "$#" -gt 1 ]; then
par=""
p=0
while : ; do
p=$(($p+1))
[ $p -gt $# ] && break
a=`eval echo "\$\{$p\}"`
par="$par\"$a\" "
done
eval $new_env $par
else
eval $new_env $*
fi
fi