Update install.sh
This commit is contained in:
parent
2bc1ad16fd
commit
f29f8b8dcc
1 changed files with 79 additions and 36 deletions
115
src/install.sh
115
src/install.sh
|
|
@ -51,6 +51,23 @@ finishInstall() {
|
|||
|
||||
cp /run/version "$STORAGE/windows.ver"
|
||||
|
||||
if [[ "${PLATFORM,,}" == "x64" ]]; then
|
||||
if [[ "${BOOT_MODE,,}" == "windows_legacy" ]]; then
|
||||
if [[ "${MACHINE,,}" != "q35" ]]; then
|
||||
echo "$MACHINE" > "$STORAGE/windows.old"
|
||||
fi
|
||||
echo "$BOOT_MODE" > "$STORAGE/windows.mode"
|
||||
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
|
||||
}
|
||||
|
|
@ -104,9 +121,13 @@ startInstall() {
|
|||
fi
|
||||
fi
|
||||
|
||||
if [[ "${PLATFORM,,}" == "x64" ]]; then
|
||||
! migrateFiles "$BASE" "$VERSION" && error "Migration failed!" && exit 57
|
||||
fi
|
||||
|
||||
if skipInstall; then
|
||||
[ ! -f "$STORAGE/$BASE" ] && BASE=""
|
||||
VGA="virtio-gpu"
|
||||
[[ "${PLATFORM,,}" == "arm64" ]] && VGA="virtio-gpu"
|
||||
return 1
|
||||
fi
|
||||
|
||||
|
|
@ -135,10 +156,9 @@ startInstall() {
|
|||
|
||||
if [ ! -f "$STORAGE/$CUSTOM" ]; then
|
||||
CUSTOM=""
|
||||
if [[ "$EXTERNAL" == [Yy1]* ]]; then
|
||||
ISO="$TMP/$BASE"
|
||||
else
|
||||
ISO="$TMP/$VERSION.esd"
|
||||
ISO="$TMP/$BASE"
|
||||
if [[ "${PLATFORM,,}" == "arm64" ]]; then
|
||||
[[ "$EXTERNAL" != [Yy1]* ]] && ISO="$TMP/$VERSION.esd"
|
||||
fi
|
||||
else
|
||||
ISO="$STORAGE/$CUSTOM"
|
||||
|
|
@ -177,7 +197,7 @@ getESD() {
|
|||
winCatalog="https://go.microsoft.com/fwlink/?LinkId=841361"
|
||||
;;
|
||||
*)
|
||||
error "Invalid version specified: $version" && return 1
|
||||
error "Invalid VERSION specified, value \"$version\" is not recognized!" && return 1
|
||||
;;
|
||||
esac
|
||||
|
||||
|
|
@ -188,6 +208,9 @@ getESD() {
|
|||
mkdir -p "$dir"
|
||||
|
||||
local wFile="catalog.cab"
|
||||
local xFile="products.xml"
|
||||
local eFile="esd_edition.xml"
|
||||
local fFile="products_filter.xml"
|
||||
|
||||
{ wget "$winCatalog" -O "$dir/$wFile" -q; rc=$?; } || :
|
||||
(( rc != 0 )) && error "Failed to download $winCatalog , reason: $rc" && return 1
|
||||
|
|
@ -196,33 +219,33 @@ getESD() {
|
|||
|
||||
if ! cabextract "$wFile" > /dev/null; then
|
||||
cd /run
|
||||
error "Failed to extract CAB file!" && return 1
|
||||
error "Failed to extract $wFile!" && return 1
|
||||
fi
|
||||
|
||||
cd /run
|
||||
|
||||
if [ ! -s "$dir/products.xml" ]; then
|
||||
error "Failed to find products.xml!" && return 1
|
||||
if [ ! -s "$dir/$xFile" ]; then
|
||||
error "Failed to find $xFile in $wFile!" && return 1
|
||||
fi
|
||||
|
||||
local esdLang="en-us"
|
||||
local editionName="Professional"
|
||||
local edQuery='//File[Architecture="'${PLATFORM}'"][Edition="'${editionName}'"]'
|
||||
|
||||
echo -e '<Catalog>' > "${dir}/products_filter.xml"
|
||||
xmllint --nonet --xpath "${edQuery}" "${dir}/products.xml" >> "${dir}/products_filter.xml" 2>/dev/null
|
||||
echo -e '</Catalog>'>> "${dir}/products_filter.xml"
|
||||
xmllint --nonet --xpath '//File[LanguageCode="'${esdLang}'"]' "${dir}/products_filter.xml" >"${dir}/esd_edition.xml"
|
||||
echo -e '<Catalog>' > "$dir/$fFile"
|
||||
xmllint --nonet --xpath "${edQuery}" "$dir/$xFile" >> "$dir/$fFile" 2>/dev/null
|
||||
echo -e '</Catalog>'>> "$dir/$fFile"
|
||||
xmllint --nonet --xpath '//File[LanguageCode="'${esdLang}'"]' "$dir/$fFile" >"$dir/$eFile"
|
||||
|
||||
size=$(stat -c%s "${dir}/esd_edition.xml")
|
||||
size=$(stat -c%s "$dir/$eFile")
|
||||
if ((size<20)); then
|
||||
error "Failed to find Windows product!" && return 1
|
||||
error "Failed to find Windows product in $eFile!" && return 1
|
||||
fi
|
||||
|
||||
ESD_URL=$(xmllint --nonet --xpath '//FilePath' "${dir}/esd_edition.xml" | sed -E -e 's/<[\/]?FilePath>//g')
|
||||
ESD_URL=$(xmllint --nonet --xpath '//FilePath' "$dir/$eFile" | sed -E -e 's/<[\/]?FilePath>//g')
|
||||
|
||||
if [ -z "$ESD_URL" ]; then
|
||||
error "Failed to find ESD URL!" && return 1
|
||||
error "Failed to find ESD URL in $eFile!" && return 1
|
||||
fi
|
||||
|
||||
rm -rf "$dir"
|
||||
|
|
@ -281,10 +304,14 @@ downloadImage() {
|
|||
fi
|
||||
|
||||
if ! validVersion "$version"; then
|
||||
error "Invalid VERSION value: $version" && return 1
|
||||
error "Invalid VERSION specified, value \"$version\" is not recognized!" && return 1
|
||||
fi
|
||||
|
||||
desc=$(printVersion "$version" "Windows for ${PLATFORM}")
|
||||
if [[ "${PLATFORM,,}" == "x64" ]]; then
|
||||
desc=$(printVersion "$version" "Windows")
|
||||
else
|
||||
desc=$(printVersion "$version" "Windows for ${PLATFORM}")
|
||||
fi
|
||||
|
||||
if isESD "$version"; then
|
||||
|
||||
|
|
@ -338,9 +365,10 @@ extractESD() {
|
|||
|
||||
local iso="$1"
|
||||
local dir="$2"
|
||||
local version="$3"
|
||||
local desc="$4"
|
||||
local size size_gb space space_gb desc
|
||||
|
||||
desc=$(printVersion "$VERSION" "Windows for ${PLATFORM}")
|
||||
local msg="Extracting $desc bootdisk..."
|
||||
info "$msg" && html "$msg"
|
||||
|
||||
|
|
@ -365,7 +393,7 @@ extractESD() {
|
|||
|
||||
wimlib-imagex apply "$iso" 1 "${dir}" --quiet 2>/dev/null || {
|
||||
retVal=$?
|
||||
error "Extracting bootdisk failed" && return $retVal
|
||||
error "Extracting $desc bootdisk failed" && return $retVal
|
||||
}
|
||||
|
||||
local bootWimFile="${dir}/sources/boot.wim"
|
||||
|
|
@ -392,7 +420,7 @@ extractESD() {
|
|||
|
||||
local edition imageIndex imageEdition
|
||||
|
||||
case "${VERSION,,}" in
|
||||
case "${version,,}" in
|
||||
"win11${PLATFORM,,}")
|
||||
edition="11 pro"
|
||||
;;
|
||||
|
|
@ -400,7 +428,7 @@ extractESD() {
|
|||
edition="10 pro"
|
||||
;;
|
||||
*)
|
||||
error "Invalid version specified: $VERSION" && return 1
|
||||
error "Invalid VERSION specified, value \"$version\" is not recognized!" && return 1
|
||||
;;
|
||||
esac
|
||||
|
||||
|
|
@ -409,7 +437,7 @@ extractESD() {
|
|||
[[ "${imageEdition,,}" != *"$edition"* ]] && continue
|
||||
wimlib-imagex export "${iso}" ${imageIndex} "${installWimFile}" --compress=LZMS --chunk-size 128K --quiet || {
|
||||
retVal=$?
|
||||
error "Addition of ${imageIndex} to the image failed" && return $retVal
|
||||
error "Addition of ${imageIndex} to the $desc image failed" && return $retVal
|
||||
}
|
||||
return 0
|
||||
done
|
||||
|
|
@ -421,16 +449,17 @@ extractImage() {
|
|||
|
||||
local iso="$1"
|
||||
local dir="$2"
|
||||
local version="$3"
|
||||
local desc="downloaded ISO"
|
||||
local size size_gb space space_gb
|
||||
|
||||
if [[ "${iso,,}" == *".esd" ]]; then
|
||||
extractESD "$iso" "$dir" && return 0
|
||||
return 1
|
||||
if [[ "$EXTERNAL" != [Yy1]* ]] && [ -z "$CUSTOM" ]; then
|
||||
desc=$(printVersion "$version" "downloaded ISO")
|
||||
fi
|
||||
|
||||
if [[ "$EXTERNAL" != [Yy1]* ]] && [ -z "$CUSTOM" ]; then
|
||||
desc=$(printVersion "$VERSION" "downloaded ISO")
|
||||
if [[ "${iso,,}" == *".esd" ]]; then
|
||||
extractESD "$iso" "$dir" "$version" "$desc" && return 0
|
||||
return 1
|
||||
fi
|
||||
|
||||
local msg="Extracting $desc image..."
|
||||
|
|
@ -487,7 +516,7 @@ detectImage() {
|
|||
local dsc
|
||||
dsc=$(printVersion "$DETECTED" "$DETECTED")
|
||||
|
||||
warn "got $dsc, but no matching XML file exists, $FB."
|
||||
warn "got $dsc, but no matching $DETECTED.xml file exists, $FB."
|
||||
fi
|
||||
|
||||
return 0
|
||||
|
|
@ -495,10 +524,18 @@ detectImage() {
|
|||
|
||||
info "Detecting Windows version from ISO image..."
|
||||
|
||||
if [[ "${PLATFORM,,}" == "x64" ]]; then
|
||||
if [ -f "$dir/WIN51" ] || [ -f "$dir/SETUPXP.HTM" ]; then
|
||||
DETECTED="winxpx86"
|
||||
info "Detected: Windows XP" && return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
local src loc tag result name name2 desc
|
||||
src=$(find "$dir" -maxdepth 1 -type d -iname sources | head -n 1)
|
||||
|
||||
if [ ! -d "$src" ]; then
|
||||
[[ "${PLATFORM,,}" == "x64" ]] && BOOT_MODE="windows_legacy"
|
||||
warn "failed to locate 'sources' folder in ISO image, $FB" && return 1
|
||||
fi
|
||||
|
||||
|
|
@ -506,6 +543,7 @@ detectImage() {
|
|||
[ ! -f "$loc" ] && loc=$(find "$src" -maxdepth 1 -type f -iname install.esd | head -n 1)
|
||||
|
||||
if [ ! -f "$loc" ]; then
|
||||
[[ "${PLATFORM,,}" == "x64" ]] && BOOT_MODE="windows_legacy"
|
||||
warn "failed to locate 'install.wim' or 'install.esd' in ISO image, $FB" && return 1
|
||||
fi
|
||||
|
||||
|
|
@ -533,7 +571,7 @@ detectImage() {
|
|||
[[ "$MANUAL" != [Yy1]* ]] && XML="$DETECTED.xml"
|
||||
info "Detected: $desc"
|
||||
else
|
||||
warn "detected $desc, but no matching XML file exists, $FB."
|
||||
warn "detected $desc, but no matching $DETECTED.xml file exists, $FB."
|
||||
fi
|
||||
|
||||
return 0
|
||||
|
|
@ -572,6 +610,7 @@ updateImage() {
|
|||
src=$(find "$dir" -maxdepth 1 -type d -iname sources | head -n 1)
|
||||
|
||||
if [ ! -d "$src" ]; then
|
||||
[[ "${PLATFORM,,}" == "x64" ]] && BOOT_MODE="windows_legacy"
|
||||
warn "failed to locate 'sources' folder in ISO image, $FB" && return 1
|
||||
fi
|
||||
|
||||
|
|
@ -579,10 +618,11 @@ updateImage() {
|
|||
[ ! -f "$loc" ] && loc=$(find "$src" -maxdepth 1 -type f -iname boot.esd | head -n 1)
|
||||
|
||||
if [ ! -f "$loc" ]; then
|
||||
[[ "${PLATFORM,,}" == "x64" ]] && BOOT_MODE="windows_legacy"
|
||||
warn "failed to locate 'boot.wim' or 'boot.esd' in ISO image, $FB" && return 1
|
||||
fi
|
||||
|
||||
info "Adding XML file for automatic installation..."
|
||||
info "Adding "$(basename $asset)" for automatic installation..."
|
||||
|
||||
index="1"
|
||||
result=$(wimlib-imagex info -xml "$loc" | tr -d '\000')
|
||||
|
|
@ -592,7 +632,7 @@ updateImage() {
|
|||
fi
|
||||
|
||||
if ! wimlib-imagex update "$loc" "$index" --command "add $asset /autounattend.xml" > /dev/null; then
|
||||
warn "failed to add XML to ISO image, $FB" && return 1
|
||||
warn "failed to add "$(basename $asset)" to ISO image, $FB" && return 1
|
||||
fi
|
||||
|
||||
return 0
|
||||
|
|
@ -675,13 +715,16 @@ buildImage() {
|
|||
|
||||
bootWindows() {
|
||||
|
||||
rm -rf "$TMP"
|
||||
|
||||
if [ -s "$STORAGE/windows.mode" ] && [ -f "$STORAGE/windows.mode" ]; then
|
||||
BOOT_MODE=$(<"$STORAGE/windows.mode")
|
||||
rm -rf "$TMP"
|
||||
if [ -s "$STORAGE/windows.old" ] && [ -f "$STORAGE/windows.old" ]; then
|
||||
[[ "${PLATFORM,,}" == "x64" ]] && MACHINE=$(<"$STORAGE/windows.old")
|
||||
fi
|
||||
return 0
|
||||
fi
|
||||
|
||||
rm -rf "$TMP"
|
||||
return 0
|
||||
}
|
||||
|
||||
|
|
@ -702,7 +745,7 @@ if [ ! -s "$ISO" ] || [ ! -f "$ISO" ]; then
|
|||
fi
|
||||
fi
|
||||
|
||||
if ! extractImage "$ISO" "$DIR"; then
|
||||
if ! extractImage "$ISO" "$DIR" "$VERSION"; then
|
||||
rm -f "$ISO"
|
||||
exit 62
|
||||
fi
|
||||
|
|
|
|||
Loading…
Reference in a new issue