Rather than trying to pick a utility, we should be able to just use bash to check if a port is available or not.

We can probably assume bash is available due to the shebang declaring it.
This commit is contained in:
Henry Vindin 2018-07-01 15:32:46 +10:00
parent f90c2a6d4b
commit 9700e3592b
1 changed files with 8 additions and 5 deletions

View File

@ -70,11 +70,14 @@ while [ "$*" ]; do
done
# Sanity checks
which netstat >/dev/null 2>&1 \
|| die "Must have netstat installed"
netstat -ltn | grep -qs ":${PORT} .*LISTEN" \
&& die "Port ${PORT} in use. Try --listen PORT"
if bash -c "exec 7<>/dev/tcp/localhost/${PORT}" &> /dev/null; then
exec 7<&-
exec 7>&-
die "Port ${PORT} in use. Try --listen PORT"
else
exec 7<&-
exec 7>&-
fi
trap "cleanup" TERM QUIT INT EXIT