source: common/progress_bar.sh@ 86debb0

ablfs-more trunk
Last change on this file since 86debb0 was fd4a798, checked in by Pierre Labastie <pierre.labastie@…>, 3 years ago

Remove $Id$ comments, they are useless with git

  • Property mode set to 100644
File size: 1.8 KB
RevLine 
[bc2f591]1# shellcheck shell=bash
[a858a78]2
3set -e
4
[ea81eb2]5# Be sure that we know the target name
[a36805d]6[[ -z $1 ]] && exit
[843c479]7TARGET=$1 # Remember the target build we are looking for
[d44206f]8MAKE_PPID=$2
[a36805d]9
[843c479]10declare -r CSI=$'\e[' # DEC terminology, Control Sequence Introducer
11declare -r CURSOR_OFF=${CSI}$'?25l'
12declare -r CURSOR_ON=${CSI}$'?25h'
13declare -r ERASE_LINE=${CSI}$'2K'
14declare -r FRAME_OPEN=${CSI}$'2G['
15declare -r FRAME_CLOSE=${CSI}$'63G]'
16declare -r TS_POSITION=${CSI}$'65G'
[bc2f591]17declare -r RESET_LINE=${CURSOR_OFF}${ERASE_LINE}${FRAME_OPEN}${FRAME_CLOSE}
[843c479]18
[bc2f591]19declare -r GRAPHIC_STR="| / - \\ + "
[843c479]20declare -i SEC=0 # Seconds accumulator
[ddf5f77]21declare -i PREV_SEC=0
22
[b0ba1f0]23# Prevent segfault on stripping phases
[c180dec]24if [[ "$BASHBIN" = "/tools/bin/bash" ]] ; then
[b0ba1f0]25 SLEEP=/tools/bin/sleep
[ea81eb2]26elif [ -x /bin/sleep ] ; then
[c180dec]27 SLEEP=/bin/sleep
[ea81eb2]28else
29 SLEEP=/usr/bin/sleep
[b0ba1f0]30fi
31
[843c479]32write_or_exit() {
[7dd28ea]33 # make has been killed or failed or run to completion, leave
[d44206f]34 [[ ! -e /proc/${MAKE_PPID} ]] && echo -n "${CURSOR_ON}" && exit
[041f2ed]35
[e2ef100]36 # Target build complete, leave.
37 [[ -f ${TARGET} ]] && echo -n "${CURSOR_ON}" && exit
[041f2ed]38
[843c479]39 # It is safe to write to the screen
40 echo -n "$1"
41}
42
[ddf5f77]43 # initialize screen
[045b2dc]44write_or_exit "${RESET_LINE}${TS_POSITION}0 min. 0 sec"
[ddf5f77]45
46 # loop forever..
47while true ; do
48
[bc2f591]49 # Loop through the animation string
50 for GRAPHIC_CHAR in ${GRAPHIC_STR} ; do
51 write_or_exit "${CSI}$((SEC + 3))G${GRAPHIC_CHAR}"
52 $SLEEP .12 # This value MUST be less than .2 seconds.
53 done
[ddf5f77]54
[bc2f591]55 # A BASH internal variable, the number of seconds the script
56 # has been running. modulo convert to 0-59
57 SEC=$((SECONDS % 60))
[ddf5f77]58
[bc2f591]59 # Detect rollover of the seconds.
60 (( PREV_SEC > SEC )) && write_or_exit "${RESET_LINE}"
61 PREV_SEC=$SEC
[ddf5f77]62
[bc2f591]63 # Display the accumulated time. div minutes.. modulo seconds.
64 write_or_exit "${TS_POSITION}$((SECONDS / 60)) min. $SEC sec"
[843c479]65done
66
[ddf5f77]67exit
Note: See TracBrowser for help on using the repository browser.