From fca9072898878beb9a92e3b271bec6f554a9da56 Mon Sep 17 00:00:00 2001 From: Kroese Date: Thu, 16 May 2024 19:59:16 +0200 Subject: [PATCH] feat: Refactor download code --- src/install.sh | 66 +++++++++++++++++++++++++------------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/src/install.sh b/src/install.sh index 58a555d..f4278f3 100644 --- a/src/install.sh +++ b/src/install.sh @@ -342,19 +342,6 @@ extractImage() { return 0 } -setXML() { - - local file="/custom.xml" - [ ! -f "$file" ] || [ ! -s "$file" ] && file="$STORAGE/custom.xml" - [ ! -f "$file" ] || [ ! -s "$file" ] && file="/run/assets/custom.xml" - [ ! -f "$file" ] || [ ! -s "$file" ] && file="$1" - [ ! -f "$file" ] || [ ! -s "$file" ] && file="/run/assets/$DETECTED.xml" - [ ! -f "$file" ] || [ ! -s "$file" ] && return 1 - - XML="$file" - return 0 -} - getPlatform() { local xml="$1" @@ -374,6 +361,26 @@ getPlatform() { return 0 } +checkPlatform() { + + local xml="$1" + local platform compat + + platform=$(getPlatform "$xml") + + case "${platform,,}" in + "x86" ) compat="x64" ;; + "x64" ) compat="$platform" ;; + "arm64" ) compat="$platform" ;; + * ) compat="${PLATFORM,,}" ;; + esac + + [[ "${compat,,}" == "${PLATFORM,,}" ]] && return 0 + + error "You cannot boot ${platform^^} images on a $PLATFORM CPU!" + return 1 +} + hasVersion() { local id="$1" @@ -419,26 +426,6 @@ selectVersion() { return 0 } -checkPlatform() { - - local xml="$1" - local platform compat - - platform=$(getPlatform "$xml") - - case "${platform,,}" in - "x86" ) compat="x64" ;; - "x64" ) compat="$platform" ;; - "arm64" ) compat="$platform" ;; - * ) compat="${PLATFORM,,}" ;; - esac - - [[ "${compat,,}" == "${PLATFORM,,}" ]] && return 0 - - error "You cannot boot ${platform^^} images on a $PLATFORM CPU!" - return 1 -} - detectVersion() { local xml="$1" @@ -453,6 +440,19 @@ detectVersion() { return 0 } +setXML() { + + local file="/custom.xml" + [ ! -f "$file" ] || [ ! -s "$file" ] && file="$STORAGE/custom.xml" + [ ! -f "$file" ] || [ ! -s "$file" ] && file="/run/assets/custom.xml" + [ ! -f "$file" ] || [ ! -s "$file" ] && file="$1" + [ ! -f "$file" ] || [ ! -s "$file" ] && file="/run/assets/$DETECTED.xml" + [ ! -f "$file" ] || [ ! -s "$file" ] && return 1 + + XML="$file" + return 0 +} + detectImage() { local dir="$1"