[bc2f591] | 1 | # shellcheck shell=bash
|
---|
[a858a78] | 2 |
|
---|
| 3 | set -e
|
---|
| 4 |
|
---|
[ea81eb2] | 5 | # Be sure that we know the target name
|
---|
[a36805d] | 6 | [[ -z $1 ]] && exit
|
---|
[843c479] | 7 | TARGET=$1 # Remember the target build we are looking for
|
---|
[d44206f] | 8 | MAKE_PPID=$2
|
---|
[a36805d] | 9 |
|
---|
[843c479] | 10 | declare -r CSI=$'\e[' # DEC terminology, Control Sequence Introducer
|
---|
| 11 | declare -r CURSOR_OFF=${CSI}$'?25l'
|
---|
| 12 | declare -r CURSOR_ON=${CSI}$'?25h'
|
---|
| 13 | declare -r ERASE_LINE=${CSI}$'2K'
|
---|
| 14 | declare -r FRAME_OPEN=${CSI}$'2G['
|
---|
| 15 | declare -r FRAME_CLOSE=${CSI}$'63G]'
|
---|
| 16 | declare -r TS_POSITION=${CSI}$'65G'
|
---|
[bc2f591] | 17 | declare -r RESET_LINE=${CURSOR_OFF}${ERASE_LINE}${FRAME_OPEN}${FRAME_CLOSE}
|
---|
[843c479] | 18 |
|
---|
[bc2f591] | 19 | declare -r GRAPHIC_STR="| / - \\ + "
|
---|
[843c479] | 20 | declare -i SEC=0 # Seconds accumulator
|
---|
[ddf5f77] | 21 | declare -i PREV_SEC=0
|
---|
| 22 |
|
---|
[b0ba1f0] | 23 | # Prevent segfault on stripping phases
|
---|
[c180dec] | 24 | if [[ "$BASHBIN" = "/tools/bin/bash" ]] ; then
|
---|
[b0ba1f0] | 25 | SLEEP=/tools/bin/sleep
|
---|
[ea81eb2] | 26 | elif [ -x /bin/sleep ] ; then
|
---|
[c180dec] | 27 | SLEEP=/bin/sleep
|
---|
[ea81eb2] | 28 | else
|
---|
| 29 | SLEEP=/usr/bin/sleep
|
---|
[b0ba1f0] | 30 | fi
|
---|
| 31 |
|
---|
[843c479] | 32 | write_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] | 44 | write_or_exit "${RESET_LINE}${TS_POSITION}0 min. 0 sec"
|
---|
[ddf5f77] | 45 |
|
---|
| 46 | # loop forever..
|
---|
| 47 | while 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] | 65 | done
|
---|
| 66 |
|
---|
[ddf5f77] | 67 | exit
|
---|