Add FreeBSD support and remove bashisms from launch.sh

This commit is contained in:
Olivier Cochard-Labbé 2017-08-29 00:39:41 +02:00
parent d1a1e0e529
commit ed82584f87
1 changed files with 12 additions and 7 deletions

View File

@ -1,4 +1,4 @@
#!/usr/bin/env bash #!/bin/sh
# Copyright 2016 Joel Martin # Copyright 2016 Joel Martin
# Copyright 2016 Solly Ross # Copyright 2016 Solly Ross
@ -36,6 +36,7 @@ CERT=""
WEB="" WEB=""
proxy_pid="" proxy_pid=""
SSLONLY="" SSLONLY=""
PORTUSED=false
die() { die() {
echo "$*" echo "$*"
@ -73,8 +74,12 @@ done
which netstat >/dev/null 2>&1 \ which netstat >/dev/null 2>&1 \
|| die "Must have netstat installed" || die "Must have netstat installed"
netstat -ltn | grep -qs ":${PORT} .*LISTEN" \ case $(uname -s) in
&& die "Port ${PORT} in use. Try --listen PORT" "FreeBSD") netstat -lan | grep -qs ".${PORT} .*LISTEN" && PORTUSED=true ;;
"Linux") netstat -ltn | grep -qs ":${PORT} .*LISTEN" && PORTUSED=true ;;
*) break ;;
esac
($PORTUSED) && die "Port ${PORT} in use. Try --listen PORT"
trap "cleanup" TERM QUIT INT EXIT trap "cleanup" TERM QUIT INT EXIT
@ -111,10 +116,10 @@ else
fi fi
# try to find websockify (prefer local, try global, then download local) # try to find websockify (prefer local, try global, then download local)
if [[ -e ${HERE}/websockify ]]; then if [ -e ${HERE}/websockify ]; then
WEBSOCKIFY=${HERE}/websockify/run WEBSOCKIFY=${HERE}/websockify/run
if [[ ! -x $WEBSOCKIFY ]]; then if [ ! -x $WEBSOCKIFY ]; then
echo "The path ${HERE}/websockify exists, but $WEBSOCKIFY either does not exist or is not executable." echo "The path ${HERE}/websockify exists, but $WEBSOCKIFY either does not exist or is not executable."
echo "If you intended to use an installed websockify package, please remove ${HERE}/websockify." echo "If you intended to use an installed websockify package, please remove ${HERE}/websockify."
exit 1 exit 1
@ -124,12 +129,12 @@ if [[ -e ${HERE}/websockify ]]; then
else else
WEBSOCKIFY=$(which websockify 2>/dev/null) WEBSOCKIFY=$(which websockify 2>/dev/null)
if [[ $? -ne 0 ]]; then if [ $? -ne 0 ]; then
echo "No installed websockify, attempting to clone websockify..." echo "No installed websockify, attempting to clone websockify..."
WEBSOCKIFY=${HERE}/websockify/run WEBSOCKIFY=${HERE}/websockify/run
git clone https://github.com/novnc/websockify ${HERE}/websockify git clone https://github.com/novnc/websockify ${HERE}/websockify
if [[ ! -e $WEBSOCKIFY ]]; then if [ ! -e $WEBSOCKIFY ]; then
echo "Unable to locate ${HERE}/websockify/run after downloading" echo "Unable to locate ${HERE}/websockify/run after downloading"
exit 1 exit 1
fi fi