From 92ce1beddc5b9a6a8f96367eaf990f37ebfc71dd Mon Sep 17 00:00:00 2001 From: Tom Eastep Date: Sat, 20 Jan 2018 14:26:13 -0800 Subject: [PATCH] Move read_yesno_with_timeout() to lib.cli-std Signed-off-by: Tom Eastep --- Shorewall-core/lib.cli | 35 ----------------------------------- Shorewall/lib.cli-std | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/Shorewall-core/lib.cli b/Shorewall-core/lib.cli index 8d707c27d..6b8c9262b 100644 --- a/Shorewall-core/lib.cli +++ b/Shorewall-core/lib.cli @@ -1957,41 +1957,6 @@ show_proc() # $1 = name of a file [ -f $1 ] && echo " $1 = $(cat $1)" } -read_yesno_with_timeout() { - local timeout - timeout=${1:-60} - - case $timeout in - *s) - ;; - *m) - timeout=$((${timeout%m} * 60)) - ;; - *h) - timeout=$((${timeout%h} * 3600)) - ;; - esac - - read -t $timeout yn 2> /dev/null - if [ $? -eq 2 ] - then - # read doesn't support timeout - test -x /bin/bash || return 2 # bash is not installed so the feature is not available - /bin/bash -c "read -t $timeout yn ; if [ \"\$yn\" == \"y\" ] ; then exit 0 ; else exit 1 ; fi" # invoke bash and use its version of read - return $? - else - # read supports timeout - case "$yn" in - y|Y) - return 0 - ;; - *) - return 1 - ;; - esac - fi -} - # # Create the appropriate -q option to pass onward # diff --git a/Shorewall/lib.cli-std b/Shorewall/lib.cli-std index f363fb8e0..37969b945 100644 --- a/Shorewall/lib.cli-std +++ b/Shorewall/lib.cli-std @@ -1154,6 +1154,41 @@ refresh_command() { return $rc } +read_yesno_with_timeout() { + local timeout + timeout=${1:-60} + + case $timeout in + *s) + ;; + *m) + timeout=$((${timeout%m} * 60)) + ;; + *h) + timeout=$((${timeout%h} * 3600)) + ;; + esac + + read -t $timeout yn 2> /dev/null + if [ $? -eq 2 ] + then + # read doesn't support timeout + test -x /bin/bash || return 2 # bash is not installed so the feature is not available + /bin/bash -c "read -t $timeout yn ; if [ \"\$yn\" == \"y\" ] ; then exit 0 ; else exit 1 ; fi" # invoke bash and use its version of read + return $? + else + # read supports timeout + case "$yn" in + y|Y) + return 0 + ;; + *) + return 1 + ;; + esac + fi +} + # # Safe-start/safe-reload/safe-restart Command Executor #