feat: Move image edition selection policy (#2118)

This commit is contained in:
Kroese
2026-08-08 17:39:43 +02:00
committed by GitHub
parent 43be9024e9
commit 133c3d3bc3
2 changed files with 128 additions and 95 deletions
+120 -32
View File
@@ -638,6 +638,38 @@ fromName() {
return 0
}
getVersion() {
local name="$1"
local arch="$2"
local id edition
local evaluation=""
id=$(fromName "$name" "$arch")
[[ "${name,,}" == *"evaluation"* ]] && evaluation="-eval"
case "${id,,}" in
"winvista"* | "win7"* | "win8"* | "win10"* | "win11"* )
if edition=$(getEditionID "$name" "$id"); then
[ -n "$edition" ] && id+="-$edition"
[ -n "$evaluation" ] && id+="$evaluation"
fi
;;
"win20"* )
if [[ "${name,,}" == *"hyper-v server"* ]]; then
id+="-hv"
elif edition=$(getServerEditionID "$name" "$id"); then
[ -n "$edition" ] && id+="-$edition"
[ -n "$evaluation" ] && id+="$evaluation"
fi
;;
esac
echo "$id"
return 0
}
isClientEdition() {
case "${1,,}" in
@@ -651,6 +683,94 @@ isClientEdition() {
return 1
}
getEditionRank() {
local id="${1,,}"
local base="${id%%-*}"
local edition
id="${id%-eval}"
edition="${id#"$base"}"
edition="${edition#-}"
case "$base" in
"win20"* )
case "$edition" in
"" ) echo 0 ;;
"datacenter-azure-core" | "datacenter-azure-core-"* | \
"datacenter-core" | "datacenter-core-"* ) echo 7 ;;
"enterprise-core" | "enterprise-core-"* ) echo 8 ;;
"web-core" | "web-core-"* ) echo 9 ;;
"standard-core" | "standard-core-"* ) echo 6 ;;
"datacenter" | "datacenter-"* ) echo 1 ;;
"enterprise" | "enterprise-"* ) echo 2 ;;
"web" | "web-"* ) echo 3 ;;
"foundation" | "foundation-"* ) echo 4 ;;
"essentials" | "essentials-"* ) echo 5 ;;
"hv" | "hv-"* ) echo 10 ;;
* ) echo 99 ;;
esac
;;
* )
case "$edition" in
"enterprise-iot" | "enterprise-iot-"* | "iot" | "iot-"* ) echo 3 ;;
"enterprise-ltsc" | "enterprise-ltsc-"* | "ltsc" | "ltsc-"* ) echo 4 ;;
"pro-education" | "pro-education-"* | "education" | "education-"* ) echo 5 ;;
"enterprise" | "enterprise-"* ) echo 0 ;;
"ultimate" | "ultimate-"* ) echo 1 ;;
"" | "n" | "pro" | "pro-"* | "professional" | "professional-"* | \
"business" | "business-"* ) echo 2 ;;
"home" | "home-"* ) echo 6 ;;
"starter" | "starter-"* ) echo 7 ;;
* ) echo 99 ;;
esac
;;
esac
return 0
}
getEditionPolicy() {
local base="${1,,}"
case "$base" in
"win20"* )
printf '%s\n' \
"normalizeServerEditionID" \
"" \
"-datacenter" \
"-datacenter-azure" \
"-enterprise" \
"-web" \
"-foundation" \
"-essentials" \
"-standard-core" \
"-datacenter-core" \
"-datacenter-azure-core" \
"-enterprise-core" \
"-web-core" \
"-hv"
;;
* )
printf '%s\n' \
"normalizeEditionID" \
"-enterprise" \
"-ultimate" \
"" \
"-iot" \
"-ltsc" \
"-education" \
"-home" \
"-home-premium" \
"-home-basic" \
"-starter"
;;
esac
return 0
}
normalizeEdition() {
local source="${1,,}"
@@ -819,38 +939,6 @@ getServerEditionID() {
return 0
}
getVersion() {
local name="$1"
local arch="$2"
local id edition
local evaluation=""
id=$(fromName "$name" "$arch")
[[ "${name,,}" == *"evaluation"* ]] && evaluation="-eval"
case "${id,,}" in
"winvista"* | "win7"* | "win8"* | "win10"* | "win11"* )
if edition=$(getEditionID "$name" "$id"); then
[ -n "$edition" ] && id+="-$edition"
[ -n "$evaluation" ] && id+="$evaluation"
fi
;;
"win20"* )
if [[ "${name,,}" == *"hyper-v server"* ]]; then
id+="-hv"
elif edition=$(getServerEditionID "$name" "$id"); then
[ -n "$edition" ] && id+="-$edition"
[ -n "$evaluation" ] && id+="$evaluation"
fi
;;
esac
echo "$id"
return 0
}
getRequiredMemory() {
local id="${1,,}"
+8 -63
View File
@@ -130,58 +130,13 @@ getVersions() {
return 0
}
getEditionRank() {
local id="${1,,}"
local base="${id%%-*}"
local edition
id="${id%-eval}"
edition="${id#"$base"}"
edition="${edition#-}"
case "$base" in
"win20"* )
case "$edition" in
"" ) echo 0 ;;
"datacenter-azure-core" | "datacenter-azure-core-"* | \
"datacenter-core" | "datacenter-core-"* ) echo 7 ;;
"enterprise-core" | "enterprise-core-"* ) echo 8 ;;
"web-core" | "web-core-"* ) echo 9 ;;
"standard-core" | "standard-core-"* ) echo 6 ;;
"datacenter" | "datacenter-"* ) echo 1 ;;
"enterprise" | "enterprise-"* ) echo 2 ;;
"web" | "web-"* ) echo 3 ;;
"foundation" | "foundation-"* ) echo 4 ;;
"essentials" | "essentials-"* ) echo 5 ;;
"hv" | "hv-"* ) echo 10 ;;
* ) echo 99 ;;
esac
;;
* )
case "$edition" in
"enterprise-iot" | "enterprise-iot-"* | "iot" | "iot-"* ) echo 3 ;;
"enterprise-ltsc" | "enterprise-ltsc-"* | "ltsc" | "ltsc-"* ) echo 4 ;;
"pro-education" | "pro-education-"* | "education" | "education-"* ) echo 5 ;;
"enterprise" | "enterprise-"* ) echo 0 ;;
"ultimate" | "ultimate-"* ) echo 1 ;;
"" | "n" | "pro" | "pro-"* | "professional" | "professional-"* | \
"business" | "business-"* ) echo 2 ;;
"home" | "home-"* ) echo 6 ;;
"starter" | "starter-"* ) echo 7 ;;
* ) echo 99 ;;
esac
;;
esac
}
selectVersion() {
local wanted="$1"
shift
local candidate record id index
local -a candidates=("$wanted")
local candidate record id index
# Normal and Evaluation variants of the same edition are compatible.
if [[ "${wanted,,}" == *"-eval" ]]; then
@@ -211,9 +166,8 @@ detectVersion() {
local xml="$1"
local normalize="normalizeEditionID"
local output record id index base edition suffix
local -a images=() bases=() order=()
local -a images=() bases=() order=() preferences=()
local normalize output policy record id index base edition suffix
output=$(getVersions "$xml") || return
[ -n "$output" ] && mapfile -t images <<< "$output"
@@ -228,20 +182,11 @@ detectVersion() {
bases+=("${id%%-*}")
done
case "${bases[0],,}" in
"win20"* )
normalize="normalizeServerEditionID"
order=(
"" "-datacenter" "-datacenter-azure" "-enterprise" "-web"
"-foundation" "-essentials" "-standard-core" "-datacenter-core"
"-datacenter-azure-core" "-enterprise-core" "-web-core" "-hv"
) ;;
* )
order=(
"-enterprise" "-ultimate" "" "-iot" "-ltsc" "-education"
"-home" "-home-premium" "-home-basic" "-starter"
) ;;
esac
policy=$(getEditionPolicy "${bases[0]}") || return 1
mapfile -t preferences <<< "$policy"
normalize="${preferences[0]}"
order=("${preferences[@]:1}")
# An explicit EDITION always gets first choice.
if [ -n "$EDITION" ]; then