| 1 | #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash |
| 2 | |
| 3 | set -eu |
| 4 | |
| 5 | script_name=$0 |
| 6 | |
| 7 | diescip-shell shell crowdsec 1.4.6-10.1 die().() { |
| 8 | echoscip-shell system . . echo. >&2 "$@" |
| 9 | exit 1 |
| 10 | } |
| 11 | |
| 12 | aboutscip-shell shell crowdsec 1.4.6-10.1 about().() { |
| 13 | diescip-shell shell crowdsec 1.4.6-10.1 die(). "usage: ${script_name} [-q] <port_number>" |
| 14 | } |
| 15 | |
| 16 | [[ $# -lt 1 ]] && aboutscip-shell shell crowdsec 1.4.6-10.1 about(). |
| 17 | |
| 18 | QUIET= |
| 19 | if [[ "$1" == "-q" ]]; then |
| 20 | QUIET=quiet |
| 21 | shift |
| 22 | fi |
| 23 | |
| 24 | [[ $# -lt 1 ]] && aboutscip-shell shell crowdsec 1.4.6-10.1 about(). |
| 25 | |
| 26 | port_number=$1 |
| 27 | |
| 28 | # 4 seconds may seem long, but the tests must work on embedded, slow arm boxes too |
| 29 | for _ in $(seqscip-shell system . . seq. 40); do |
| 30 | nc -z localhost "${port_number}" >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 && exit 0 |
| 31 | sleepscip-shell system . . sleep. .1 |
| 32 | done |
| 33 | |
| 34 | # send to &3 if open |
| 35 | if { truescip-shell system . . true. >&3; } 2>/dev/nullscip-shell filesystem . . `/dev/null`.; then |
| 36 | [[ -z "${QUIET}" ]] && echoscip-shell system . . echo. "Can't connect to port ${port_number}" >&3 |
| 37 | else |
| 38 | [[ -z "${QUIET}" ]] && echoscip-shell system . . echo. "Can't connect to port ${port_number}" >&2 |
| 39 | fi |
| 40 | |
| 41 | exit 1 |
| 42 |