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

This commit is contained in:
Jenkins 2012-09-24 21:34:04 +00:00 committed by Gerrit Code Review
commit 8cbeb97956

View File

@ -585,10 +585,35 @@ APACHE_GROUP=${APACHE_GROUP:-$APACHE_USER}
# 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
@ -670,10 +695,20 @@ fi
# 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