From 3a85f51e72909d82cd887efd1e364438ed766c91 Mon Sep 17 00:00:00 2001 From: KatolaZ Date: Mon, 23 Jul 2018 17:19:22 +0100 Subject: shellcheck on gosher -- a few checks disabled --- gosher | 53 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 23 deletions(-) (limited to 'gosher') diff --git a/gosher b/gosher index 3dda536..45161b9 100755 --- a/gosher +++ b/gosher @@ -58,13 +58,13 @@ DEBUG= ## function cleanup(){ - [ -n "$INF" ] && [ -p "$INF" ] && rm -f ${INF} + [ -n "$INF" ] && [ -p "$INF" ] && rm -f "${INF}" exit 1 } -MYNAME=$(basename $0) -MYDIR=$(dirname $(realpath $0)) -NETCAT=$(which $NETCAT) +MYNAME=$(basename "$0") +MYDIR=$(dirname "$(realpath "$0")") +NETCAT=$(which "$NETCAT") if [ -z "${MYNAME#gosher}" ]; then ## we are called as gosher -- launch the server @@ -72,27 +72,30 @@ if [ -z "${MYNAME#gosher}" ]; then PORT=${1:-70} GOPHERDIR=${2:-"./"} - [ ! -f "${NETCAT}" -o ! -x "${NETCAT}" ] && { + [ ! -f "${NETCAT}" ] || [ ! -x "${NETCAT}" ] && { echo "Wrong NETCAT -- Exiting" >&2 exit 2 } - if [ -f "${MYDIR}/gosher_serve" -o -h "${MYDIR}/gosher_serve" ]; then + if [ -f "${MYDIR}/gosher_serve" ] || [ -h "${MYDIR}/gosher_serve" ]; then GOSHER_SERVE="${MYDIR}/gosher_serve" trap cleanup 0 HUP INT TRAP TERM QUIT - INF=${IPREFIX}$$ + INF="${IPREFIX}$$" [ "$STYLE" = "pipe" ] && { - mkfifo -m 600 $INF + mkfifo -m 600 "$INF" +# shellcheck disable=SC2050 while [ 1 -eq 1 ]; do - ${GOSHER_SERVE} ${GOPHERDIR} <$INF | ${NETCAT} -vvvvv -l -p ${PORT} >$INF +# shellcheck disable=SC2094 + ${GOSHER_SERVE} "${GOPHERDIR}" <"$INF" | ${NETCAT} -vvvvv -l -p "${PORT}" >"$INF" done rm -f $INF exit 0 } [ "$STYLE" = 'fork' ] && { +# shellcheck disable=SC2050 while [ 1 -eq 1 ]; do - ${NETCAT} -vv -l -p $PORT -c "${GOSHERSERVE} ${GOPHERDIR}" + ${NETCAT} -vv -l -p "$PORT" -c "${GOSHER_SERVE} ${GOPHERDIR}" done exit 0 } @@ -115,6 +118,7 @@ fi invalid_selector(){ sel="$1" echo "3Error: Invalid selector: \"$sel\"" +# shellcheck disable=SC1117 printf ".\r\n" exec 1>&- exec 2>&- @@ -139,19 +143,20 @@ serve_index(){ IDX=$1 IFS=' ' - while read line; do - rline=$(echo $line | sed -r -e 's/\r//g') - case $rline in + while read -r line; do + rline=$(echo "$line" | sed -r -e 's/\r//g') + case "$rline" in '['*) - echo $rline | sed -r -e 's/\[//g;s/\]//g;s/\|/\t/g;s/\t//;s/$/\r/g' + echo "$rline" | sed -r -e 's/\[//g;s/\]//g;s/\|/\t/g;s/\t//;s/$/\r/g' ;; t*) - echo $rline | cut -c 2- + echo "$rline" | cut -c 2- ;; *) - echo $line + echo "$line" esac - done < $IDX + done < "$IDX" +# shellcheck disable=SC1117 printf ".\r\n" exec 1>&- exec 2>&- @@ -183,9 +188,9 @@ EOF GOPHERDIR=${1:-"./"} -read selector +read -r selector -selector=$(echo $selector | sed -r 's:\$.*::g;s:\r::g' ) +selector=$(echo "$selector" | sed -r 's:\$.*::g;s:\r::g' ) [ -n "$DEBUG" ] && { echo "iGOPHERDIR: ${GOPHERDIR}" @@ -194,13 +199,15 @@ selector=$(echo $selector | sed -r 's:\$.*::g;s:\r::g' ) case $selector in URL:*) - url=$(echo $selector | cut -d ":" -f 2-) - serve_redirect $url + url=$(echo "$selector" | cut -d ":" -f 2-) + serve_redirect "$url" ;; /?*|"") RP1=$(realpath "${GOPHERDIR}"/"${selector}" || "") +# shellcheck disable=SC2181 [ $? -eq 0 ] || invalid_selector "$selector" RP2=$(realpath "${GOPHERDIR}")"${selector}" +# shellcheck disable=SC2181 [ $? -eq 0 ] || invalid_selector "$selector" [ -n "$DEBUG" ] && { echo "iRP1: ${RP1}" @@ -209,8 +216,8 @@ case $selector in if [ "${RP1}" = "${RP2}" ]; then if [ -f "${RP1}" ]; then - if [ -n "$(echo $RP1 | sed -n '/\.gph$/p')" ]; then - serve_index $RP1 + if [ -n "$(echo "${RP1}" | sed -n '/\.gph$/p')" ]; then + serve_index "${RP1}" else serve_selector "${RP1}" fi -- cgit v1.2.3