Unverified Commit 9fa68908 authored by Kroese's avatar Kroese Committed by GitHub
Browse files

feat: Show download progress (#608)

parent 740dbec1
Loading
Loading
Loading
Loading
+17 −1
Original line number Diff line number Diff line
@@ -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

src/progress.sh

0 → 100644
+32 −0
Original line number Diff line number Diff line
#!/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