Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Show download progress #398

Merged
merged 6 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,19 @@ 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])..." &
{ 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
Expand All @@ -50,5 +55,4 @@ fi

mv -f "$TMP" "$STORAGE/$BASE"

html "Download finished successfully..."
return 0
29 changes: 29 additions & 0 deletions src/progress.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash
set -Eeuo pipefail

escape () {
local s
s=${1//&/\&amp;}
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
size=$(stat -c '%s' "$file" | numfmt --to=si --suffix=B)
echo "${body//(\[P\])/($size)}"> "$info"
fi
sleep 1
done