Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Detect Windows version from ISO file #51

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 45 additions & 10 deletions src/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -102,33 +102,68 @@ else

{ wget "$VERSION" -O "$ISO" -q --no-check-certificate --show-progress "$PROGRESS"; rc=$?; } || :

(( rc != 0 )) && error "Failed to download $VERSION, reason: $rc" && exit 60
(( rc != 0 )) && echo && error "Failed to download $VERSION, reason: $rc" && exit 60

fi

[ ! -f "$ISO" ] && error "Failed to download $VERSION" && exit 61
[ ! -f "$ISO" ] && echo && error "Failed to download $VERSION" && exit 61

SIZE=$(stat -c%s "$ISO")

if ((SIZE<10000000)); then
error "Invalid ISO file: Size is smaller than 10 MB" && exit 62
echo && error "Invalid ISO file: Size is smaller than 10 MB" && exit 62
fi

info "Preparing ISO image for installation..."
echo && info "Preparing ISO image for installation..." && echo

DIR="$TMP/unpack"
rm -rf "$DIR"

7z x "$ISO" -o"$DIR"
echo

if [[ "$EXTERNAL" != [Yy1]* ]]; then

XML="$VERSION.xml"

else

info "Detecting Windows version from ISO image..." && echo

XML=""
DETECTED=""
TAG="DISPLAYNAME"
RESULT=$(wimlib-imagex info -xml "$DIR/sources/install.wim" | tr -d '\000')
NAME=$(sed -n "/$TAG/{s/.*<$TAG>\(.*\)<\/$TAG>.*/\1/;p}" <<< "$RESULT")

[[ "$NAME" == "Windows 11"* ]] && DETECTED="win11x64"
[[ "$NAME" == "Windows 10"* ]] && DETECTED="win10x64"
[[ "$NAME" == "Windows 8"* ]] && DETECTED="win81x64"
[[ "$NAME" == "Windows Server 2022"* ]] && DETECTED="win2022-eval"
[[ "$NAME" == "Windows Server 2019"* ]] && DETECTED="win2019-eval"
[[ "$NAME" == "Windows Server 2016"* ]] && DETECTED="win2016-eval"

if [ -n "$DETECTED" ]; then

XML="$DETECTED.xml"
echo "Detected image of type '$DETECTED', will apply unattended.xml file." && echo

else

echo "Warning: failed to detect Windows version from '$NAME', falling back to manual installation!" && echo

fi
fi

if [[ "$MANUAL" != [Yy1]* ]]; then
if [[ "$EXTERNAL" != [Yy1]* ]]; then
if [ -f "/run/assets/$VERSION.xml" ]; then
if [ -f "/run/assets/$XML" ]; then

wimlib-imagex update "$DIR/sources/boot.wim" 2 \
--command "add /run/assets/$VERSION.xml /autounattend.xml"
wimlib-imagex update "$DIR/sources/boot.wim" 2 \
--command "add /run/assets/$XML /autounattend.xml"
echo

fi
else
[ -n "$XML" ] && info "Warning: XML file '$XML' does not exist, falling back to manual installation!" && echo
fi
fi

Expand All @@ -143,7 +178,7 @@ genisoimage -b boot/etfsboot.com -no-emul-boot -c BOOT.CAT -iso-level 4 -J -l -D
-no-emul-boot -o "$ISO" -allow-limited-size "$DIR"

mv "$ISO" "$STORAGE/$BASE"

rm -rf "$TMP"

echo
return 0