Browse code

Merge "Add a spinner so users know the script is going"

Jenkins authored on 2012/09/25 06:34:04
Showing 1 changed files
... ...
@@ -585,10 +585,35 @@ APACHE_GROUP=${APACHE_GROUP:-$APACHE_USER}
585 585
 # Log files
586 586
 # ---------
587 587
 
588
+# Draw a spinner so the user knows something is happening
589
+function spinner()
590
+{
591
+    local delay=0.75
592
+    local spinstr='|/-\'
593
+    printf "..." >&3
594
+    while [ true ]; do
595
+        local temp=${spinstr#?}
596
+        printf "[%c]" "$spinstr" >&3
597
+        local spinstr=$temp${spinstr%"$temp"}
598
+        sleep $delay
599
+        printf "\b\b\b" >&3
600
+    done
601
+}
602
+
588 603
 # Echo text to the log file, summary log file and stdout
589 604
 # echo_summary "something to say"
590 605
 function echo_summary() {
591
-    echo $@ >&6
606
+    if [[ -t 3 && "$VERBOSE" != "True" ]]; then
607
+        kill >/dev/null 2>&1 $LAST_SPINNER_PID
608
+        if [ ! -z "$LAST_SPINNER_PID" ]; then
609
+            printf "\b\b\bdone\n" >&3
610
+        fi
611
+        echo -n $@ >&6
612
+        spinner &
613
+        LAST_SPINNER_PID=$!
614
+    else
615
+        echo $@ >&6
616
+    fi
592 617
 }
593 618
 
594 619
 # Echo text only to stdout, no log files
... ...
@@ -670,10 +695,20 @@ fi
670 670
 # Set Up Script Execution
671 671
 # -----------------------
672 672
 
673
+# Kill background processes on exit
674
+trap clean EXIT
675
+clean() {
676
+    local r=$?
677
+    kill >/dev/null 2>&1 $(jobs -p)
678
+    exit $r
679
+}
680
+
681
+
673 682
 # Exit on any errors so that errors don't compound
674 683
 trap failed ERR
675 684
 failed() {
676 685
     local r=$?
686
+    kill >/dev/null 2>&1 $(jobs -p)
677 687
     set +o xtrace
678 688
     [ -n "$LOGFILE" ] && echo "${0##*/} failed: full log in $LOGFILE"
679 689
     exit $r