2021-03-04 16:30:38 +05:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
EXEDIR="$(dirname "$0")"
|
|
|
|
EXEDIR="$(cd "$EXEDIR"; pwd)"
|
|
|
|
BINS=binaries
|
|
|
|
BINDIR="$EXEDIR/$BINS"
|
|
|
|
|
2024-08-25 19:49:15 +05:00
|
|
|
ZAPRET_BASE=${ZAPRET_BASE:-"$EXEDIR"}
|
2023-08-08 12:47:01 +05:00
|
|
|
. "$ZAPRET_BASE/common/base.sh"
|
2022-06-02 00:03:27 +05:00
|
|
|
|
2021-03-04 16:30:38 +05:00
|
|
|
check_dir()
|
|
|
|
{
|
2022-02-05 23:42:10 +05:00
|
|
|
local dir="$BINDIR/$1"
|
|
|
|
local exe="$dir/ip2net"
|
|
|
|
local out
|
2021-03-04 16:30:38 +05:00
|
|
|
if [ -f "$exe" ]; then
|
|
|
|
if [ -x "$exe" ]; then
|
2022-02-05 23:42:10 +05:00
|
|
|
# ash and dash try to execute invalid executables as a script. they interpret binary garbage with possible negative consequences
|
2023-12-18 15:49:30 +05:00
|
|
|
# bash and zsh do not do this
|
2022-06-02 00:03:27 +05:00
|
|
|
if exists bash; then
|
2024-04-26 23:36:27 +05:00
|
|
|
out=$(echo 0.0.0.0 | bash -c "\"$exe"\" 2>/dev/null)
|
2023-12-18 15:49:30 +05:00
|
|
|
elif exists zsh; then
|
2024-04-26 23:36:27 +05:00
|
|
|
out=$(echo 0.0.0.0 | zsh -c "\"$exe\"" 2>/dev/null)
|
2022-06-02 00:03:27 +05:00
|
|
|
else
|
2023-12-18 15:49:30 +05:00
|
|
|
# find does not use its own shell exec
|
2022-06-02 00:03:27 +05:00
|
|
|
# it uses execvp(). in musl libc it does not call shell, in glibc it DOES call /bin/sh
|
2023-12-18 15:49:30 +05:00
|
|
|
# that's why prefer bash or zsh if present. otherwise it's our last chance
|
2022-06-02 00:03:27 +05:00
|
|
|
out=$(echo 0.0.0.0 | find "$dir" -maxdepth 1 -name ip2net -exec {} \; 2>/dev/null)
|
|
|
|
fi
|
2022-02-05 23:42:10 +05:00
|
|
|
[ -n "$out" ]
|
2021-03-04 16:30:38 +05:00
|
|
|
else
|
|
|
|
echo "$exe is not executable. set proper chmod."
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "$exe is absent"
|
|
|
|
return 2
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# link or copy executables. uncomment either ln or cp, comment other
|
|
|
|
ccp()
|
|
|
|
{
|
2024-08-25 20:04:11 +05:00
|
|
|
local F="$(basename "$1")"
|
2024-08-25 19:49:15 +05:00
|
|
|
[ -d "$ZAPRET_BASE/$2" ] || mkdir "$ZAPRET_BASE/$2"
|
|
|
|
[ -f "$ZAPRET_BASE/$2/$F" ] && rm -f "$ZAPRET_BASE/$2/$F"
|
|
|
|
ln -fs "../$BINS/$1" "$ZAPRET_BASE/$2" && echo linking : "../$BINS/$1" =\> "$ZAPRET_BASE/$2"
|
|
|
|
#cp -f "../$BINS/$1" "$ZAPRET_BASE/$2" && echo copying : "../$BINS/$1" =\> "$ZAPRET_BASE/$2"
|
2021-03-04 16:30:38 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
UNAME=$(uname)
|
2024-04-26 23:36:27 +05:00
|
|
|
unset PKTWS
|
|
|
|
case $UNAME in
|
|
|
|
Linux)
|
|
|
|
ARCHLIST="my x86_64 x86 aarch64 arm mips64r2-msb mips32r1-lsb mips32r1-msb ppc"
|
|
|
|
PKTWS=nfqws
|
|
|
|
;;
|
|
|
|
Darwin)
|
|
|
|
ARCHLIST="my mac64"
|
|
|
|
;;
|
|
|
|
FreeBSD)
|
|
|
|
ARCHLIST="my freebsd-x64"
|
|
|
|
PKTWS=dvtws
|
|
|
|
;;
|
|
|
|
CYGWIN*)
|
|
|
|
UNAME=CYGWIN
|
|
|
|
ARCHLIST="win64"
|
|
|
|
PKTWS=winws
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
ARCHLIST="my"
|
|
|
|
esac
|
2021-03-04 16:30:38 +05:00
|
|
|
|
|
|
|
if [ "$1" = "getarch" ]; then
|
|
|
|
for arch in $ARCHLIST
|
|
|
|
do
|
|
|
|
[ -d "$BINDIR/$arch" ] || continue
|
|
|
|
if check_dir $arch; then
|
|
|
|
echo $arch
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
else
|
|
|
|
for arch in $ARCHLIST
|
|
|
|
do
|
|
|
|
[ -d "$BINDIR/$arch" ] || continue
|
|
|
|
if check_dir $arch; then
|
|
|
|
echo $arch is OK
|
|
|
|
echo installing binaries ...
|
|
|
|
ccp $arch/ip2net ip2net
|
|
|
|
ccp $arch/mdig mdig
|
2024-04-26 23:36:27 +05:00
|
|
|
[ -n "$PKTWS" ] && ccp $arch/$PKTWS nfq
|
|
|
|
[ "$UNAME" = CYGWIN ] || ccp $arch/tpws tpws
|
2021-03-04 16:30:38 +05:00
|
|
|
exit 0
|
|
|
|
else
|
|
|
|
echo $arch is NOT OK
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
echo no compatible binaries found
|
|
|
|
fi
|
|
|
|
|
|
|
|
exit 1
|