[PATCH] Correct configserver-setup keep_going prompt

James Laska jlaska at redhat.com
Wed Apr 11 20:05:50 UTC 2012


Previously, the prompt would not recognize invalid input.  You could
press <Enter> and the setup process would continue.  I've adjusted the
prompt to check whether we are running on a tty first, and to reprompt
when a invalid response is received.  Checking for the presence of a
tty, will allow aeolus-configserver-setup to be called by a
non-interactive script (or deployable).
---
 configserver/configure/bin/config_httpd.sh |   33 ++++++++++++++++++++++------
 1 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/configserver/configure/bin/config_httpd.sh b/configserver/configure/bin/config_httpd.sh
index be28715..0792e4c 100755
--- a/configserver/configure/bin/config_httpd.sh
+++ b/configserver/configure/bin/config_httpd.sh
@@ -28,6 +28,17 @@ secure pages on port 443, then this tool should not be used.
 
 """
 
+# Determine whether running on an interactive tty (or a pipe)
+isatty(){
+    stdin="$(ls -l /proc/self/fd/0)"
+    stdin="${stdin/*-> /}"
+
+    if [[ "$stdin" =~ ^/dev/pts/[0-9] ]]; then
+        return 0 # terminal
+    else
+        return 1 # pipe
+    fi
+}
 
 usage()
 {
@@ -68,15 +79,23 @@ fi
 
 echo "$PREAMBLE"
 echo -n "Do you wish to continue [y/N]: "
-read keep_going
-if [ "x$keep_going" == "x" ]; then
-    keep_going="Y"
-fi
-keep_going=$(echo "$keep_going" | tr a-z A-Z)
-if [ "Y" != "$keep_going" ]; then
-    exit 1
+if isatty ; then
+    keep_going="n"
+    while read keep_going ; do
+        if [[ $keep_going == [Yy] ]]; then
+            break
+        elif [[ $keep_going == [Nn] ]]; then
+            exit 1
+        else
+            echo -n "Do you wish to continue [y/N]: "
+            continue
+        fi
+    done
+else
+    echo y
 fi
 
+
 PREAMBLE2="""
 There are a few pieces of information to collect.  Some of the information
 provides default values. The default values are enclosed in square brackets
-- 
1.7.7.6




More information about the aeolus-devel mailing list