Skip to content

Commit 2016dc8

Browse files
authored
feat: Show download progress (#126)
1 parent 8207169 commit 2016dc8

File tree

1 file changed

+37
-31
lines changed

1 file changed

+37
-31
lines changed

src/install.sh

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,7 @@ abortInstall() {
185185

186186
startInstall() {
187187

188-
local magic desc
189-
local msg="Windows is being started, please wait..."
188+
html "Starting Windows..."
190189

191190
if [ -f "$STORAGE/$CUSTOM" ]; then
192191

@@ -207,36 +206,24 @@ startInstall() {
207206

208207
BASE="$VERSION.iso"
209208

210-
if ! skipInstall && [ ! -f "$STORAGE/$BASE" ]; then
211-
212-
desc=$(printVersion "$VERSION")
213-
[ -z "$desc" ] && desc="Windows"
214-
msg="$desc is being downloaded, please wait..."
215-
fi
216-
217209
else
218210

219211
BASE=$(basename "${VERSION%%\?*}")
220212
: "${BASE//+/ }"; printf -v BASE '%b' "${_//%/\\x}"
221213
BASE=$(echo "$BASE" | sed -e 's/[^A-Za-z0-9._-]/_/g')
222214

223-
if ! skipInstall && [ ! -f "$STORAGE/$BASE" ]; then
224-
msg="Image '$BASE' is being downloaded, please wait..."
225-
fi
226-
227215
fi
228216

229217
[[ "${BASE,,}" == "custom."* ]] && BASE="windows.iso"
230218

231219
fi
232220

233-
html "$msg"
234-
235221
[ -z "$MANUAL" ] && MANUAL="N"
236222

237223
if [ -f "$STORAGE/$BASE" ]; then
238224

239225
# Check if the ISO was already processed by our script
226+
local magic=""
240227
magic=$(dd if="$STORAGE/$BASE" seek=0 bs=1 count=1 status=none | tr -d '\000')
241228
magic="$(printf '%s' "$magic" | od -A n -t x1 -v | tr -d ' \n')"
242229

@@ -277,34 +264,53 @@ downloadImage() {
277264

278265
local iso="$1"
279266
local url="$2"
280-
local progress
267+
local file="$iso"
268+
local desc="$BASE"
269+
local rc progress
270+
281271
rm -f "$iso"
282272

283273
if [[ "$EXTERNAL" != [Yy1]* ]]; then
284274

285-
cd "$TMP"
286-
if ! /run/mido.sh "$url"; then
287-
return 1
288-
fi
289-
cd /run
275+
file="$iso.PART"
276+
desc=$(printVersion "$VERSION")
277+
[ -z "$desc" ] && desc="Windows"
290278

291-
[ ! -f "$iso" ] && return 1
292-
return 0
293279
fi
294280

295-
info "Downloading $BASE as boot image..."
281+
local msg="Downloading $desc..."
282+
info "$msg" && html "$msg"
283+
284+
/run/progress.sh "$file" "Downloading $desc ([P])..." &
285+
286+
if [[ "$EXTERNAL" != [Yy1]* ]]; then
287+
288+
cd "$TMP"
289+
{ /run/mido.sh "$url"; rc=$?; } || :
290+
cd /run
291+
292+
fKill "progress.sh"
293+
(( rc != 0 )) && return 1
296294

297-
# Check if running with interactive TTY or redirected to docker log
298-
if [ -t 1 ]; then
299-
progress="--progress=bar:noscroll"
300295
else
301-
progress="--progress=dot:giga"
302-
fi
303296

304-
{ wget "$url" -O "$iso" -q --no-check-certificate --show-progress "$progress"; rc=$?; } || :
305-
(( rc != 0 )) && error "Failed to download $url , reason: $rc" && exit 60
297+
# Check if running with interactive TTY or redirected to docker log
298+
if [ -t 1 ]; then
299+
progress="--progress=bar:noscroll"
300+
else
301+
progress="--progress=dot:giga"
302+
fi
303+
304+
{ wget "$url" -O "$iso" -q --no-check-certificate --show-progress "$progress"; rc=$?; } || :
305+
306+
fKill "progress.sh"
307+
(( rc != 0 )) && error "Failed to download $url , reason: $rc" && exit 60
308+
309+
fi
306310

307311
[ ! -f "$iso" ] && return 1
312+
313+
html "Download finished successfully..."
308314
return 0
309315
}
310316

0 commit comments

Comments
 (0)