2021-03-04 11:30:38 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
EXEDIR="$(dirname "$0")"
|
|
|
|
EXEDIR="$(cd "$EXEDIR"; pwd)"
|
|
|
|
BINS=binaries
|
|
|
|
BINDIR="$EXEDIR/$BINS"
|
|
|
|
|
2022-06-01 19:03:27 +00:00
|
|
|
exists()
|
|
|
|
{
|
|
|
|
which "$1" >/dev/null 2>/dev/null
|
|
|
|
}
|
|
|
|
|
2021-03-04 11:30:38 +00:00
|
|
|
check_dir()
|
|
|
|
{
|
2022-02-05 18:42:10 +00:00
|
|
|
local dir="$BINDIR/$1"
|
|
|
|
local exe="$dir/ip2net"
|
|
|
|
local out
|
2021-03-04 11:30:38 +00:00
|
|
|
if [ -f "$exe" ]; then
|
|
|
|
if [ -x "$exe" ]; then
|
2022-02-05 18:42:10 +00:00
|
|
|
# ash and dash try to execute invalid executables as a script. they interpret binary garbage with possible negative consequences
|
2022-06-01 19:03:27 +00:00
|
|
|
# bash do not do this
|
|
|
|
if exists bash; then
|
|
|
|
out=$(echo 0.0.0.0 | bash -c "$exe" 2>/dev/null)
|
|
|
|
else
|
|
|
|
# find do not use its own shell exec
|
|
|
|
# it uses execvp(). in musl libc it does not call shell, in glibc it DOES call /bin/sh
|
|
|
|
# that's why prefer bash if present
|
|
|
|
out=$(echo 0.0.0.0 | find "$dir" -maxdepth 1 -name ip2net -exec {} \; 2>/dev/null)
|
|
|
|
fi
|
2022-02-05 18:42:10 +00:00
|
|
|
[ -n "$out" ]
|
2021-03-04 11:30:38 +00: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()
|
|
|
|
{
|
|
|
|
local F=$(basename $1)
|
|
|
|
[ -d "$EXEDIR/$2" ] || mkdir "$EXEDIR/$2"
|
|
|
|
[ -f "$EXEDIR/$2/$F" ] && rm -f "$EXEDIR/$2/$F"
|
|
|
|
ln -fs "../$BINS/$1" "$EXEDIR/$2" && echo linking : "../$BINS/$1" =\> "$EXEDIR/$2"
|
|
|
|
#cp -f "$BINDIR/$1" "$EXEDIR/$2" && echo copying : "$BINDIR/$1" =\> "$EXEDIR/$2"
|
|
|
|
}
|
|
|
|
|
|
|
|
UNAME=$(uname)
|
|
|
|
if [ "$UNAME" = "Linux" ]; then
|
|
|
|
ARCHLIST="my x86_64 x86 aarch64 arm mips64r2-msb mips32r1-lsb mips32r1-msb ppc"
|
|
|
|
elif [ "$UNAME" = "Darwin" ]; then
|
|
|
|
ARCHLIST="my mac64"
|
2022-01-23 08:37:40 +00:00
|
|
|
elif [ "$UNAME" = "FreeBSD" ]; then
|
2022-01-24 17:14:40 +00:00
|
|
|
ARCHLIST="my freebsd-x64"
|
2021-03-04 11:30:38 +00:00
|
|
|
else
|
|
|
|
ARCHLIST="my"
|
|
|
|
fi
|
|
|
|
|
|
|
|
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
|
2022-01-23 11:45:12 +00:00
|
|
|
if [ "$UNAME" = "Linux" ]; then
|
2021-03-04 11:30:38 +00:00
|
|
|
ccp $arch/nfqws nfq
|
|
|
|
else
|
|
|
|
ccp $arch/dvtws nfq
|
|
|
|
fi
|
|
|
|
ccp $arch/tpws tpws
|
|
|
|
exit 0
|
|
|
|
else
|
|
|
|
echo $arch is NOT OK
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
echo no compatible binaries found
|
|
|
|
fi
|
|
|
|
|
|
|
|
exit 1
|