feat: Show download progress (#398)
This commit is contained in:
parent
88b16678d7
commit
a69c13e61b
2 changed files with 35 additions and 2 deletions
|
@ -34,14 +34,19 @@ BASE=$(echo "$BASE" | sed -e 's/[^A-Za-z0-9._-]/_/g')
|
||||||
TMP="$STORAGE/${BASE%.*}.tmp"
|
TMP="$STORAGE/${BASE%.*}.tmp"
|
||||||
rm -f "$TMP"
|
rm -f "$TMP"
|
||||||
|
|
||||||
MSG="Downloading $BASE as boot image..."
|
MSG="Downloading $BASE ..."
|
||||||
info "$MSG" && html "$MSG"
|
info "$MSG" && html "$MSG"
|
||||||
|
|
||||||
|
/run/progress.sh "$TMP" "Downloading $BASE ([P])..." &
|
||||||
{ wget "$BOOT" -O "$TMP" -q --no-check-certificate --show-progress "$PROGRESS"; rc=$?; } || :
|
{ wget "$BOOT" -O "$TMP" -q --no-check-certificate --show-progress "$PROGRESS"; rc=$?; } || :
|
||||||
|
|
||||||
|
fKill "progress.sh"
|
||||||
|
|
||||||
(( rc != 0 )) && error "Failed to download $BOOT , reason: $rc" && exit 60
|
(( rc != 0 )) && error "Failed to download $BOOT , reason: $rc" && exit 60
|
||||||
[ ! -f "$TMP" ] && error "Failed to download $BOOT" && exit 61
|
[ ! -f "$TMP" ] && error "Failed to download $BOOT" && exit 61
|
||||||
|
|
||||||
|
html "Download finished successfully..."
|
||||||
|
|
||||||
SIZE=$(stat -c%s "$TMP")
|
SIZE=$(stat -c%s "$TMP")
|
||||||
|
|
||||||
if ((SIZE<100000)); then
|
if ((SIZE<100000)); then
|
||||||
|
@ -50,5 +55,4 @@ fi
|
||||||
|
|
||||||
mv -f "$TMP" "$STORAGE/$BASE"
|
mv -f "$TMP" "$STORAGE/$BASE"
|
||||||
|
|
||||||
html "Download finished successfully..."
|
|
||||||
return 0
|
return 0
|
||||||
|
|
29
src/progress.sh
Normal file
29
src/progress.sh
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
set -Eeuo pipefail
|
||||||
|
|
||||||
|
escape () {
|
||||||
|
local s
|
||||||
|
s=${1//&/\&}
|
||||||
|
s=${s//</\<}
|
||||||
|
s=${s//>/\>}
|
||||||
|
s=${s//'"'/\"}
|
||||||
|
printf -- %s "$s"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
file="$1"
|
||||||
|
body=$(escape "$2")
|
||||||
|
info="/run/shm/msg.html"
|
||||||
|
|
||||||
|
if [[ "$body" == *"..." ]]; then
|
||||||
|
body="<p class=\"loading\">${body/.../}</p>"
|
||||||
|
fi
|
||||||
|
|
||||||
|
while true
|
||||||
|
do
|
||||||
|
if [ -f "$file" ]; then
|
||||||
|
size=$(stat -c '%s' "$file" | numfmt --to=si --suffix=B)
|
||||||
|
echo "${body//(\[P\])/($size)}"> "$info"
|
||||||
|
fi
|
||||||
|
sleep 1
|
||||||
|
done
|
Loading…
Reference in a new issue