feat: Show download progress (#608)

This commit is contained in:
Kroese 2024-01-29 05:40:06 +01:00 committed by GitHub
parent 740dbec1b1
commit 9fa68908a9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 49 additions and 1 deletions

View File

@ -105,6 +105,7 @@ RDC="$STORAGE/dsm.rd"
if [ ! -f "$RDC" ]; then
MSG="Downloading installer..."
PRG="Downloading installer ([P])..."
info "Install: $MSG" && html "$MSG"
RD="$TMP/rd.gz"
@ -112,7 +113,11 @@ if [ ! -f "$RDC" ]; then
VERIFY="b4215a4b213ff5154db0488f92c87864"
LOC="$DL/release/7.0.1/42218/DSM_VirtualDSM_42218.pat"
rm -f "$RD"
/run/progress.sh "$RD" "$PRG" &
{ curl -r "$POS" -sfk -S -o "$RD" "$LOC"; rc=$?; } || :
fKill "progress.sh"
(( rc != 0 )) && error "Failed to download $LOC, reason: $rc" && exit 60
SUM=$(md5sum "$RD" | cut -f 1 -d " ")
@ -123,7 +128,11 @@ if [ ! -f "$RDC" ]; then
rm "$RD"
rm -f "$PAT"
html "$MSG"
/run/progress.sh "$PAT" "$PRG" &
{ wget "$LOC" -O "$PAT" -q --no-check-certificate --show-progress "$PROGRESS"; rc=$?; } || :
fKill "progress.sh"
(( rc != 0 )) && error "Failed to download $LOC , reason: $rc" && exit 60
tar --extract --file="$PAT" --directory="$(dirname "$RD")"/. "$(basename "$RD")"
@ -175,7 +184,10 @@ fi
rm -rf "$TMP" && mkdir -p "$TMP"
info "Install: Downloading $BASE.pat..."
html "Install: Downloading DSM from Synology..."
MSG="Downloading DSM..."
PRG="Downloading DSM ([P])..."
html "$MSG"
PAT="/$BASE.pat"
rm -f "$PAT"
@ -186,7 +198,11 @@ if [[ "$URL" == "file://"* ]]; then
else
/run/progress.sh "$PAT" "$PRG" &
{ wget "$URL" -O "$PAT" -q --no-check-certificate --show-progress "$PROGRESS"; rc=$?; } || :
fKill "progress.sh"
(( rc != 0 )) && error "Failed to download $URL , reason: $rc" && exit 69
fi

32
src/progress.sh Normal file
View File

@ -0,0 +1,32 @@
#!/usr/bin/env bash
set -Eeuo pipefail
escape () {
local s
s=${1//&/\&}
s=${s//</\&lt;}
s=${s//>/\&gt;}
s=${s//'"'/\&quot;}
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
bytes=$(du -sb "$file" | cut -f1)
if (( bytes > 1000 )); then
size=$(echo "$bytes" | numfmt --to=iec --suffix=B | sed -r 's/([A-Z])/ \1/')
echo "${body//(\[P\])/($size)}"> "$info"
fi
fi
sleep 1
done