Date:2010-12-01 08:31:38 (8 years 9 months ago)
Author:kyak
Commit:5cb8088e199b10efbfc39ccaeb568f6c6d8c1f08
Message:reflash_ben.sh: add progress bar

Files: data/qi_lb60/scripts/reflash_ben.sh (2 diffs)

Change Details

data/qi_lb60/scripts/reflash_ben.sh
8585    exit 1
8686}
8787
88progress_prepare () {
89    WIDTH=$(tput cols)
90    HEIGHT=$(tput lines)
91    i=1
92    DONE=0
93    FITFR=0
94    echo "Done:"
95    echo -n "["
96    tput cup $HEIGHT $WIDTH; echo -n "]"
97}
98
99progress_draw () {
100    ILINE="$1"
101    if [[ "$ILINE" =~ It\ will\ cause\ [[:digit:]]+\ times\ buffer\ transfer\.$ ]]; then
102        TOTAL=${ILINE#*cause\ }
103        TOTAL=${TOTAL%\ times*}
104        FIT=$(echo "($WIDTH-2)/$TOTAL" | bc -l)
105        tput cup $(( $HEIGHT-2 )) 7; echo -n 0/$TOTAL
106    fi
107    if [[ "$ILINE" =~ Checking\ [[:digit:]]+\ bytes\.\.\.\ Comparing\ [[:digit:]]+\ bytes\ -\ SUCCESS$ || "$ILINE" =~ Checking\ [[:digit:]]+\ bytes\.\.\.\ no\ check\!\ End\ at\ Page\:\ [[:digit:]]+ ]]; then
108        FITFR=$(echo $FITFR+$FIT | bc -l)
109        ((DONE++))
110        tput cup $(( $HEIGHT-2 )) 7; echo -n $DONE/$TOTAL
111        if [ $(echo "$FITFR >= 1" | bc) -eq 1 ]; then
112            tput cup $HEIGHT $i;
113            i=$(( $i+${FITFR%.*} ))
114            for j in $(seq 1 ${FITFR%.*}); do echo -n "#"; done
115            FITFR=0.${FITFR#*.}
116        fi
117    fi
118}
119
120progress_finish () {
121    tput cup $HEIGHT $WIDTH
122    echo
123    tmp=$(<"${LOG_FILE}.err")
124    cat "${LOG_FILE}.err" >> "${LOG_FILE}"
125}
126
88127[ "$(whoami)" == "root" ] || abort "this script must be run as root"
89128
90129log "working dir: ${WORKING_DIR}"
...... 
141180
142181if [ "$B" == "TRUE" ]; then
143182    log "flashing bootloader..."
144    tmp=$(usbboot -c "nprog 0 ${WORKING_DIR}/${LOADER} 0 0 -n" 3>> "${LOG_FILE}" 2>&1 >&3)
183    progress_prepare
184    while read ILINE
185        do progress_draw "$ILINE"
186    done< <(usbboot -c "nprog 0 ${WORKING_DIR}/${LOADER} 0 0 -n" 2>"${LOG_FILE}.err" | tee -a "${LOG_FILE}")
187    progress_finish
145188    test "${tmp}" && abort "error while flashing bootloader:\n${tmp}"
146189fi
147190if [ "$K" == "TRUE" ]; then
148191    log "flashing kernel..."
149    tmp=$(usbboot -c "nprog 1024 ${WORKING_DIR}/${KERNEL} 0 0 -n" 3>> "${LOG_FILE}" 2>&1 >&3)
192    progress_prepare
193    while read ILINE
194        do progress_draw "$ILINE"
195    done< <(usbboot -c "nprog 1024 ${WORKING_DIR}/${KERNEL} 0 0 -n" 2>"${LOG_FILE}.err" | tee -a "${LOG_FILE}")
196    progress_finish
150197    test "${tmp}" && abort "error while flashing kernel:\n${tmp}"
151198fi
152199if [ "$R" == "TRUE" ]; then
153200    log "erase nand rootfs partition..."
154201    usbboot -c "boot;nerase 16 1024 0 0" >> "${LOG_FILE}" 2>&1
155202    log "flashing rootfs..."
156    tmp=$(usbboot -c "nprog 2048 ${WORKING_DIR}/${ROOTFS} 0 0 -n" 3>> "${LOG_FILE}" 2>&1 >&3)
203    progress_prepare
204    while read ILINE
205        do progress_draw "$ILINE"
206    done< <(usbboot -c "nprog 2048 ${WORKING_DIR}/${ROOTFS} 0 0 -n" 2>"${LOG_FILE}.err" | tee -a "${LOG_FILE}")
207    progress_finish
157208    test "${tmp}" && abort "error while flashing rootfs:\n${tmp}"
158209fi
159210log "done"

Archive Download the corresponding diff file



interactive