diff --git a/src/install.sh b/src/install.sh index 6cac43e..24e1221 100644 --- a/src/install.sh +++ b/src/install.sh @@ -1,6 +1,45 @@ #!/usr/bin/env bash set -Eeuo pipefail +file=$(find / -maxdepth 1 -type f -iname boot.iso | head -n 1) +[ ! -s "$file" ] && file=$(find "$STORAGE" -maxdepth 1 -type f -iname boot.iso | head -n 1) + +if [ ! -s "$file" ] && [[ "${BOOT,,}" != "http"* ]]; then + base=$(basename "$BOOT") + file="$STORAGE/$base" +fi + +if [ -f "$file" ] && [ -s "$file" ]; then + BOOT="$file" + return 0 +fi + +if [ -z "$BOOT" ]; then + hasDisk && return 0 + error "No boot disk specified, set BOOT= to the URL of an ISO file." && exit 64 +fi + +base=$(basename "$BOOT") +file="$STORAGE/$base" + +if [ -f "$file" ] && [ -s "$file" ]; then + BOOT="$file" + return 0 +fi + +base=$(basename "${BOOT%%\?*}") +: "${base//+/ }"; printf -v base '%b' "${_//%/\\x}" +base=$(echo "$base" | sed -e 's/[^A-Za-z0-9._-]/_/g') +file="$STORAGE/$base" + +if [ -f "$file" ] && [ -s "$file" ]; then + BOOT="$file" + return 0 +fi + +TMP="$STORAGE/${base%.*}.tmp" +rm -f "$TMP" + # Check if running with interactive TTY or redirected to docker log if [ -t 1 ]; then progress="--progress=bar:noscroll" @@ -8,36 +47,11 @@ else progress="--progress=dot:giga" fi -file="/boot.iso" && [ -f "$file" ] && [ -s "$file" ] && BOOT="$file" && return 0 -file="/boot.img" && [ -f "$file" ] && [ -s "$file" ] && BOOT="$file" && return 0 - -file=$(find "$STORAGE" -maxdepth 1 -type f -iname boot.iso -printf "%f\n" | head -n 1) -[ -z "$file" ] && file=$(find "$STORAGE" -maxdepth 1 -type f -iname boot.img -printf "%f\n" | head -n 1) -[ -n "$file" ] && file="$STORAGE/$file" -[ -f "$file" ] && [ -s "$file" ] && BOOT="$file" && return 0 - -if [ -z "$BOOT" ]; then - error "No boot disk specified, set BOOT= to the URL of an ISO file." && exit 64 -fi - -base=$(basename "$BOOT") -[ -n "$base" ] && file="$STORAGE/$base" -[ -f "$file" ] && [ -s "$file" ] && BOOT="$file" && return 0 - -base=$(basename "${BOOT%%\?*}") -: "${base//+/ }"; printf -v base '%b' "${_//%/\\x}" -base=$(echo "$base" | sed -e 's/[^A-Za-z0-9._-]/_/g') -[ -n "$base" ] && file="$STORAGE/$base" -[ -f "$file" ] && [ -s "$file" ] && BOOT="$file" && return 0 - -TMP="$STORAGE/${base%.*}.tmp" -rm -f "$TMP" - msg="Downloading $base..." info "$msg" && html "$msg" /run/progress.sh "$TMP" "" "Downloading $base ([P])..." & -{ wget "$BOOT" -O "$TMP" -q --timeout=10 --show-progress "$progress"; rc=$?; } || : +{ wget "$BOOT" -O "$TMP" -q --timeout=30 --show-progress "$progress"; rc=$?; } || : fKill "progress.sh"