Merge "Add a spinner so users know the script is going"
This commit is contained in:
commit
8cbeb97956
37
stack.sh
37
stack.sh
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user