From 23f2de80146f2fe515416a3c13fabdf97846f1a9 Mon Sep 17 00:00:00 2001 From: bol-van Date: Sat, 11 May 2024 16:11:06 +0300 Subject: [PATCH] blockcheck: support cygwin native ping --- blockcheck.sh | 9 +++++++-- common/base.sh | 13 ++++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/blockcheck.sh b/blockcheck.sh index 47d26f8..7e9dd15 100755 --- a/blockcheck.sh +++ b/blockcheck.sh @@ -1353,8 +1353,13 @@ pingtest() ping -c 1 -w 1 $1 >/dev/null ;; CYGWIN) - # cygwin does not have own PING by default. use windows PING. - ping -n 1 -w 1000 $1 >/dev/null + if starts_with "$(which ping)" /cygdrive; then + # cygwin does not have own PING by default. use windows PING. + ping -n 1 -w 1000 $1 >/dev/null + else + # they have installed cygwin ping + ping -c 1 -W 1 $1 >/dev/null + fi ;; *) ping -c 1 -W 1 $1 >/dev/null diff --git a/common/base.sh b/common/base.sh index ed853aa..5ef723a 100644 --- a/common/base.sh +++ b/common/base.sh @@ -49,6 +49,17 @@ contains() # check if substring $2 contains in $1 [ "${1#*$2}" != "$1" ] } +starts_with() +{ + # $1 : what + # $2 : starts with + case "$1" in + "$2"*) + return 0 + ;; + esac + return 1 +} find_str_in_list() { [ -n "$1" ] && { @@ -290,7 +301,7 @@ shell_name() SHELL_NAME=$(ps -p $$ -o comm=) fi - [ -n "$SHELL_NAME" ] || SHELL_NAME=$(basename "$SHELL") + [ -n "$SHELL_NAME" ] || SHELL_NAME="$(basename "$SHELL")" } }