mirror of
https://github.com/dockur/windows.git
synced 2026-08-24 07:39:00 +01:00
feat: Centralize image and boot state checks (#2137)
This commit is contained in:
+6
-6
@@ -400,9 +400,9 @@ extractImage() {
|
|||||||
local archive="${dir}.archive"
|
local archive="${dir}.archive"
|
||||||
local file size required archiveSize rc
|
local file size required archiveSize rc
|
||||||
|
|
||||||
if [ -z "$CUSTOM" ]; then
|
if ! isCustomImage; then
|
||||||
desc="downloaded ISO"
|
desc="downloaded ISO"
|
||||||
if [[ "$version" != "http"* ]]; then
|
if ! isURL "$version"; then
|
||||||
desc=$(printVariant "$version" "$desc")
|
desc=$(printVariant "$version" "$desc")
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@@ -1652,7 +1652,7 @@ extractESD() {
|
|||||||
|
|
||||||
index=""
|
index=""
|
||||||
|
|
||||||
if [[ "${version,,}" == "http"* ]]; then
|
if isURL "$version"; then
|
||||||
|
|
||||||
# Direct ESD URLs have no catalog identity. Restrict automatic detection
|
# Direct ESD URLs have no catalog identity. Restrict automatic detection
|
||||||
# to installable images because indexes 1-3 contain setup components.
|
# to installable images because indexes 1-3 contain setup components.
|
||||||
@@ -1758,7 +1758,7 @@ extractESD() {
|
|||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "${version,,}" != "http"* ]] &&
|
if ! isURL "$version" &&
|
||||||
[[ "${resultEdition,,}" != "${edition,,}" ]]; then
|
[[ "${resultEdition,,}" != "${edition,,}" ]]; then
|
||||||
error "Prepared install.esd does not contain only '$edition' at index 1!"
|
error "Prepared install.esd does not contain only '$edition' at index 1!"
|
||||||
return 1
|
return 1
|
||||||
@@ -1925,7 +1925,7 @@ buildImage() {
|
|||||||
|
|
||||||
checkFreeSpace "$TMP" "$size" || return 1
|
checkFreeSpace "$TMP" "$size" || return 1
|
||||||
|
|
||||||
if [[ "${BOOT_MODE,,}" == "windows_legacy" ]] && [ -z "${BOOT_LOAD_SIZE:-}" ]; then
|
if isLegacyBoot && [ -z "${BOOT_LOAD_SIZE:-}" ]; then
|
||||||
if [[ "${DETECTED,,}" != "win9"* && "${DETECTED,,}" != "winnt4" ]]; then
|
if [[ "${DETECTED,,}" != "win9"* && "${DETECTED,,}" != "winnt4" ]]; then
|
||||||
error "Failed to determine the boot image load size!"
|
error "Failed to determine the boot image load size!"
|
||||||
return 1
|
return 1
|
||||||
@@ -1951,7 +1951,7 @@ buildImage() {
|
|||||||
|
|
||||||
# Use separate layouts for modern hybrid media, NT 5.x legacy media, Win9x,
|
# Use separate layouts for modern hybrid media, NT 5.x legacy media, Win9x,
|
||||||
# and other legacy releases because their El Torito requirements differ.
|
# and other legacy releases because their El Torito requirements differ.
|
||||||
if [[ "${BOOT_MODE,,}" != "windows_legacy" ]]; then
|
if ! isLegacyBoot; then
|
||||||
|
|
||||||
args+=(
|
args+=(
|
||||||
-no-emul-boot
|
-no-emul-boot
|
||||||
|
|||||||
+36
-17
@@ -151,7 +151,7 @@ configureMachine() {
|
|||||||
|
|
||||||
if ! checkMemory "$DETECTED"; then
|
if ! checkMemory "$DETECTED"; then
|
||||||
|
|
||||||
if [ -z "$CUSTOM" ]; then
|
if ! isCustomImage; then
|
||||||
useOriginalImage "$iso" || {
|
useOriginalImage "$iso" || {
|
||||||
error "Failed to preserve the original installation image!"
|
error "Failed to preserve the original installation image!"
|
||||||
return 79
|
return 79
|
||||||
@@ -295,12 +295,12 @@ startInstall() {
|
|||||||
|
|
||||||
html "Starting $APP..."
|
html "Starting $APP..."
|
||||||
|
|
||||||
if [ -z "$CUSTOM" ]; then
|
if ! isCustomImage; then
|
||||||
|
|
||||||
local file="${VERSION//\//}.iso"
|
local file="${VERSION//\//}.iso"
|
||||||
local boot="$file"
|
local boot="$file"
|
||||||
|
|
||||||
if [[ "${VERSION,,}" == "http"* ]]; then
|
if isURL "$VERSION"; then
|
||||||
|
|
||||||
file=$(basename "${VERSION%%[\?#]*}")
|
file=$(basename "${VERSION%%[\?#]*}")
|
||||||
printf -v file '%b' "${file//%/\\x}"
|
printf -v file '%b' "${file//%/\\x}"
|
||||||
@@ -385,7 +385,7 @@ startInstall() {
|
|||||||
return 50
|
return 50
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$CUSTOM" ]; then
|
if ! isCustomImage; then
|
||||||
|
|
||||||
if [ -s "$BOOT" ]; then
|
if [ -s "$BOOT" ]; then
|
||||||
ISO="$TMP/$(basename "$BOOT")"
|
ISO="$TMP/$(basename "$BOOT")"
|
||||||
@@ -397,7 +397,7 @@ startInstall() {
|
|||||||
|
|
||||||
# Keep existing media at its persistent path until all storage cleanup has
|
# Keep existing media at its persistent path until all storage cleanup has
|
||||||
# completed successfully, so a later failure cannot strand it under $TMP.
|
# completed successfully, so a later failure cannot strand it under $TMP.
|
||||||
if [ -n "$CUSTOM" ] || [ ! -s "$BOOT" ]; then
|
if isCustomImage || [ ! -s "$BOOT" ]; then
|
||||||
if ! rm -f -- "$BOOT"; then
|
if ! rm -f -- "$BOOT"; then
|
||||||
error "Failed to remove obsolete ISO file \"$BOOT\" !"
|
error "Failed to remove obsolete ISO file \"$BOOT\" !"
|
||||||
return 50
|
return 50
|
||||||
@@ -419,14 +419,14 @@ startInstall() {
|
|||||||
return 50
|
return 50
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$CUSTOM" ] && [[ "${VERSION,,}" != "http"* ]]; then
|
if ! isCustomImage && ! isURL "$VERSION"; then
|
||||||
checkMemory "$VERSION" || return 67
|
checkMemory "$VERSION" || return 67
|
||||||
setDiskMinimum "$VERSION" || return 67
|
setDiskMinimum "$VERSION" || return 67
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Work from the temporary directory so the persistent source path can
|
# Work from the temporary directory so the persistent source path can
|
||||||
# later contain either the preserved ISO or the rebuilt installation image.
|
# later contain either the preserved ISO or the rebuilt installation image.
|
||||||
if [ -z "$CUSTOM" ] && [ -f "$BOOT" ] && [ -s "$BOOT" ]; then
|
if ! isCustomImage && [ -f "$BOOT" ] && [ -s "$BOOT" ]; then
|
||||||
if ! mv -f -- "$BOOT" "$ISO"; then
|
if ! mv -f -- "$BOOT" "$ISO"; then
|
||||||
error "Failed to move ISO file from \"$BOOT\" to \"$ISO\" !"
|
error "Failed to move ISO file from \"$BOOT\" to \"$ISO\" !"
|
||||||
return 50
|
return 50
|
||||||
@@ -603,7 +603,7 @@ finishInstall() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$boot" == "$STORAGE/"* ]]; then
|
if [[ "$boot" == "$STORAGE/"* ]]; then
|
||||||
if [[ "$aborted" != [Yy1]* ]] || [ -z "$CUSTOM" ]; then
|
if [[ "$aborted" != [Yy1]* ]] || ! isCustomImage; then
|
||||||
|
|
||||||
base=$(basename "$boot")
|
base=$(basename "$boot")
|
||||||
writeState "base" "$base" || {
|
writeState "base" "$base" || {
|
||||||
@@ -615,7 +615,7 @@ finishInstall() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "${PLATFORM,,}" == "x64" ]]; then
|
if [[ "${PLATFORM,,}" == "x64" ]]; then
|
||||||
if [[ "${BOOT_MODE,,}" == "windows_legacy" ]]; then
|
if isLegacyBoot; then
|
||||||
|
|
||||||
writeState "mode" "$BOOT_MODE" || {
|
writeState "mode" "$BOOT_MODE" || {
|
||||||
error "Failed to save the Windows boot mode!"
|
error "Failed to save the Windows boot mode!"
|
||||||
@@ -707,7 +707,7 @@ findFile() {
|
|||||||
file=$(find "$STORAGE" -maxdepth 1 -type f -iname "$fname" -print -quit) || return 1
|
file=$(find "$STORAGE" -maxdepth 1 -type f -iname "$fname" -print -quit) || return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -s "$file" ] && [[ "${VERSION,,}" != "http"* ]]; then
|
if [ ! -s "$file" ] && ! isURL "$VERSION"; then
|
||||||
base=$(basename "$VERSION")
|
base=$(basename "$VERSION")
|
||||||
file="$STORAGE/$base"
|
file="$STORAGE/$base"
|
||||||
fi
|
fi
|
||||||
@@ -736,7 +736,7 @@ findFile() {
|
|||||||
normalizeDetected() {
|
normalizeDetected() {
|
||||||
|
|
||||||
# Known catalog versions already provide the required image metadata.
|
# Known catalog versions already provide the required image metadata.
|
||||||
if [ -z "$DETECTED" ] && [ -z "$CUSTOM" ] && [[ "${VERSION,,}" != "http"* ]]; then
|
if [ -z "$DETECTED" ] && ! isCustomImage && ! isURL "$VERSION"; then
|
||||||
DETECTED="$VERSION"
|
DETECTED="$VERSION"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -752,14 +752,14 @@ detectCustom() {
|
|||||||
|
|
||||||
findFile "custom.iso" || return 1
|
findFile "custom.iso" || return 1
|
||||||
|
|
||||||
if [ -n "$CUSTOM" ]; then
|
if isCustomImage; then
|
||||||
DETECTED=""
|
DETECTED=""
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
findFile "boot.iso" || return 1
|
findFile "boot.iso" || return 1
|
||||||
|
|
||||||
if [ -n "$CUSTOM" ]; then
|
if isCustomImage; then
|
||||||
DETECTED=""
|
DETECTED=""
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
@@ -767,6 +767,25 @@ detectCustom() {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isCustomImage() {
|
||||||
|
|
||||||
|
[ -n "${CUSTOM:-}" ]
|
||||||
|
}
|
||||||
|
|
||||||
|
isURL() {
|
||||||
|
|
||||||
|
local value="$1"
|
||||||
|
|
||||||
|
[[ "${value,,}" == "http"* ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
isLegacyBoot() {
|
||||||
|
|
||||||
|
local mode="${BOOT_MODE:-}"
|
||||||
|
|
||||||
|
[[ "${mode,,}" == "windows_legacy" ]]
|
||||||
|
}
|
||||||
|
|
||||||
hasImage() {
|
hasImage() {
|
||||||
|
|
||||||
local iso="$1"
|
local iso="$1"
|
||||||
@@ -837,7 +856,7 @@ useOriginalImage() {
|
|||||||
|
|
||||||
local iso="$1"
|
local iso="$1"
|
||||||
|
|
||||||
if [ -n "$CUSTOM" ]; then
|
if isCustomImage; then
|
||||||
BOOT="$iso"
|
BOOT="$iso"
|
||||||
elif [[ "$iso" != "$BOOT" ]]; then
|
elif [[ "$iso" != "$BOOT" ]]; then
|
||||||
if ! mv -f -- "$iso" "$BOOT"; then
|
if ! mv -f -- "$iso" "$BOOT"; then
|
||||||
@@ -858,7 +877,7 @@ removeImage() {
|
|||||||
|
|
||||||
local iso="$1"
|
local iso="$1"
|
||||||
|
|
||||||
[ -n "$CUSTOM" ] && return 0
|
isCustomImage && return 0
|
||||||
|
|
||||||
if ! rm -f -- "$iso" 2>/dev/null; then
|
if ! rm -f -- "$iso" 2>/dev/null; then
|
||||||
warn "failed to remove image \"$iso\"!"
|
warn "failed to remove image \"$iso\"!"
|
||||||
@@ -953,7 +972,7 @@ prepareImage() {
|
|||||||
ETFS="${ETFS:-boot/etfsboot.com}"
|
ETFS="${ETFS:-boot/etfsboot.com}"
|
||||||
|
|
||||||
# Legacy rebuilt media must retain the source ISO's El Torito boot-load size.
|
# Legacy rebuilt media must retain the source ISO's El Torito boot-load size.
|
||||||
if [[ "${BOOT_MODE,,}" == "windows_legacy" ]]; then
|
if isLegacyBoot; then
|
||||||
|
|
||||||
getBootLoadSize "$iso" "$dir" "$desc" || return 1
|
getBootLoadSize "$iso" "$dir" "$desc" || return 1
|
||||||
|
|
||||||
@@ -961,7 +980,7 @@ prepareImage() {
|
|||||||
|
|
||||||
supportsXML "$DETECTED" || return 0
|
supportsXML "$DETECTED" || return 0
|
||||||
|
|
||||||
if [[ "${BOOT_MODE,,}" == "windows_legacy" ]]; then
|
if isLegacyBoot; then
|
||||||
|
|
||||||
extractBootImage "$iso" "$dir" "$desc" && return 0
|
extractBootImage "$iso" "$dir" "$desc" && return 0
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1277,7 +1277,7 @@ downloadImage() {
|
|||||||
local tried="n" success="n" seconds="5"
|
local tried="n" success="n" seconds="5"
|
||||||
local i url sum size base language desc web_desc rc
|
local i url sum size base language desc web_desc rc
|
||||||
|
|
||||||
if [[ "${version,,}" == "http"* ]]; then
|
if isURL "$version"; then
|
||||||
|
|
||||||
base=$(basename "$iso")
|
base=$(basename "$iso")
|
||||||
desc=$(fromFile "$base")
|
desc=$(fromFile "$base")
|
||||||
|
|||||||
+5
-5
@@ -28,7 +28,7 @@ bootStatus() {
|
|||||||
|
|
||||||
[ ! -s "$QEMU_PTY" ] && return 1
|
[ ! -s "$QEMU_PTY" ] && return 1
|
||||||
|
|
||||||
if [[ "${BOOT_MODE,,}" == "windows_legacy" ]]; then
|
if isLegacyBoot; then
|
||||||
local line last recent
|
local line last recent
|
||||||
|
|
||||||
# Only inspect output produced after the most recent BIOS boot attempt so
|
# Only inspect output produced after the most recent BIOS boot attempt so
|
||||||
@@ -130,7 +130,7 @@ waitForBoot() {
|
|||||||
elif bootKeyReady; then
|
elif bootKeyReady; then
|
||||||
(( keyWait += 1 ))
|
(( keyWait += 1 ))
|
||||||
|
|
||||||
if [[ "${BOOT_MODE,,}" == "windows_legacy" ]]; then
|
if isLegacyBoot; then
|
||||||
# Keep the legacy fallback at about one second after the DVD marker.
|
# Keep the legacy fallback at about one second after the DVD marker.
|
||||||
if (( keyWait >= 5 )); then
|
if (( keyWait >= 5 )); then
|
||||||
if sendKey ret 0 100 6 0.25; then
|
if sendKey ret 0 100 6 0.25; then
|
||||||
@@ -265,7 +265,7 @@ ready() {
|
|||||||
|
|
||||||
[ ! -s "$QEMU_PTY" ] && return 1
|
[ ! -s "$QEMU_PTY" ] && return 1
|
||||||
|
|
||||||
if [[ "${BOOT_MODE,,}" == "windows_legacy" ]]; then
|
if isLegacyBoot; then
|
||||||
legacyBootReady && return 0
|
legacyBootReady && return 0
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
@@ -358,7 +358,7 @@ bootKeyReady() {
|
|||||||
|
|
||||||
[ ! -s "$QEMU_PTY" ] && return 1
|
[ ! -s "$QEMU_PTY" ] && return 1
|
||||||
|
|
||||||
if [[ "${BOOT_MODE,,}" == "windows_legacy" ]]; then
|
if isLegacyBoot; then
|
||||||
grep -Fq "Booting from DVD/CD" "$QEMU_PTY"
|
grep -Fq "Booting from DVD/CD" "$QEMU_PTY"
|
||||||
return $?
|
return $?
|
||||||
fi
|
fi
|
||||||
@@ -372,7 +372,7 @@ bootKeyReady() {
|
|||||||
|
|
||||||
getBootMarker() {
|
getBootMarker() {
|
||||||
|
|
||||||
if [[ "${BOOT_MODE,,}" == "windows_legacy" ]]; then
|
if isLegacyBoot; then
|
||||||
grep -nE "$LEGACY_BOOT_PATTERN" "$QEMU_PTY" | tail -1
|
grep -nE "$LEGACY_BOOT_PATTERN" "$QEMU_PTY" | tail -1
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|||||||
+1
-1
@@ -388,7 +388,7 @@ isUserMode && return 0
|
|||||||
|
|
||||||
# Older Windows versions discover shares through NetBIOS, while modern Windows
|
# Older Windows versions discover shares through NetBIOS, while modern Windows
|
||||||
# uses Web Services Discovery.
|
# uses Web Services Discovery.
|
||||||
if [[ "${BOOT_MODE:-}" == "windows_legacy" ]]; then
|
if isLegacyBoot; then
|
||||||
startNetbios || :
|
startNetbios || :
|
||||||
else
|
else
|
||||||
startWsddn || :
|
startWsddn || :
|
||||||
|
|||||||
Reference in New Issue
Block a user