From 9fa68908a9dad557d4533c176acd62b1c413ca4c Mon Sep 17 00:00:00 2001 From: Kroese Date: Mon, 29 Jan 2024 05:40:06 +0100 Subject: [PATCH] feat: Show download progress (#608) --- src/install.sh | 18 +++++++++++++++++- src/progress.sh | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 src/progress.sh diff --git a/src/install.sh b/src/install.sh index b035068..3e928e1 100644 --- a/src/install.sh +++ b/src/install.sh @@ -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 diff --git a/src/progress.sh b/src/progress.sh new file mode 100644 index 0000000..3f774fe --- /dev/null +++ b/src/progress.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +set -Eeuo pipefail + +escape () { + local s + s=${1//&/\&} + s=${s///\>} + s=${s//'"'/\"} + printf -- %s "$s" + return 0 +} + +file="$1" +body=$(escape "$2") +info="/run/shm/msg.html" + +if [[ "$body" == *"..." ]]; then + body="

${body/.../}

" +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