Update install.sh

This commit is contained in:
Kroese 2024-05-22 16:58:11 +02:00 committed by GitHub
parent 359936cfb2
commit b40832c08e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,36 +1,31 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -Eeuo pipefail set -Eeuo pipefail
file=$(find / -maxdepth 1 -type f -iname boot.iso | head -n 1) iso () {
[ ! -s "$file" ] && file=$(find "$STORAGE" -maxdepth 1 -type f -iname boot.iso | head -n 1) local file="$1"
[ ! -f "$file" ] && return 1
[ ! -s "$file" ] && return 1
if [ -f "$file" ] && [ -s "$file" ]; then
BOOT="$file" BOOT="$file"
return 0 return 0
fi }
if [ -z "$BOOT" ]; then 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)
iso "$file" && return 0
if [ -z "$BOOT" ] || [[ "$BOOT" == *"example.com/image.iso" ]]; then
hasDisk && return 0 hasDisk && return 0
error "No boot disk specified, set BOOT= to the URL of an ISO file." && exit 64 error "No boot disk specified, set BOOT= to the URL of an ISO file." && exit 64
fi fi
base=$(basename "$BOOT") base=$(basename "$BOOT")
file="$STORAGE/$base" iso "$STORAGE/$base" && return 0
if [ -f "$file" ] && [ -s "$file" ]; then
BOOT="$file"
return 0
fi
base=$(basename "${BOOT%%\?*}") base=$(basename "${BOOT%%\?*}")
: "${base//+/ }"; printf -v base '%b' "${_//%/\\x}" : "${base//+/ }"; printf -v base '%b' "${_//%/\\x}"
base=$(echo "$base" | sed -e 's/[^A-Za-z0-9._-]/_/g') base=$(echo "$base" | sed -e 's/[^A-Za-z0-9._-]/_/g')
file="$STORAGE/$base" iso "$STORAGE/$base" && return 0
if [ -f "$file" ] && [ -s "$file" ]; then
BOOT="$file"
return 0
fi
TMP="$STORAGE/${base%.*}.tmp" TMP="$STORAGE/${base%.*}.tmp"
rm -f "$TMP" rm -f "$TMP"
@ -62,6 +57,7 @@ if ((size<100000)); then
error "Invalid ISO file: Size is smaller than 100 KB" && exit 62 error "Invalid ISO file: Size is smaller than 100 KB" && exit 62
fi fi
mv -f "$TMP" "$file" mv -f "$TMP" "$STORAGE/$base"
! iso "$STORAGE/$base" && exit 63
return 0 return 0