Update install.sh

This commit is contained in:
Kroese 2024-05-02 02:34:05 +02:00 committed by GitHub
parent 0e8a1179aa
commit b1ef535b87
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -29,65 +29,6 @@ skipInstall() {
return 1 return 1
} }
finishInstall() {
local iso="$1"
local aborted="$2"
if [ ! -s "$iso" ] || [ ! -f "$iso" ]; then
error "Failed to find ISO file: $iso" && return 1
fi
if [ -w "$iso" ] && [[ "$aborted" != [Yy1]* ]]; then
# Mark ISO as prepared via magic byte
if ! printf '\x16' | dd of="$iso" bs=1 seek=0 count=1 conv=notrunc status=none; then
error "Failed to set magic byte in ISO file: $iso" && return 1
fi
fi
rm -f "$STORAGE/windows.ver"
rm -f "$STORAGE/windows.old"
rm -f "$STORAGE/windows.boot"
rm -f "$STORAGE/windows.mode"
cp /run/version "$STORAGE/windows.ver"
if [[ "${PLATFORM,,}" == "x64" ]]; then
if [[ "${BOOT_MODE,,}" == "windows_legacy" ]]; then
echo "$BOOT_MODE" > "$STORAGE/windows.mode"
if [[ "${MACHINE,,}" != "q35" ]]; then
echo "$MACHINE" > "$STORAGE/windows.old"
fi
else
# Enable secure boot + TPM on manual installs as Win11 requires
if [[ "$MANUAL" == [Yy1]* ]] || [[ "$aborted" == [Yy1]* ]]; then
if [[ "${DETECTED,,}" == "win11"* ]]; then
BOOT_MODE="windows_secure"
echo "$BOOT_MODE" > "$STORAGE/windows.mode"
fi
fi
fi
fi
rm -rf "$TMP"
return 0
}
abortInstall() {
local iso="$1"
if [[ "$iso" != "$STORAGE/$BASE" ]]; then
if ! mv -f "$iso" "$STORAGE/$BASE"; then
error "Failed to move ISO file: $iso" && return 1
fi
fi
finishInstall "$STORAGE/$BASE" "Y" && return 0
return 1
}
startInstall() { startInstall() {
html "Starting Windows..." html "Starting Windows..."
@ -161,6 +102,65 @@ startInstall() {
return 0 return 0
} }
finishInstall() {
local iso="$1"
local aborted="$2"
if [ ! -s "$iso" ] || [ ! -f "$iso" ]; then
error "Failed to find ISO file: $iso" && return 1
fi
if [ -w "$iso" ] && [[ "$aborted" != [Yy1]* ]]; then
# Mark ISO as prepared via magic byte
if ! printf '\x16' | dd of="$iso" bs=1 seek=0 count=1 conv=notrunc status=none; then
error "Failed to set magic byte in ISO file: $iso" && return 1
fi
fi
rm -f "$STORAGE/windows.ver"
rm -f "$STORAGE/windows.old"
rm -f "$STORAGE/windows.boot"
rm -f "$STORAGE/windows.mode"
cp /run/version "$STORAGE/windows.ver"
if [[ "${PLATFORM,,}" == "x64" ]]; then
if [[ "${BOOT_MODE,,}" == "windows_legacy" ]]; then
echo "$BOOT_MODE" > "$STORAGE/windows.mode"
if [[ "${MACHINE,,}" != "q35" ]]; then
echo "$MACHINE" > "$STORAGE/windows.old"
fi
else
# Enable secure boot + TPM on manual installs as Win11 requires
if [[ "$MANUAL" == [Yy1]* ]] || [[ "$aborted" == [Yy1]* ]]; then
if [[ "${DETECTED,,}" == "win11"* ]]; then
BOOT_MODE="windows_secure"
echo "$BOOT_MODE" > "$STORAGE/windows.mode"
fi
fi
fi
fi
rm -rf "$TMP"
return 0
}
abortInstall() {
local iso="$1"
if [[ "$iso" != "$STORAGE/$BASE" ]]; then
if ! mv -f "$iso" "$STORAGE/$BASE"; then
error "Failed to move ISO file: $iso" && return 1
fi
fi
finishInstall "$STORAGE/$BASE" "Y" && return 0
return 1
}
detectCustom() { detectCustom() {
CUSTOM=$(find "$STORAGE" -maxdepth 1 -type f -iname windows.iso -printf "%f\n" | head -n 1) CUSTOM=$(find "$STORAGE" -maxdepth 1 -type f -iname windows.iso -printf "%f\n" | head -n 1)
@ -273,6 +273,7 @@ doMido() {
} }
verifyFile() { verifyFile() {
local iso="$1" local iso="$1"
local version="$2" local version="$2"
local hash="" local hash=""
@ -355,11 +356,9 @@ downloadImage() {
local url desc local url desc
if [[ "${version,,}" == "http"* ]]; then if [[ "${version,,}" == "http"* ]]; then
desc=$(getName "$BASE") desc=$(getName "$BASE")
downloadFile "$iso" "$version" "$desc" "" && return 0 downloadFile "$iso" "$version" "$desc" "" && return 0
return 1 return 1
fi fi
if ! validVersion "$version"; then if ! validVersion "$version"; then
@ -542,6 +541,7 @@ extractImage() {
} }
detectVersion() { detectVersion() {
local xml="$1" local xml="$1"
local name name2 name3 local name name2 name3
@ -587,15 +587,20 @@ detectImage() {
if [ -n "$DETECTED" ]; then if [ -n "$DETECTED" ]; then
[[ "$MANUAL" == [Yy1]* ]] && return 0
if [ -f "$STORAGE/custom.xml" ]; then
XML="$STORAGE/custom.xml"
return 0
fi
if [ -f "/run/assets/$DETECTED.xml" ]; then if [ -f "/run/assets/$DETECTED.xml" ]; then
[[ "$MANUAL" != [Yy1]* ]] && XML="$DETECTED.xml" XML="/run/assets/$DETECTED.xml"
return 0 return 0
fi fi
if [[ "${DETECTED,,}" != "winxp"* ]]; then if [[ "${DETECTED,,}" != "winxp"* ]]; then
dsc=$(printVersion "$DETECTED" "$DETECTED") dsc=$(printVersion "$DETECTED" "$DETECTED")
warn "detected $dsc, but its answer file does not exist ($DETECTED.xml), $FB." warn "detected $dsc, but its answer file does not exist ($DETECTED.xml), $FB."
fi fi
@ -611,7 +616,7 @@ detectImage() {
else else
DETECTED="winxpx86" DETECTED="winxpx86"
fi fi
dsc=$(printVersion "$DETECTED" "$DETECTED") dsc=$(printVersion "$DETECTED" "Windows XP")
info "Detected: $dsc" info "Detected: $dsc"
return 0 return 0
fi fi
@ -636,6 +641,10 @@ detectImage() {
result=$(wimlib-imagex info -xml "$loc" | tr -d '\000') result=$(wimlib-imagex info -xml "$loc" | tr -d '\000')
if ! detectVersion "$result"; then if ! detectVersion "$result"; then
if [ -f "$STORAGE/custom.xml" ]; then
XML="$STORAGE/custom.xml"
return 0
fi
warn "failed to determine Windows version from image, $FB" warn "failed to determine Windows version from image, $FB"
return 0 return 0
fi fi
@ -643,7 +652,7 @@ detectImage() {
desc=$(printVersion "$DETECTED" "$DETECTED") desc=$(printVersion "$DETECTED" "$DETECTED")
if [ -f "/run/assets/$DETECTED.xml" ]; then if [ -f "/run/assets/$DETECTED.xml" ]; then
[[ "$MANUAL" != [Yy1]* ]] && XML="$DETECTED.xml" [[ "$MANUAL" != [Yy1]* ]] && XML="/run/assets/$DETECTED.xml"
info "Detected: $desc" info "Detected: $desc"
else else
warn "detected $desc, but no answer file exists for its edition ($DETECTED.xml), $FB." warn "detected $desc, but no answer file exists for its edition ($DETECTED.xml), $FB."
@ -656,45 +665,43 @@ prepareImage() {
local iso="$1" local iso="$1"
local dir="$2" local dir="$2"
local missing
case "${DETECTED,,}" in
"winxp"* | "winvista"* | "win7"* | "win2008"*)
[[ "${PLATFORM,,}" == "arm64" ]] && return 1
BOOT_MODE="windows_legacy" ;;
esac
if [[ "${BOOT_MODE,,}" != "windows_legacy" ]]; then if [[ "${BOOT_MODE,,}" != "windows_legacy" ]]; then
if [[ "${DETECTED,,}" != "winxp"* ]] && [[ "${DETECTED,,}" != "win2008"* ]]; then
if [[ "${DETECTED,,}" != "winvista"* ]] && [[ "${DETECTED,,}" != "win7"* ]]; then
if [ -f "$dir/$ETFS" ] && [ -f "$dir/$EFISYS" ]; then [ -f "$dir/$ETFS" ] && [ -f "$dir/$EFISYS" ] && return 0
return 0
fi
if [ ! -f "$dir/$ETFS" ]; then missing=$(basename "$dir/$EFISYS")
warn "failed to locate file 'etfsboot.com' in ISO image, falling back to legacy boot!" [ ! -f "$dir/$ETFS" ] && missing=$(basename "$dir/$ETFS")
else warn "failed to locate file '${missing,,}' in ISO image!"
warn "failed to locate file 'efisys_noprompt.bin' in ISO image, falling back to legacy boot!"
fi
fi fi
fi
fi
[[ "${PLATFORM,,}" == "arm64" ]] && return 1 [[ "${PLATFORM,,}" == "arm64" ]] && return 1
BOOT_MODE="windows_legacy"
if [[ "${DETECTED,,}" == "winxp"* ]]; then if [[ "${DETECTED,,}" == "winxp"* ]]; then
if ! prepareXP "$iso" "$dir"; then prepareXP "$iso" "$dir" && return 0
error "Failed to prepare Windows XP ISO!" && return 1 error "Failed to prepare Windows XP ISO!" && return 1
fi fi
else
if ! prepareLegacy "$iso" "$dir"; then
error "Failed to prepare Windows ISO!" && return 1
fi
fi
return 0 prepareLegacy "$iso" "$dir" && return 0
error "Failed to extract boot image from ISO!"
return 1
} }
updateImage() { updateImage() {
local iso="$1" local iso="$1"
local dir="$2" local dir="$2"
local asset="/run/assets/$3" local asset="$3"
local path src loc xml index result local path src loc xml index result
[ ! -s "$asset" ] || [ ! -f "$asset" ] && return 0 [ ! -s "$asset" ] || [ ! -f "$asset" ] && return 0
@ -728,13 +735,14 @@ updateImage() {
fi fi
if ! wimlib-imagex update "$loc" "$index" --command "add $asset /autounattend.xml" > /dev/null; then if ! wimlib-imagex update "$loc" "$index" --command "add $asset /autounattend.xml" > /dev/null; then
warn "failed to add answer file $xml to ISO image, $FB" && return 1 warn "failed to add answer file ($xml) to ISO image, $FB" && return 1
fi fi
return 0 return 0
} }
copyOEM() { copyOEM() {
local dir="$1" local dir="$1"
local folder="$STORAGE/oem" local folder="$STORAGE/oem"
local src local src