Last active
December 13, 2018 16:46
-
-
Save Freaky/de88c5e499e49c16705e7cf802346bed to your computer and use it in GitHub Desktop.
Patch to CURRENT freebsd-update to replace the 10....20....30.... progress indicator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- freebsd-update.sh.orig 2018-12-13 16:28:44.343075728 +0000 | |
+++ freebsd-update.sh 2018-12-13 16:44:41.440009430 +0000 | |
@@ -1059,6 +1059,30 @@ | |
# Print user-friendly progress statistics | |
fetch_progress () { | |
+ if [ "$1" -gt 0 -a -t 1 ]; then | |
+ fetch_progress_tty $1 | |
+ else | |
+ fetch_progress_classic | |
+ fi | |
+} | |
+ | |
+# Progress in an in-place "123/456 (26%)" style | |
+fetch_progress_tty () { | |
+ EXP=$1 | |
+ LNC=0 | |
+ printf " \033[s" | |
+ while read x; do | |
+ LNC=$(($LNC + 1)) | |
+ PCT=$((100 * $LNC / $EXP)) | |
+ if [ $(($LNC % 10)) = 0 ]; then | |
+ printf "\033[u%d/%d (%d%%)" $LNC $EXP $PCT | |
+ fi | |
+ done | |
+ printf "\033[u\033[K" | |
+} | |
+ | |
+# Progress in the original "10....20....30" style | |
+fetch_progress_classic () { | |
LNC=0 | |
while read x; do | |
LNC=$(($LNC + 1)) | |
@@ -1311,12 +1335,13 @@ | |
if [ -s patchlist ]; then | |
# Attempt to fetch metadata patches | |
- echo -n "Fetching `wc -l < patchlist | tr -d ' '` " | |
+ NITEMS=`wc -l < patchlist | tr -d ' '` | |
+ echo -n "Fetching ${NITEMS} " | |
echo ${NDEBUG} "metadata patches.${DDSTATS}" | |
tr '|' '-' < patchlist | | |
lam -s "${FETCHDIR}/tp/" - -s ".gz" | | |
xargs ${XARGST} ${PHTTPGET} ${SERVERNAME} \ | |
- 2>${STATSREDIR} | fetch_progress | |
+ 2>${STATSREDIR} | fetch_progress ${NITEMS} | |
echo "done." | |
# Attempt to apply metadata patches | |
@@ -1850,12 +1875,13 @@ | |
fetch_files () { | |
# Attempt to fetch patches | |
if [ -s patchlist ]; then | |
- echo -n "Fetching `wc -l < patchlist | tr -d ' '` " | |
+ NITEMS=`wc -l < patchlist | tr -d ' '` | |
+ echo -n "Fetching ${NITEMS} " | |
echo ${NDEBUG} "patches.${DDSTATS}" | |
tr '|' '-' < patchlist | | |
lam -s "${PATCHDIR}/" - | | |
xargs ${XARGST} ${PHTTPGET} ${SERVERNAME} \ | |
- 2>${STATSREDIR} | fetch_progress | |
+ 2>${STATSREDIR} | fetch_progress ${NITEMS} | |
echo "done." | |
# Attempt to apply patches | |
@@ -1884,11 +1910,12 @@ | |
done < files.wanted > filelist | |
if [ -s filelist ]; then | |
- echo -n "Fetching `wc -l < filelist | tr -d ' '` " | |
+ NITEMS=`wc -l < filelist | tr -d ' '` | |
+ echo -n "Fetching ${NITEMS} " | |
echo ${NDEBUG} "files... " | |
lam -s "${FETCHDIR}/f/" - -s ".gz" < filelist | | |
xargs ${XARGST} ${PHTTPGET} ${SERVERNAME} \ | |
- 2>${STATSREDIR} | fetch_progress | |
+ 2>${STATSREDIR} | fetch_progress ${NITEMS} | |
while read Y; do | |
if ! [ -f ${Y}.gz ]; then |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment