Add a spinner so users know the script is going

The spinner will appear if VERBOSE=False.

Change-Id: I6413decbab2da3996dce5150a4600701eadd6f82
diff --git a/stack.sh b/stack.sh
index 545c071..23c728b 100755
--- a/stack.sh
+++ b/stack.sh
@@ -584,10 +584,35 @@
 # Log files
 # ---------
 
+# Draw a spinner so the user knows something is happening
+function spinner()
+{
+    local delay=0.75
+    local spinstr='|/-\'
+    printf "..." >&3
+    while [ true ]; do
+        local temp=${spinstr#?}
+        printf "[%c]" "$spinstr" >&3
+        local spinstr=$temp${spinstr%"$temp"}
+        sleep $delay
+        printf "\b\b\b" >&3
+    done
+}
+
 # Echo text to the log file, summary log file and stdout
 # echo_summary "something to say"
 function echo_summary() {
-    echo $@ >&6
+    if [[ -t 3 && "$VERBOSE" != "True" ]]; then
+        kill >/dev/null 2>&1 $LAST_SPINNER_PID
+        if [ ! -z "$LAST_SPINNER_PID" ]; then
+            printf "\b\b\bdone\n" >&3
+        fi
+        echo -n $@ >&6
+        spinner &
+        LAST_SPINNER_PID=$!
+    else
+        echo $@ >&6
+    fi
 }
 
 # Echo text only to stdout, no log files
@@ -669,10 +694,20 @@
 # Set Up Script Execution
 # -----------------------
 
+# Kill background processes on exit
+trap clean EXIT
+clean() {
+    local r=$?
+    kill >/dev/null 2>&1 $(jobs -p)
+    exit $r
+}
+
+
 # Exit on any errors so that errors don't compound
 trap failed ERR
 failed() {
     local r=$?
+    kill >/dev/null 2>&1 $(jobs -p)
     set +o xtrace
     [ -n "$LOGFILE" ] && echo "${0##*/} failed: full log in $LOGFILE"
     exit $r