forked from extern/shorewall_code
Restore the read_yesno_with_timeout() function
Signed-off-by: Tom Eastep <teastep@shorewall.net>
This commit is contained in:
parent
9c950082f6
commit
b5e8f9bd50
@ -1063,6 +1063,41 @@ restart_command() {
|
|||||||
return $rc
|
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
|
# Safe-start/safe-reload/safe-restart Command Executor
|
||||||
#
|
#
|
||||||
|
Loading…
Reference in New Issue
Block a user