Compare commits

...

11 Commits

Author SHA1 Message Date
Kroese c2e00a054f
Update install.sh 2024-05-10 02:34:49 +02:00
Kroese 0ae9c64bbb
Update install.sh 2024-05-10 02:28:28 +02:00
Kroese f3198d396f
Update install.sh 2024-05-10 02:24:21 +02:00
Kroese 85edbd79fe
Update install.sh 2024-05-10 02:11:49 +02:00
Kroese fba584ff16
Update install.sh 2024-05-10 02:00:31 +02:00
Kroese 96a26831a8
Update install.sh 2024-05-10 01:54:12 +02:00
Kroese 35262485af
feat: Extract XML 2024-05-10 01:47:07 +02:00
Kroese 2de40c4cad
feat: Switch between install modes 2024-05-10 01:32:41 +02:00
Kroese 6c2fedb5d2
Update define.sh 2024-05-09 22:54:38 +02:00
Kroese a2320d8649
feat: Detect XML during manual installs 2024-05-09 20:39:23 +02:00
Kroese 8cf4278f87
feat: Detect modified ISO 2024-05-09 19:55:13 +02:00
2 changed files with 139 additions and 69 deletions

View File

@ -984,7 +984,7 @@ migrateFiles() {
[[ "${version,,}" == "win7${PLATFORM,,}" ]] && file="en_windows_7_enterprise_with_sp1_${PLATFORM,,}_dvd_u_677651.iso"
[ ! -f "$STORAGE/$file" ] && return 0
! mv "$STORAGE/$file" "$base" && return 1
! mv -f "$STORAGE/$file" "$base" && return 1
return 0
}

View File

