From 9fec576377eff1cc5f0e95deb6ed10d424b7e6eb Mon Sep 17 00:00:00 2001 From: Kroese Date: Mon, 29 Jan 2024 03:05:48 +0100 Subject: [PATCH 1/6] feat: Show download progress --- src/progress.sh | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/progress.sh diff --git a/src/progress.sh b/src/progress.sh new file mode 100644 index 00000000..4d31de38 --- /dev/null +++ b/src/progress.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash +set -Eeuo pipefail + +info="/run/shm/msg.html" + +escape () { + local s + s=${1//&/\&} + s=${s///\>} + s=${s//'"'/\"} + printf -- %s "$s" + return 0 +} + +file="$1" +body=$(escape "$2") + +if [[ "$body" == *"..." ]]; then + body="

${body/.../}

" +fi + +while true +do + mb=$(ls -s --block-size=1048576 "$file" | cut -d' ' -f1) + out="${body//[P]/$mb;}" + echo "$out" > "$info" + sleep 1 +done From a4655740548aeaec4e1753a703a87ae08dd3d6b2 Mon Sep 17 00:00:00 2001 From: Kroese Date: Mon, 29 Jan 2024 03:10:10 +0100 Subject: [PATCH 2/6] feat: Show download progress --- src/install.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/install.sh b/src/install.sh index e8485377..2f76864b 100644 --- a/src/install.sh +++ b/src/install.sh @@ -37,11 +37,16 @@ rm -f "$TMP" MSG="Downloading $BASE as boot image..." info "$MSG" && html "$MSG" +/run/progress.sh "$TMP" "Downloading $BASE ([P])..." & { 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 [ ! -f "$TMP" ] && error "Failed to download $BOOT" && exit 61 +html "Download finished successfully..." + SIZE=$(stat -c%s "$TMP") if ((SIZE<100000)); then @@ -50,5 +55,4 @@ fi mv -f "$TMP" "$STORAGE/$BASE" -html "Download finished successfully..." return 0 From 59bbbe9476296190aea608dc625376735069cb76 Mon Sep 17 00:00:00 2001 From: Kroese Date: Mon, 29 Jan 2024 03:11:48 +0100 Subject: [PATCH 3/6] Update progress.sh --- src/progress.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/progress.sh b/src/progress.sh index 4d31de38..b9f578ef 100644 --- a/src/progress.sh +++ b/src/progress.sh @@ -22,8 +22,8 @@ fi while true do - mb=$(ls -s --block-size=1048576 "$file" | cut -d' ' -f1) - out="${body//[P]/$mb;}" + mb=$(ls -s --block-size=1048576 "$file" | cut -d' ' -f1) + out="${body//(\[P\])/( $mb MB );}" echo "$out" > "$info" - sleep 1 + sleep 1 done From 08aa96e493a6a5dbf480092137b26b28925ec176 Mon Sep 17 00:00:00 2001 From: Kroese Date: Mon, 29 Jan 2024 03:25:42 +0100 Subject: [PATCH 4/6] Update progress.sh --- src/progress.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/progress.sh b/src/progress.sh index b9f578ef..1d3f39aa 100644 --- a/src/progress.sh +++ b/src/progress.sh @@ -22,8 +22,9 @@ fi while true do - mb=$(ls -s --block-size=1048576 "$file" | cut -d' ' -f1) - out="${body//(\[P\])/( $mb MB );}" - echo "$out" > "$info" + if [ -f "$file" ]; then + size=$(stat -c '%s' "$file" | numfmt --to=si --suffix=B) + echo "${body//(\[P\])/($size)}"> "$info" + fi sleep 1 done From 0b4925b400f4ca6aba42a62494356ee88cbd445f Mon Sep 17 00:00:00 2001 From: Kroese Date: Mon, 29 Jan 2024 03:28:24 +0100 Subject: [PATCH 5/6] Update progress.sh --- src/progress.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/progress.sh b/src/progress.sh index 1d3f39aa..1b88d9af 100644 --- a/src/progress.sh +++ b/src/progress.sh @@ -1,8 +1,6 @@ #!/usr/bin/env bash set -Eeuo pipefail -info="/run/shm/msg.html" - escape () { local s s=${1//&/\&} @@ -15,6 +13,7 @@ escape () { file="$1" body=$(escape "$2") +info="/run/shm/msg.html" if [[ "$body" == *"..." ]]; then body="

${body/.../}

" From 8b0fb060e1d650025a9bddb4a9302ba1dcbc4a45 Mon Sep 17 00:00:00 2001 From: Kroese Date: Mon, 29 Jan 2024 03:41:35 +0100 Subject: [PATCH 6/6] Update install.sh --- src/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/install.sh b/src/install.sh index 2f76864b..fb97c55c 100644 --- a/src/install.sh +++ b/src/install.sh @@ -34,7 +34,7 @@ BASE=$(echo "$BASE" | sed -e 's/[^A-Za-z0-9._-]/_/g') TMP="$STORAGE/${BASE%.*}.tmp" rm -f "$TMP" -MSG="Downloading $BASE as boot image..." +MSG="Downloading $BASE ..." info "$MSG" && html "$MSG" /run/progress.sh "$TMP" "Downloading $BASE ([P])..." &