diff options
Diffstat (limited to 'gosher')
-rwxr-xr-x | gosher | 52 |
1 files changed, 32 insertions, 20 deletions
@@ -43,7 +43,7 @@ NETCAT="nc.openbsd" ### use named pipes (Does *not* work with original netcat!!!!!) STYLE='pipe' -OPREFIX=/tmp/outf_ +### prefix of the input FIFO IPREFIX=/tmp/inf_ DEBUG= @@ -63,6 +63,8 @@ cleanup(){ } MYNAME=$(basename $0) +MYDIR=$(dirname $(realpath $0)) +NETCAT=$(which $NETCAT) if [ -z "${MYNAME#gosher}" ]; then ## we are called as gosher -- launch the server @@ -70,28 +72,38 @@ if [ -z "${MYNAME#gosher}" ]; then PORT=${1:-70} GOPHERDIR=${2:-"./"} - trap cleanup 0 HUP INT TRAP TERM QUIT - - INF=${IPREFIX}$$ - [ "$STYLE" = "pipe" ] && { - mkfifo -m 600 $INF - while [ 1 -eq 1 ]; do - ./gosher_serve ${GOPHERDIR} <$INF | ${NETCAT} -vvvvv -l -p ${PORT} >$INF - done - rm -f $INF - exit 0 - } - [ "$STYLE" = 'fork' ] && { - while [ 1 -eq 1 ]; do - ${NETCAT} -vv -l -p $PORT -c "~/gosher_serve ${GOPHERDIR}" - done - exit 0 + [ ! -f "${NETCAT}" -o ! -x "${NETCAT}" ] && { + echo "Wrong NETCAT -- Exiting" >&2 + exit 2 } - echo "Error!!! wrong STYLE specified!!!" >&2 - exit 1 + + if [ -f "${MYDIR}/gosher_serve" -o -h "${MYDIR}/gosher_serve" ]; then + GOSHER_SERVE="${MYDIR}/gosher_serve" + trap cleanup 0 HUP INT TRAP TERM QUIT + + INF=${IPREFIX}$$ + [ "$STYLE" = "pipe" ] && { + mkfifo -m 600 $INF + while [ 1 -eq 1 ]; do + ${GOSHER_SERVE} ${GOPHERDIR} <$INF | ${NETCAT} -vvvvv -l -p ${PORT} >$INF + done + rm -f $INF + exit 0 + } + [ "$STYLE" = 'fork' ] && { + while [ 1 -eq 1 ]; do + ${NETCAT} -vv -l -p $PORT -c "${GOSHERSERVE} ${GOPHERDIR}" + done + exit 0 + } + echo "Wrong STYLE specified -- Exiting" >&2 + exit 2 + else + echo "Cannot find gosher_serve -- Exiting">&2 + exit 3 + fi fi - ###################### ## |