@ -31,7 +31,7 @@ skipInstall() {
startInstall() {
html "Starting Windows..."
html "Starting $APP..."
if [ -n "$CUSTOM" ]; then
@ -59,13 +59,22 @@ startInstall() {
if [ -f "$ISO" ] && [ -s "$ISO" ]; then
# Check if the ISO was already processed by our script
local magic
local byte="16"
[[ "$MANUAL" == [Yy1]* ]] && byte="17"
local auto="16"
local manual="17"
# Check if the ISO was already processed by our script
magic=$(dd if="$ISO" seek=0 bs=1 count=1 status=none | tr -d '\000')
magic="$(printf '%s' "$magic" | od -A n -t x1 -v | tr -d ' \n')"
if [[ "$magic" == "$auto" ]] || [[ "$magic" == "$manual" ]]; then
if [ -n "$CUSTOM" ] && [ -z "$ORIGINAL" ]; then
warn "this ISO file has already been modified by a previous installation!"
fi
fi
local byte="$auto"
[[ "$MANUAL" == [Yy1]* ]] && byte="$manual"
[[ "$magic" == "$byte" ]] && return 1
fi
@ -174,19 +183,18 @@ detectCustom() {
base="${VERSION/\/storage\//}"
[[ "$base" == "."* ]] && base="${file:1}"
[[ "$base" == *"/"* ]] && base=""
[ -n "$base" ] && file=$(find "$STORAGE" -maxdepth 1 -type f -iname "$base" -printf "%f\n" | head -n 1)
[ -n "$base" ] && file=$(find "$STORAGE" -maxdepth 1 -type f -iname "$base" | head -n 1)
fi
[ -z "$file" ] && file=$(find "$STORAGE" -maxdepth 1 -type f -iname custom.iso -printf "%f\n" | head -n 1)
[ -z "$file" ] && file=$(find "$STORAGE" -maxdepth 1 -type f -iname custom.img -printf "%f\n" | head -n 1)
[ -n "$file" ] && file="$STORAGE/$file"
[ -z "$file" ] && file=$(find "$STORAGE" -maxdepth 1 -type f -iname custom.iso | head -n 1)
[ -z "$file" ] && file=$(find "$STORAGE" -maxdepth 1 -type f -iname custom.img | head -n 1)
base="/custom.iso"
[ -f "$base" ] && [ -s "$base" ] && file="$base"
[ -z "$file" ] && return 0
[ ! -f "$file" ] && return 0
[ ! -s "$file" ] && return 0
if [ ! -f "$file" ] || [ ! -s "$file" ]; then
return 0
fi
size="$(stat -c%s "$file")"
[ -z "$size" ] || [[ "$size" == "0" ]] && return 0
@ -197,8 +205,8 @@ detectCustom() {
CUSTOM="$base"
ORIGINAL="$file"
else
CUSTOM="$file"
rm -f "$base"
CUSTOM="$file"
fi
return 0
@ -499,20 +507,20 @@ extractESD() {
fi
local esdImageCount
esdImageCount=$(wimlib-imagex info "${iso}" | awk '/Image Count:/ {print $3}')
esdImageCount=$(wimlib-imagex info "$iso" | awk '/Image Count:/ {print $3}')
wimlib-imagex apply "$iso" 1 "${dir}" --quiet 2>/dev/null || {
wimlib-imagex apply "$iso" 1 "$dir" --quiet 2>/dev/null || {
retVal=$?
error "Extracting $desc bootdisk failed" && return $retVal
}
local bootWimFile="${dir}/sources/boot.wim"
local installWimFile="${dir}/sources/install.wim"
local bootWimFile="$dir/sources/boot.wim"
local installWimFile="$dir/sources/install.wim"
local msg="Extracting $desc environment..."
info "$msg" && html "$msg"
wimlib-imagex export "${iso}" 2 "${bootWimFile}" --compress=LZX --chunk-size 32K --quiet || {
wimlib-imagex export "$iso" 2 "$bootWimFile" --compress=LZX --chunk-size 32K --quiet || {
retVal=$?
error "Adding WinPE failed" && return ${retVal}
}
@ -520,7 +528,7 @@ extractESD() {
local msg="Extracting $desc setup..."
info "$msg" && html "$msg"
wimlib-imagex export "${iso}" 3 "$bootWimFile" --compress=LZX --chunk-size 32K --boot --quiet || {
wimlib-imagex export "$iso" 3 "$bootWimFile" --compress=LZX --chunk-size 32K --boot --quiet || {
retVal=$?
error "Adding Windows Setup failed" && return ${retVal}
}
@ -542,11 +550,11 @@ extractESD() {
fi
for (( imageIndex=4; imageIndex<=esdImageCount; imageIndex++ )); do
imageEdition=$(wimlib-imagex info "${iso}" ${imageIndex} | grep '^Description:' | sed 's/Description:[ \t]*//')
imageEdition=$(wimlib-imagex info "$iso" ${imageIndex} | grep '^Description:' | sed 's/Description:[ \t]*//')
[[ "${imageEdition,,}" != "${edition,,}" ]] && continue
wimlib-imagex export "${iso}" ${imageIndex} "${installWimFile}" --compress=LZMS --chunk-size 128K --quiet || {
wimlib-imagex export "$iso" ${imageIndex} "$installWimFile" --compress=LZMS --chunk-size 128K --quiet || {
retVal=$?
error "Addition of ${imageIndex} to the $desc image failed" && return $retVal
error "Addition of $imageIndex to the $desc image failed" && return $retVal
}
return 0
done
@ -606,22 +614,15 @@ extractImage() {
setXML() {
[[ "$MANUAL" == [Yy1]* ]] && return 0
local file="/custom.xml"
[ -f "$file" ] && [ -s "$file" ] && XML="$file" && return 0
[ ! -f "$file" ] || [ ! -s "$file" ] && file="$STORAGE/custom.xml"
[ ! -f "$file" ] || [ ! -s "$file" ] && file="/run/assets/custom.xml"
[ ! -f "$file" ] || [ ! -s "$file" ] && file="$1"
[ ! -f "$file" ] || [ ! -s "$file" ] && file="/run/assets/$DETECTED.xml"
[ ! -f "$file" ] || [ ! -s "$file" ] && return 1
file="$STORAGE/custom.xml"
[ -f "$file" ] && [ -s "$file" ] && XML="$file" && return 0
file="/run/assets/custom.xml"
[ -f "$file" ] && [ -s "$file" ] && XML="$file" && return 0
file="$1"
[ -z "$file" ] && file="/run/assets/$DETECTED.xml"
[ -f "$file" ] && [ -s "$file" ] && XML="$file" && return 0
return 1
XML="$file"
return 0
}
getPlatform() {
@ -643,12 +644,28 @@ getPlatform() {
return 0
}
hasVersion() {
local id="$1"
local tag="$2"
local xml="$3"
local edition
[ ! -f "/run/assets/$id.xml" ] && return 1
edition=$(printEdition "$id" "")
[ -z "$edition" ] && return 1
[[ "${xml,,}" != *"<${tag,,}>${edition,,}</${tag,,}>"* ]] && return 1
return 0
}
selectVersion() {
local tag="$1"
local xml="$2"
local platform="$3"
local id find name prefer
local id name prefer
name=$(sed -n "/$tag/{s/.*<$tag>\(.*\)<\/$tag>.*/\1/;p}" <<< "$xml")
[[ "$name" == *"Operating System"* ]] && name=""
@ -658,22 +675,13 @@ selectVersion() {
[ -z "$id" ] && warn "Unknown ${tag,,}: '$name'" && return 0
prefer="$id-enterprise"
[ -f "/run/assets/$prefer.xml" ] && find=$(printEdition "$prefer" "") || find=""
if [ -n "$find" ] && [[ "${xml,,}" == *"<${tag,,}>${find,,}</${tag,,}>"* ]]; then
echo "$prefer" && return 0
fi
hasVersion "$prefer" "$tag" "$xml" && echo "$prefer" && return 0
prefer="$id-ultimate"
[ -f "/run/assets/$prefer.xml" ] && find=$(printEdition "$prefer" "") || find=""
if [ -n "$find" ] && [[ "${xml,,}" == *"<${tag,,}>${find,,}</${tag,,}>"* ]]; then
echo "$prefer" && return 0
fi
hasVersion "$prefer" "$tag" "$xml" && echo "$prefer" && return 0
prefer="$id"
[ -f "/run/assets/$prefer.xml" ] && find=$(printEdition "$prefer" "") || find=""
if [ -n "$find" ] && [[ "${xml,,}" == *"<${tag,,}>${find,,}</${tag,,}>"* ]]; then
echo "$prefer" && return 0
fi
hasVersion "$prefer" "$tag" "$xml" && echo "$prefer" && return 0
prefer=$(getVersion "$name" "$platform")
@ -731,10 +739,12 @@ detectImage() {
[[ "${DETECTED,,}" == "winxp"* ]] && return 0
setXML "" && return 0
if ! setXML "" && [[ "$MANUAL" != [Yy1]* ]]; then
MANUAL="Y"
desc=$(printEdition "$DETECTED" "this version")
warn "the answer file for $desc was not found ($DETECTED.xml), $FB."
fi
desc=$(printEdition "$DETECTED" "this version")
warn "the answer file for $desc was not found ($DETECTED.xml), $FB."
return 0
fi
@ -770,8 +780,13 @@ detectImage() {
if [ -z "$DETECTED" ]; then
msg="Failed to determine Windows version from image"
setXML "" && info "${msg}!" && return 0
warn "${msg}, $FB" && return 0
if setXML "" || [[ "$MANUAL" == [Yy1]* ]]; then
info "${msg}!"
else
MANUAL="Y"
warn "${msg}, $FB."
fi
return 0
fi
desc=$(printEdition "$DETECTED" "$DETECTED")
@ -782,9 +797,13 @@ detectImage() {
msg="the answer file for $desc was not found ($DETECTED.xml)"
local fallback="/run/assets/${DETECTED%%-*}.xml"
setXML "$fallback" && warn "${msg}." && return 0
if setXML "$fallback" || [[ "$MANUAL" == [Yy1]* ]]; then
[[ "$MANUAL" != [Yy1]* ]] && warn "${msg}."
else
MANUAL="Y"
warn "${msg}, $FB."
fi
warn "${msg}, $FB."
return 0
}
@ -822,16 +841,31 @@ prepareImage() {
return 1
}
isOurs() {
local asset="$1"
[ ! -f "$asset" ] && return 1
grep -q Dockur "$asset" && return 0
grep -q NetKVM "$asset" && return 0
return 1
}
updateImage() {
local dir="$1"
local asset="$2"
local path src loc xml index result
local file="autounattend.xml"
local desc path src loc xml index result
[ ! -s "$asset" ] || [ ! -f "$asset" ] && return 0
path=$(find "$dir" -maxdepth 1 -type f -iname autounattend.xml | head -n 1)
[ -n "$path" ] && cp "$asset" "$path"
if [ ! -s "$asset" ] || [ ! -f "$asset" ]; then
asset=""
if [[ "$MANUAL" != [Yy1]* ]]; then
MANUAL="Y"
warn "no answer file provided, $FB."
fi
fi
src=$(find "$dir" -maxdepth 1 -type d -iname sources | head -n 1)
@ -848,9 +882,6 @@ updateImage() {
warn "failed to locate 'boot.wim' or 'boot.esd' in ISO image, $FB" && return 1
fi
xml=$(basename "$asset")
info "Adding $xml for automatic installation..."
index="1"
result=$(wimlib-imagex info -xml "$loc" | tr -d '\000')
@ -858,8 +889,47 @@ updateImage() {
index="2"
fi
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
if [[ "$MANUAL" != [Yy1]* ]]; then
xml=$(basename "$asset")
info "Adding $xml for automatic installation..."
if wimlib-imagex extract "$loc" "$index" "/$file" "--dest-dir=$TMP" >/dev/null 2>&1; then
if [ -f "$TMP/$file" ] && ! isOurs "$TMP/$file"; then
if ! wimlib-imagex update "$loc" "$index" --command "rename /$file /$file.org" > /dev/null; then
warn "failed to rename answer file ($file) in ISO image."
fi
fi
rm -f "$TMP/$file"
fi
if ! wimlib-imagex update "$loc" "$index" --command "add $asset /$file" > /dev/null; then
MANUAL="Y"
warn "failed to add answer file ($xml) to ISO image, $FB"
fi
fi
if [[ "$MANUAL" == [Yy1]* ]]; then
if ! wimlib-imagex update "$loc" "$index" --command "delete --force /$file" > /dev/null; then
warn "failed to remove answer file ($file) from ISO image!"
fi
wimlib-imagex update "$loc" "$index" --command "rename /$file.org /$file" >/dev/null 2>&1 || true
fi
local find="$file"
[[ "$MANUAL" == [Yy1]* ]] && find="$find.org"
path=$(find "$dir" -maxdepth 1 -type f -iname "$find" | head -n 1)
if [ -f "$path" ]; then
if [[ "$MANUAL" != [Yy1]* ]]; then
mv -f "$path" "$path.org"
else
mv -f "$path" "${path/.org/}"
fi
fi
return 0
@ -964,7 +1034,7 @@ buildImage() {
[ -s "$log" ] && error="$(<"$log")"
[[ "$error" != "$hide" ]] && echo "$error"
mv "$out" "$BOOT"
! mv -f "$out" "$BOOT" && return 1
return 0
}
@ -1015,10 +1085,10 @@ bootWindows() {
BOOT_MODE="windows_secure"
echo "$BOOT_MODE" > "$STORAGE/windows.mode"
if [ -f "$STORAGE/windows.rom" ] && [ ! -f "$STORAGE/$BOOT_MODE.rom" ]; then
mv "$STORAGE/windows.rom" "$STORAGE/$BOOT_MODE.rom"
mv -f "$STORAGE/windows.rom" "$STORAGE/$BOOT_MODE.rom"
fi
if [ -f "$STORAGE/windows.vars" ] && [ ! -f "$STORAGE/$BOOT_MODE.vars" ]; then
mv "$STORAGE/windows.vars" "$STORAGE/$BOOT_MODE.vars"
mv -f "$STORAGE/windows.vars" "$STORAGE/$BOOT_MODE.vars"
fi
fi
fi