From ed82584f872b70a77696bebea86c0f66adc85620 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Cochard-Labb=C3=A9?= Date: Tue, 29 Aug 2017 00:39:41 +0200 Subject: [PATCH] Add FreeBSD support and remove bashisms from launch.sh --- utils/launch.sh | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/utils/launch.sh b/utils/launch.sh index 9e650e42..f11b0582 100755 --- a/utils/launch.sh +++ b/utils/launch.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/bin/sh # Copyright 2016 Joel Martin # Copyright 2016 Solly Ross @@ -36,6 +36,7 @@ CERT="" WEB="" proxy_pid="" SSLONLY="" +PORTUSED=false die() { echo "$*" @@ -73,8 +74,12 @@ done 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" +case $(uname -s) in + "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 @@ -111,10 +116,10 @@ else fi # 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 - 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 "If you intended to use an installed websockify package, please remove ${HERE}/websockify." exit 1 @@ -124,12 +129,12 @@ if [[ -e ${HERE}/websockify ]]; then else WEBSOCKIFY=$(which websockify 2>/dev/null) - if [[ $? -ne 0 ]]; then + if [ $? -ne 0 ]; then echo "No installed websockify, attempting to clone websockify..." WEBSOCKIFY=${HERE}/websockify/run 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" exit 1 fi