feat: Pretty print image name

This commit is contained in:
Kroese 2024-01-27 14:01:38 +01:00 committed by GitHub
parent d02fa6cca1
commit 08219f7e0a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -311,14 +311,14 @@ extractImage() {
return 0
}
findVersion() {
getVersion() {
local name="$1"
local detected=""
[[ "${name,,}" == *"windows 11"* ]] && detected="win11x64"
[[ "${name,,}" == *"windows 8"* ]] && detected="win81x64"
[[ "${name,,}" == *"windows 7"* ]] && detected="win7x64"
[[ "${name,,}" == *"windows 8"* ]] && detected="win81x64"
[[ "${name,,}" == *"windows 11"* ]] && detected="win11x64"
[[ "${name,,}" == *"windows vista"* ]] && detected="winvistax64"
[[ "${name,,}" == *"server 2022"* ]] && detected="win2022-eval"
[[ "${name,,}" == *"server 2019"* ]] && detected="win2019-eval"
@ -336,6 +336,25 @@ findVersion() {
return 0
}
printVersion() {
local id="$1"
local desc=""
[[ "$id" == "win7"* ]] && desc="Windows 7"
[[ "$id" == "win8"* ]] && desc="Windows 8"
[[ "$id" == "win10"* ]] && desc="Windows 10"
[[ "$id" == "win11"* ]] && desc="Windows 11"
[[ "$id" == "winvista"* ]] && desc="Windows Vista"
[[ "$id" == "win2022"* ]] && desc="Windows Server 2022"
[[ "$id" == "win2019"* ]] && desc="Windows Server 2019"
[[ "$id" == "win2016"* ]] && desc="Windows Server 2016"
[[ "$id" == "win10x64-ltsc" ]] && desc="Windows 10 LTSC"
echo "$desc"
return 0
}
detectImage() {
XML=""
@ -349,18 +368,24 @@ detectImage() {
fi
if [ -n "$DETECTED" ]; then
if [ -f "/run/assets/$DETECTED.xml" ]; then
[[ "$MANUAL" != [Yy1]* ]] && XML="$DETECTED.xml"
return 0
fi
warn "image type is '$DETECTED', but no matching XML file exists!"
local dsc
dsc=$(printVersion "$DETECTED")
[ -z "$dsc" ] && dsc="$DETECTED"
warn "image type is '$dsc', but no matching XML file exists!"
return 0
fi
info "Detecting Windows version from ISO image..."
local dir="$1"
local tag result name name2
local tag result name name2 desc
local loc="$dir/sources/install.wim"
[ ! -f "$loc" ] && loc="$dir/sources/install.esd"
@ -373,24 +398,27 @@ detectImage() {
tag="DISPLAYNAME"
result=$(wimlib-imagex info -xml "$loc" | tr -d '\000')
name=$(sed -n "/$tag/{s/.*<$tag>\(.*\)<\/$tag>.*/\1/;p}" <<< "$result")
DETECTED=$(findVersion "$name")
DETECTED=$(getVersion "$name")
if [ -z "$DETECTED" ]; then
tag="PRODUCTNAME"
name2=$(sed -n "/$tag/{s/.*<$tag>\(.*\)<\/$tag>.*/\1/;p}" <<< "$result")
[ -z "$name" ] && name="$name2"
DETECTED=$(findVersion "$name2")
DETECTED=$(getVersion "$name2")
fi
if [ -n "$DETECTED" ]; then
desc=$(printVersion "$DETECTED")
[ -z "$desc" ] && desc="$DETECTED"
if [ -f "/run/assets/$DETECTED.xml" ]; then
[[ "$MANUAL" != [Yy1]* ]] && XML="$DETECTED.xml"
info "Detected image of type: '$DETECTED'"
info "Detected image of type: '$desc'"
else
warn "detected image of type '$DETECTED', but no matching XML file exists, $FB."
warn "detected image of type '$desc', but no matching XML file exists, $FB."
fi
else