feat: Detect platform from ISO

This commit is contained in:
Kroese 2024-05-09 18:21:13 +02:00 committed by GitHub
parent 5a000c1f9e
commit 6cffdcca00
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -662,13 +662,13 @@ selectVersion() {
return 0 return 0
} }
detectVersion() { checkPlatform() {
local xml="$1" local xml="$1"
local id arch
local tag="ARCH" local tag="ARCH"
local platform="x64" local platform="x64"
local compat="$platform" local compat="$platform"
local arch
arch=$(sed -n "/$tag/{s/.*<$tag>\(.*\)<\/$tag>.*/\1/;p}" <<< "$xml") arch=$(sed -n "/$tag/{s/.*<$tag>\(.*\)<\/$tag>.*/\1/;p}" <<< "$xml")
@ -678,16 +678,22 @@ detectVersion() {
"12" )platform="arm64"; compat="$platform" ;; "12" )platform="arm64"; compat="$platform" ;;
esac esac
if [[ "${compat,,}" != "${PLATFORM,,}" ]]; then [[ "${compat,,}" == "${PLATFORM,,}" ]] && return 0
error "You cannot boot ${platform^^} images on a $PLATFORM cpu!"
exit 67 error "You cannot boot ${platform^^} images on a $PLATFORM cpu!"
fi return 1
}
detectVersion() {
local xml="$1"
local id
id=$(selectVersion "DISPLAYNAME" "$xml" "$platform") id=$(selectVersion "DISPLAYNAME" "$xml" "$platform")
[ -z "$id" ] && id=$(selectVersion "PRODUCTNAME" "$xml" "$platform") [ -z "$id" ] && id=$(selectVersion "PRODUCTNAME" "$xml" "$platform")
[ -z "$id" ] && id=$(selectVersion "NAME" "$xml" "$platform") [ -z "$id" ] && id=$(selectVersion "NAME" "$xml" "$platform")
[ -n "$id" ] && [[ "${id,,}" != *"unknown"* ]] && echo "$id" && return 0
echo "$id"
return 0 return 0
} }
@ -740,6 +746,8 @@ detectImage() {
fi fi
info=$(wimlib-imagex info -xml "$loc" | tr -d '\000') info=$(wimlib-imagex info -xml "$loc" | tr -d '\000')
! checkPlatform "$info" && exit 67
DETECTED=$(detectVersion "$info") DETECTED=$(detectVersion "$info")
if [ -z "$DETECTED" ]; then if [ -z "$DETECTED" ]; then