install.sh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/usr/bin/env bash
  2. set -Eeuo pipefail
  3. : "${ATTENDED:="N"}"
  4. : "${VERSION:="win11x64"}"
  5. ARGUMENTS="-chardev socket,id=chrtpm,path=/tmp/emulated_tpm/swtpm-sock $ARGUMENTS"
  6. ARGUMENTS="-tpmdev emulator,id=tpm0,chardev=chrtpm -device tpm-tis,tpmdev=tpm0 $ARGUMENTS"
  7. BASE="$VERSION.iso"
  8. [ -f "$STORAGE/$BASE" ] && return 0
  9. TMP="$STORAGE/tmp"
  10. rm -rf "$TMP"
  11. mkdir -p "$TMP"
  12. if [ -f "$STORAGE/custom.iso" ]; then
  13. cp "$STORAGE/custom.iso" "$TMP/$BASE"
  14. fi
  15. if [ ! -f "$TMP/$BASE" ]; then
  16. SCRIPT="$TMP/mido.sh"
  17. cp /run/mido.sh "$SCRIPT"
  18. chmod +x "$SCRIPT"
  19. cd "$TMP"
  20. bash "$SCRIPT" "$VERSION"
  21. cd /run
  22. rm -f "$SCRIPT"
  23. [ ! -f "$TMP/$BASE" ] && error "Failed to download $VERSION.iso from the Microsoft servers!" && exit 66
  24. fi
  25. info "Preparing ISO image for installation..."
  26. DIR="$TMP/unpack"
  27. 7z x "$TMP/$BASE" -o"$DIR"
  28. if [[ "$ATTENDED" != [Yy1]* ]]; then
  29. if [ -f "/run/assets/$VERSION.xml" ]; then
  30. wimlib-imagex update "$DIR/sources/boot.wim" 2 \
  31. --command "add /run/assets/$VERSION.xml /autounattend.xml"
  32. fi
  33. fi
  34. genisoimage -b boot/etfsboot.com -no-emul-boot -c BOOT.CAT -iso-level 4 -J -l -D -N -joliet-long -relaxed-filenames \
  35. -v -V "$VERSION" -udf -boot-info-table -eltorito-alt-boot -eltorito-boot efi/microsoft/boot/efisys_noprompt.bin \
  36. -no-emul-boot -o "$TMP/$BASE.tmp" -allow-limited-size "$DIR"
  37. mv "$TMP/$BASE.tmp" "$STORAGE/$BASE"
  38. rm -rf "$TMP"
  39. return 0