source: common/progress_bar.sh@ aceacf2

ablfs-more trunk
Last change on this file since aceacf2 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
Line 
1# shellcheck shell=bash
2
3set -e
4
5# Be sure that we know the target name
6[[ -z $1 ]] && exit
7TARGET=$1 # Remember the target build we are looking for
8MAKE_PPID=$2
9
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'
17declare -r RESET_LINE=${CURSOR_OFF}${ERASE_LINE}${FRAME_OPEN}${FRAME_CLOSE}
18
19declare -r GRAPHIC_STR="| / - \\ + "
20declare -i SEC=0 # Seconds accumulator
21declare -i PREV_SEC=0
22
23# Prevent segfault on stripping phases
24if [[ "$BASHBIN" = "/tools/bin/bash" ]] ; then
25 SLEEP=/tools/bin/sleep
26elif [ -x /bin/sleep ] ; then
27 SLEEP=/bin/sleep
28else
29 SLEEP=/usr/bin/sleep
30fi
31
32write_or_exit() {
33 # make has been killed or failed or run to completion, leave
34 [[ ! -e /proc/${MAKE_PPID} ]] && echo -n "${CURSOR_ON}" && exit
35
36 # Target build complete, leave.
37 [[ -f ${TARGET} ]] && echo -n "${CURSOR_ON}" && exit
38
39 # It is safe to write to the screen
40 echo -n "$1"
41}
42
43 # initialize screen
44write_or_exit "${RESET_LINE}${TS_POSITION}0 min. 0 sec"
45
46 # loop forever..
47while true ; do
48
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
54
55 # A BASH internal variable, the number of seconds the script
56 # has been running. modulo convert to 0-59
57 SEC=$((SECONDS % 60))
58
59 # Detect rollover of the seconds.
60 (( PREV_SEC > SEC )) && write_or_exit "${RESET_LINE}"
61 PREV_SEC=$SEC
62
63 # Display the accumulated time. div minutes.. modulo seconds.
64 write_or_exit "${TS_POSITION}$((SECONDS / 60)) min. $SEC sec"
65done
66
67exit
Note: See TracBrowser for help on using the repository browser.