From: Niki Roo Date: Sun, 15 Apr 2018 02:55:33 +0000 (+0200) Subject: gopher.sh: error message when server KO X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=528c6011e9364f138761e2658ec5941e0638dbf9;p=gofetch.git gopher.sh: error message when server KO --- diff --git a/gopher.sh b/gopher.sh index 0ec852b..a6cc44d 100755 --- a/gopher.sh +++ b/gopher.sh @@ -24,6 +24,13 @@ # 0 : do not invert (default) # 1 : invert +# EXIT Codes: +# 0: ok +# 1: syntax error +# 2: cannot contact server +# 3: unknown selector mode +# 255: special exit more 'q' + SERVER="$1" SELECTOR="$2" PORT="$3" @@ -47,7 +54,7 @@ fi if [ "$SERVER" = "" ]; then echo "Syntax error: $0 [SERVER] ([SELECTOR]) ([PORT]) ([MODE])" >&2 - exit 2 + exit 1 fi # can be "-" for no escape sequences @@ -132,10 +139,14 @@ finish() { } trap finish EXIT +echo "$SELECTOR" | nc "$SERVER" "$PORT" > "$tmp" +if [ $? != 0 ]; then + echo Cannot contact gopher server "[$SERVER]" >&2 + exit 2 +fi + if [ $MODE = 1 ]; then - echo "$SELECTOR" | nc "$SERVER" "$PORT" | sed 's:\r::g' > "$tmp" -else - echo "$SELECTOR" | nc "$SERVER" "$PORT" > "$tmp" + sed --in-place 's:\r::g' "$tmp" fi # Process page content