1
0

install.sh 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117
  1. #!/usr/bin/env bash
  2. set -Eeuo pipefail
  3. : "${MANUAL:=""}"
  4. : "${DETECTED:=""}"
  5. : "${VERSION:="win11x64"}"
  6. if [[ "${VERSION}" == \"*\" || "${VERSION}" == \'*\' ]]; then
  7. VERSION="${VERSION:1:-1}"
  8. fi
  9. [[ "${VERSION,,}" == "11" ]] && VERSION="win11x64"
  10. [[ "${VERSION,,}" == "win11" ]] && VERSION="win11x64"
  11. [[ "${VERSION,,}" == "10" ]] && VERSION="win10x64"
  12. [[ "${VERSION,,}" == "win10" ]] && VERSION="win10x64"
  13. [[ "${VERSION,,}" == "8" ]] && VERSION="win81x64"
  14. [[ "${VERSION,,}" == "81" ]] && VERSION="win81x64"
  15. [[ "${VERSION,,}" == "8.1" ]] && VERSION="win81x64"
  16. [[ "${VERSION,,}" == "win8" ]] && VERSION="win81x64"
  17. [[ "${VERSION,,}" == "win81" ]] && VERSION="win81x64"
  18. [[ "${VERSION,,}" == "7" ]] && VERSION="win7x64"
  19. [[ "${VERSION,,}" == "win7" ]] && VERSION="win7x64"
  20. [[ "${VERSION,,}" == "vista" ]] && VERSION="winvistax64"
  21. [[ "${VERSION,,}" == "winvista" ]] && VERSION="winvistax64"
  22. [[ "${VERSION,,}" == "xp" ]] && VERSION="winxpx86"
  23. [[ "${VERSION,,}" == "winxp" ]] && VERSION="winxpx86"
  24. [[ "${VERSION,,}" == "22" ]] && VERSION="win2022-eval"
  25. [[ "${VERSION,,}" == "2022" ]] && VERSION="win2022-eval"
  26. [[ "${VERSION,,}" == "win22" ]] && VERSION="win2022-eval"
  27. [[ "${VERSION,,}" == "win2022" ]] && VERSION="win2022-eval"
  28. [[ "${VERSION,,}" == "19" ]] && VERSION="win2019-eval"
  29. [[ "${VERSION,,}" == "2019" ]] && VERSION="win2019-eval"
  30. [[ "${VERSION,,}" == "win19" ]] && VERSION="win2019-eval"
  31. [[ "${VERSION,,}" == "win2019" ]] && VERSION="win2019-eval"
  32. [[ "${VERSION,,}" == "16" ]] && VERSION="win2016-eval"
  33. [[ "${VERSION,,}" == "2016" ]] && VERSION="win2016-eval"
  34. [[ "${VERSION,,}" == "win16" ]] && VERSION="win2016-eval"
  35. [[ "${VERSION,,}" == "win2016" ]] && VERSION="win2016-eval"
  36. [[ "${VERSION,,}" == "2012" ]] && VERSION="win2012r2-eval"
  37. [[ "${VERSION,,}" == "win2012" ]] && VERSION="win2012r2-eval"
  38. [[ "${VERSION,,}" == "2008" ]] && VERSION="win2008r2"
  39. [[ "${VERSION,,}" == "win2008" ]] && VERSION="win2008r2"
  40. [[ "${VERSION,,}" == "ltsc10" ]] && VERSION="win10x64-enterprise-ltsc-eval"
  41. [[ "${VERSION,,}" == "10ltsc" ]] && VERSION="win10x64-enterprise-ltsc-eval"
  42. [[ "${VERSION,,}" == "win10-ltsc" ]] && VERSION="win10x64-enterprise-ltsc-eval"
  43. [[ "${VERSION,,}" == "win10x64-ltsc" ]] && VERSION="win10x64-enterprise-ltsc-eval"
  44. if [[ "${VERSION,,}" == "win10x64-enterprise-ltsc-eval" ]]; then
  45. DETECTED="win10x64-ltsc"
  46. fi
  47. if [[ "${VERSION,,}" == "win7x64" ]]; then
  48. DETECTED="win7x64"
  49. VERSION="https://dl.bobpony.com/windows/7/en_windows_7_enterprise_with_sp1_x64_dvd_u_677651.iso"
  50. fi
  51. if [[ "${VERSION,,}" == "winvistax64" ]]; then
  52. DETECTED="winvistax64"
  53. VERSION="https://dl.bobpony.com/windows/vista/en_windows_vista_sp2_x64_dvd_342267.iso"
  54. fi
  55. if [[ "${VERSION,,}" == "winxpx86" ]]; then
  56. DETECTED="winxpx86"
  57. VERSION="https://dl.bobpony.com/windows/xp/professional/en_windows_xp_professional_with_service_pack_3_x86_cd_x14-80428.iso"
  58. fi
  59. if [[ "${VERSION,,}" == "core11" ]]; then
  60. DETECTED="win11x64"
  61. VERSION="https://archive.org/download/tiny-11-core-x-64-beta-1/tiny11%20core%20x64%20beta%201.iso"
  62. fi
  63. if [[ "${VERSION,,}" == "tiny11" ]]; then
  64. DETECTED="win11x64"
  65. VERSION="https://archive.org/download/tiny11-2311/tiny11%202311%20x64.iso"
  66. fi
  67. if [[ "${VERSION,,}" == "tiny10" ]]; then
  68. DETECTED="win10x64-ltsc"
  69. VERSION="https://archive.org/download/tiny-10-23-h2/tiny10%20x64%2023h2.iso"
  70. fi
  71. CUSTOM=$(find "$STORAGE" -maxdepth 1 -type f -iname custom.iso -printf "%f\n" | head -n 1)
  72. [ -z "$CUSTOM" ] && CUSTOM=$(find "$STORAGE" -maxdepth 1 -type f -iname boot.iso -printf "%f\n" | head -n 1)
  73. [ -z "$CUSTOM" ] && CUSTOM=$(find "$STORAGE" -maxdepth 1 -type f -iname custom.img -printf "%f\n" | head -n 1)
  74. ESD_URL=""
  75. MACHINE="q35"
  76. TMP="$STORAGE/tmp"
  77. DIR="$TMP/unpack"
  78. FB="falling back to manual installation!"
  79. ETFS="boot/etfsboot.com"
  80. EFISYS="efi/microsoft/boot/efisys_noprompt.bin"
  81. printVersion() {
  82. local id="$1"
  83. local desc=""
  84. [[ "$id" == "win7"* ]] && desc="Windows 7"
  85. [[ "$id" == "win8"* ]] && desc="Windows 8"
  86. [[ "$id" == "win10"* ]] && desc="Windows 10"
  87. [[ "$id" == "win11"* ]] && desc="Windows 11"
  88. [[ "$id" == "winxp"* ]] && desc="Windows XP"
  89. [[ "$id" == "winvista"* ]] && desc="Windows Vista"
  90. [[ "$id" == "win2025"* ]] && desc="Windows Server 2025"
  91. [[ "$id" == "win2022"* ]] && desc="Windows Server 2022"
  92. [[ "$id" == "win2019"* ]] && desc="Windows Server 2019"
  93. [[ "$id" == "win2016"* ]] && desc="Windows Server 2016"
  94. [[ "$id" == "win2012"* ]] && desc="Windows Server 2012"
  95. [[ "$id" == "win2008"* ]] && desc="Windows Server 2008"
  96. [[ "$id" == "win10x64-ltsc" ]] && desc="Windows 10 LTSC"
  97. echo "$desc"
  98. return 0
  99. }
  100. getName() {
  101. local file="$1"
  102. local desc=""
  103. [[ "${file,,}" == "win11"* ]] && desc="Windows 11"
  104. [[ "${file,,}" == "win10"* ]] && desc="Windows 10"
  105. [[ "${file,,}" == "win8.1"* ]] && desc="Windows 8"
  106. [[ "${file,,}" == "win8"* ]] && desc="Windows 8"
  107. [[ "${file,,}" == "win7"* ]] && desc="Windows 7"
  108. [[ "${file,,}" == "winxp"* ]] && desc="Windows XP"
  109. [[ "${file,,}" == "winvista"* ]] && desc="Windows Vista"
  110. [[ "${file,,}" == "tiny10"* ]] && desc="Tiny 10"
  111. [[ "${file,,}" == "tiny11"* ]] && desc="Tiny 11"
  112. [[ "${file,,}" == "tiny11_core"* ]] && desc="Tiny 11 Core"
  113. [[ "${file,,}" == *"windows11"* ]] && desc="Windows 11"
  114. [[ "${file,,}" == *"windows10"* ]] && desc="Windows 10"
  115. [[ "${file,,}" == *"windows8.1"* ]] && desc="Windows 8"
  116. [[ "${file,,}" == *"windows8"* ]] && desc="Windows 8"
  117. [[ "${file,,}" == *"windows7"* ]] && desc="Windows 7"
  118. [[ "${file,,}" == *"windowsxp"* ]] && desc="Windows XP"
  119. [[ "${file,,}" == *"windowsvista"* ]] && desc="Windows Vista"
  120. [[ "${file,,}" == *"windows_11"* ]] && desc="Windows 11"
  121. [[ "${file,,}" == *"windows_10"* ]] && desc="Windows 10"
  122. [[ "${file,,}" == *"windows_8.1"* ]] && desc="Windows 8"
  123. [[ "${file,,}" == *"windows_8"* ]] && desc="Windows 8"
  124. [[ "${file,,}" == *"windows_7"* ]] && desc="Windows 7"
  125. [[ "${file,,}" == *"windows_xp"* ]] && desc="Windows XP"
  126. [[ "${file,,}" == *"windows_vista"* ]] && desc="Windows Vista"
  127. [[ "${file,,}" == *"server2008"* ]] && desc="Windows Server 2008"
  128. [[ "${file,,}" == *"server2012"* ]] && desc="Windows Server 2012"
  129. [[ "${file,,}" == *"server2016"* ]] && desc="Windows Server 2016"
  130. [[ "${file,,}" == *"server2019"* ]] && desc="Windows Server 2019"
  131. [[ "${file,,}" == *"server2022"* ]] && desc="Windows Server 2022"
  132. [[ "${file,,}" == *"server2025"* ]] && desc="Windows Server 2025"
  133. [[ "${file,,}" == *"server_2008"* ]] && desc="Windows Server 2008"
  134. [[ "${file,,}" == *"server_2012"* ]] && desc="Windows Server 2012"
  135. [[ "${file,,}" == *"server_2016"* ]] && desc="Windows Server 2016"
  136. [[ "${file,,}" == *"server_2019"* ]] && desc="Windows Server 2019"
  137. [[ "${file,,}" == *"server_2022"* ]] && desc="Windows Server 2022"
  138. [[ "${file,,}" == *"server_2025"* ]] && desc="Windows Server 2025"
  139. echo "$desc"
  140. return 0
  141. }
  142. getVersion() {
  143. local name="$1"
  144. local detected=""
  145. [[ "${name,,}" == *"windows 7"* ]] && detected="win7x64"
  146. [[ "${name,,}" == *"windows 8"* ]] && detected="win81x64"
  147. [[ "${name,,}" == *"windows 11"* ]] && detected="win11x64"
  148. [[ "${name,,}" == *"windows vista"* ]] && detected="winvistax64"
  149. [[ "${name,,}" == *"server 2025"* ]] && detected="win2025-eval"
  150. [[ "${name,,}" == *"server 2022"* ]] && detected="win2022-eval"
  151. [[ "${name,,}" == *"server 2019"* ]] && detected="win2019-eval"
  152. [[ "${name,,}" == *"server 2016"* ]] && detected="win2016-eval"
  153. [[ "${name,,}" == *"server 2012"* ]] && detected="win2012r2-eval"
  154. [[ "${name,,}" == *"server 2008"* ]] && detected="win2008r2"
  155. if [[ "${name,,}" == *"windows 10"* ]]; then
  156. if [[ "${name,,}" == *"ltsc"* ]]; then
  157. detected="win10x64-ltsc"
  158. else
  159. detected="win10x64"
  160. fi
  161. fi
  162. echo "$detected"
  163. return 0
  164. }
  165. hasDisk() {
  166. [ -b "${DEVICE:-}" ] && return 0
  167. if [ -f "$STORAGE/data.img" ] || [ -f "$STORAGE/data.qcow2" ]; then
  168. return 0
  169. fi
  170. return 1
  171. }
  172. skipInstall() {
  173. if hasDisk && [ -f "$STORAGE/windows.boot" ]; then
  174. return 0
  175. fi
  176. return 1
  177. }
  178. finishInstall() {
  179. local iso="$1"
  180. # Mark ISO as prepared via magic byte
  181. printf '\x16' | dd of="$iso" bs=1 seek=0 count=1 conv=notrunc status=none
  182. rm -f "$STORAGE/windows.boot"
  183. cp /run/version "$STORAGE/windows.ver"
  184. if [[ "${BOOT_MODE,,}" == "windows_legacy" ]]; then
  185. echo "$MACHINE" > "$STORAGE/windows.old"
  186. else
  187. rm -f "$STORAGE/windows.old"
  188. fi
  189. rm -rf "$TMP"
  190. return 0
  191. }
  192. abortInstall() {
  193. local iso="$1"
  194. if [[ "$iso" != "$STORAGE/$BASE" ]]; then
  195. mv -f "$iso" "$STORAGE/$BASE"
  196. fi
  197. finishInstall "$STORAGE/$BASE"
  198. return 0
  199. }
  200. startInstall() {
  201. html "Starting Windows..."
  202. if [ -f "$STORAGE/$CUSTOM" ]; then
  203. EXTERNAL="Y"
  204. BASE="$CUSTOM"
  205. else
  206. CUSTOM=""
  207. if [[ "${VERSION,,}" == "http"* ]]; then
  208. EXTERNAL="Y"
  209. else
  210. EXTERNAL="N"
  211. fi
  212. if [[ "$EXTERNAL" != [Yy1]* ]]; then
  213. BASE="$VERSION.iso"
  214. else
  215. BASE=$(basename "${VERSION%%\?*}")
  216. : "${BASE//+/ }"; printf -v BASE '%b' "${_//%/\\x}"
  217. BASE=$(echo "$BASE" | sed -e 's/[^A-Za-z0-9._-]/_/g')
  218. fi
  219. [[ "${BASE,,}" == "boot."* ]] && BASE="windows.iso"
  220. [[ "${BASE,,}" == "custom."* ]] && BASE="windows.iso"
  221. fi
  222. [ -z "$MANUAL" ] && MANUAL="N"
  223. if [ -f "$STORAGE/$BASE" ]; then
  224. # Check if the ISO was already processed by our script
  225. local magic=""
  226. magic=$(dd if="$STORAGE/$BASE" seek=0 bs=1 count=1 status=none | tr -d '\000')
  227. magic="$(printf '%s' "$magic" | od -A n -t x1 -v | tr -d ' \n')"
  228. if [[ "$magic" == "16" ]]; then
  229. if hasDisk || [[ "$MANUAL" = [Yy1]* ]]; then
  230. return 1
  231. fi
  232. fi
  233. EXTERNAL="Y"
  234. CUSTOM="$BASE"
  235. else
  236. if skipInstall; then
  237. BASE=""
  238. return 1
  239. fi
  240. fi
  241. rm -rf "$TMP"
  242. mkdir -p "$TMP"
  243. if [ ! -f "$STORAGE/$CUSTOM" ]; then
  244. CUSTOM=""
  245. ISO="$TMP/$BASE"
  246. else
  247. ISO="$STORAGE/$CUSTOM"
  248. fi
  249. return 0
  250. }
  251. getESD() {
  252. local dir="$1"
  253. local file="$2"
  254. local architecture="x64"
  255. local winCatalog size
  256. case "${VERSION,,}" in
  257. win11x64)
  258. winCatalog="https://go.microsoft.com/fwlink?linkid=2156292"
  259. ;;
  260. win10x64)
  261. winCatalog="https://go.microsoft.com/fwlink/?LinkId=841361"
  262. ;;
  263. *)
  264. error "Invalid ESD version specified: $VERSION"
  265. return 1
  266. ;;
  267. esac
  268. local msg="Downloading product information from Microsoft..."
  269. info "$msg" && html "$msg"
  270. rm -rf "$dir"
  271. mkdir -p "$dir"
  272. local wFile="catalog.cab"
  273. { wget "$winCatalog" -O "$dir/$wFile" -q --no-check-certificate; rc=$?; } || :
  274. (( rc != 0 )) && error "Failed to download $winCatalog , reason: $rc" && return 1
  275. cd "$dir"
  276. if ! cabextract "$wFile" > /dev/null; then
  277. cd /run
  278. error "Failed to extract CAB file!" && return 1
  279. fi
  280. cd /run
  281. if [ ! -f "$dir/products.xml" ]; then
  282. error "Failed to find products.xml!" && return 1
  283. fi
  284. local esdLang="en-us"
  285. local editionName="Professional"
  286. local edQuery='//File[Architecture="'${architecture}'"][Edition="'${editionName}'"]'
  287. echo -e '<Catalog>' > "${dir}/products_filter.xml"
  288. xmllint --nonet --xpath "${edQuery}" "${dir}/products.xml" >> "${dir}/products_filter.xml" 2>/dev/null
  289. echo -e '</Catalog>'>> "${dir}/products_filter.xml"
  290. xmllint --nonet --xpath '//File[LanguageCode="'${esdLang}'"]' "${dir}/products_filter.xml" >"${dir}/esd_edition.xml"
  291. size=$(stat -c%s "${dir}/esd_edition.xml")
  292. if ((size<20)); then
  293. error "Failed to find Windows product!" && return 1
  294. fi
  295. ESD_URL=$(xmllint --nonet --xpath '//FilePath' "${dir}/esd_edition.xml" | sed -E -e 's/<[\/]?FilePath>//g')
  296. if [ -z "$ESD_URL" ]; then
  297. error "Failed to find ESD url!" && return 1
  298. fi
  299. rm -rf "$dir"
  300. return 0
  301. }
  302. downloadImage() {
  303. local iso="$1"
  304. local url="$2"
  305. local file="$iso"
  306. local desc rc progress
  307. rm -f "$iso"
  308. if [[ "$EXTERNAL" != [Yy1]* ]]; then
  309. file="$iso.PART"
  310. desc=$(printVersion "$VERSION")
  311. [ -z "$desc" ] && desc="Windows"
  312. else
  313. desc=$(getName "$BASE")
  314. [ -z "$desc" ] && desc="$BASE"
  315. fi
  316. local msg="Downloading $desc..."
  317. info "$msg" && html "$msg"
  318. /run/progress.sh "$file" "Downloading $desc ([P])..." &
  319. if [[ "$EXTERNAL" != [Yy1]* ]]; then
  320. cd "$TMP"
  321. { /run/mido.sh "$url"; rc=$?; } || :
  322. cd /run
  323. fKill "progress.sh"
  324. if (( rc == 0 )); then
  325. [ ! -f "$iso" ] && return 1
  326. html "Download finished successfully..."
  327. return 0
  328. fi
  329. if [[ "$VERSION" != "win10x64"* ]] && [[ "$VERSION" != "win11x64" ]]; then
  330. return 1
  331. fi
  332. info "Failed to download $desc using Mido, will try a different method now..."
  333. rm -rf "$TMP"
  334. mkdir -p "$TMP"
  335. ISO="$TMP/$VERSION.esd"
  336. iso="$ISO"
  337. file="$ISO"
  338. rm -f "$iso"
  339. if ! getESD "$TMP/esd" "$iso"; then
  340. return 1
  341. fi
  342. url="$ESD_URL"
  343. msg="Downloading $desc..."
  344. info "$msg" && html "$msg"
  345. /run/progress.sh "$iso" "Downloading $desc ([P])..." &
  346. fi
  347. # Check if running with interactive TTY or redirected to docker log
  348. if [ -t 1 ]; then
  349. progress="--progress=bar:noscroll"
  350. else
  351. progress="--progress=dot:giga"
  352. fi
  353. { wget "$url" -O "$iso" -q --no-check-certificate --show-progress "$progress"; rc=$?; } || :
  354. fKill "progress.sh"
  355. (( rc != 0 )) && error "Failed to download $url , reason: $rc" && exit 60
  356. [ ! -f "$iso" ] && return 1
  357. html "Download finished successfully..."
  358. return 0
  359. }
  360. extractESD() {
  361. local iso="$1"
  362. local dir="$2"
  363. local size size_gb space space_gb desc
  364. desc=$(printVersion "$VERSION")
  365. local msg="Extracting $desc bootdisk..."
  366. info "$msg" && html "$msg"
  367. size=16106127360
  368. size_gb=$(( (size + 1073741823)/1073741824 ))
  369. space=$(df --output=avail -B 1 "$TMP" | tail -n 1)
  370. space_gb=$(( (space + 1073741823)/1073741824 ))
  371. if ((size<10000000)); then
  372. error "Invalid ESD file: Size is smaller than 10 MB" && exit 62
  373. fi
  374. if (( size > space )); then
  375. error "Not enough free space in $STORAGE, have $space_gb GB available but need at least $size_gb GB." && exit 63
  376. fi
  377. rm -rf "$dir"
  378. mkdir -p "$dir"
  379. local esdImageCount
  380. esdImageCount=$(wimlib-imagex info "${iso}" | awk '/Image Count:/ {print $3}')
  381. wimlib-imagex apply "$iso" 1 "${dir}" --quiet 2>/dev/null || {
  382. retVal=$?
  383. error "Extracting bootdisk failed" && return $retVal
  384. }
  385. local bootWimFile="${dir}/sources/boot.wim"
  386. local installWimFile="${dir}/sources/install.wim"
  387. local msg="Extracting $desc environment..."
  388. info "$msg" && html "$msg"
  389. wimlib-imagex export "${iso}" 2 "${bootWimFile}" --compress=LZX --chunk-size 32K --quiet || {
  390. retVal=$?
  391. error "Adding WinPE failed" && return ${retVal}
  392. }
  393. local msg="Extracting $desc setup..."
  394. info "$msg" && html "$msg"
  395. wimlib-imagex export "${iso}" 3 "$bootWimFile" --compress=LZX --chunk-size 32K --boot --quiet || {
  396. retVal=$?
  397. error "Adding Windows Setup failed" && return ${retVal}
  398. }
  399. local msg="Extracting $desc image..."
  400. info "$msg" && html "$msg"
  401. local edition imageIndex imageEdition
  402. case "${VERSION,,}" in
  403. win11x64)
  404. edition="11 pro"
  405. ;;
  406. win10x64)
  407. edition="10 pro"
  408. ;;
  409. *)
  410. error "Invalid version specified: $VERSION"
  411. return 1
  412. ;;
  413. esac
  414. for (( imageIndex=4; imageIndex<=esdImageCount; imageIndex++ )); do
  415. imageEdition=$(wimlib-imagex info "${iso}" ${imageIndex} | grep '^Description:' | sed 's/Description:[ \t]*//')
  416. [[ "${imageEdition,,}" != *"$edition"* ]] && continue
  417. wimlib-imagex export "${iso}" ${imageIndex} "${installWimFile}" --compress=LZMS --chunk-size 128K --quiet || {
  418. retVal=$?
  419. error "Addition of ${imageIndex} to the image failed" && return $retVal
  420. }
  421. return 0
  422. done
  423. error "Failed to find product in install.wim!"
  424. return 1
  425. }
  426. extractImage() {
  427. local iso="$1"
  428. local dir="$2"
  429. local desc="downloaded ISO"
  430. local size size_gb space space_gb
  431. if [[ "${iso,,}" == *".esd" ]]; then
  432. if ! extractESD "$iso" "$dir"; then
  433. rm -f "$iso"
  434. error "Failed to extract ESD file!"
  435. exit 67
  436. fi
  437. return 0
  438. fi
  439. if [[ "$EXTERNAL" != [Yy1]* ]] && [ -z "$CUSTOM" ]; then
  440. desc=$(printVersion "$VERSION")
  441. [ -z "$desc" ] && desc="downloaded ISO"
  442. fi
  443. local msg="Extracting $desc image..."
  444. [ -n "$CUSTOM" ] && msg="Extracting local ISO image..."
  445. info "$msg" && html "$msg"
  446. size=$(stat -c%s "$iso")
  447. size_gb=$(( (size + 1073741823)/1073741824 ))
  448. space=$(df --output=avail -B 1 "$TMP" | tail -n 1)
  449. space_gb=$(( (space + 1073741823)/1073741824 ))
  450. if ((size<10000000)); then
  451. error "Invalid ISO file: Size is smaller than 10 MB" && exit 62
  452. fi
  453. if (( size > space )); then
  454. error "Not enough free space in $STORAGE, have $space_gb GB available but need at least $size_gb GB." && exit 63
  455. fi
  456. rm -rf "$dir"
  457. if ! 7z x "$iso" -o"$dir" > /dev/null; then
  458. rm -f "$iso"
  459. error "Failed to extract ISO file!"
  460. exit 66
  461. fi
  462. return 0
  463. }
  464. detectImage() {
  465. XML=""
  466. local dir="$1"
  467. if [ -n "$CUSTOM" ]; then
  468. DETECTED=""
  469. else
  470. if [ -z "$DETECTED" ] && [[ "$EXTERNAL" != [Yy1]* ]]; then
  471. DETECTED="$VERSION"
  472. fi
  473. fi
  474. if [ -n "$DETECTED" ]; then
  475. if [ -f "/run/assets/$DETECTED.xml" ]; then
  476. [[ "$MANUAL" != [Yy1]* ]] && XML="$DETECTED.xml"
  477. return 0
  478. fi
  479. if [[ "${DETECTED,,}" != "winxp"* ]]; then
  480. local dsc
  481. dsc=$(printVersion "$DETECTED")
  482. [ -z "$dsc" ] && dsc="$DETECTED"
  483. warn "got $dsc, but no matching XML file exists, $FB."
  484. fi
  485. return 0
  486. fi
  487. info "Detecting Windows version from ISO image..."
  488. if [ -f "$dir/WIN51" ] || [ -f "$dir/SETUPXP.HTM" ]; then
  489. DETECTED="winxpx86"
  490. info "Detected: Windows XP"
  491. return 0
  492. fi
  493. local src loc tag result name name2 desc
  494. src=$(find "$dir" -maxdepth 1 -type d -iname sources | head -n 1)
  495. if [ ! -d "$src" ]; then
  496. warn "failed to locate 'sources' folder in ISO image, $FB"
  497. BOOT_MODE="windows_legacy"
  498. return 1
  499. fi
  500. loc=$(find "$src" -maxdepth 1 -type f -iname install.wim | head -n 1)
  501. [ ! -f "$loc" ] && loc=$(find "$src" -maxdepth 1 -type f -iname install.esd | head -n 1)
  502. if [ ! -f "$loc" ]; then
  503. warn "failed to locate 'install.wim' or 'install.esd' in ISO image, $FB"
  504. BOOT_MODE="windows_legacy"
  505. return 1
  506. fi
  507. tag="DISPLAYNAME"
  508. result=$(wimlib-imagex info -xml "$loc" | tr -d '\000')
  509. name=$(sed -n "/$tag/{s/.*<$tag>\(.*\)<\/$tag>.*/\1/;p}" <<< "$result")
  510. DETECTED=$(getVersion "$name")
  511. if [ -z "$DETECTED" ]; then
  512. tag="PRODUCTNAME"
  513. name2=$(sed -n "/$tag/{s/.*<$tag>\(.*\)<\/$tag>.*/\1/;p}" <<< "$result")
  514. [ -z "$name" ] && name="$name2"
  515. DETECTED=$(getVersion "$name2")
  516. fi
  517. if [ -z "$DETECTED" ]; then
  518. warn "failed to determine Windows version from string '$name', $FB"
  519. return 0
  520. fi
  521. desc=$(printVersion "$DETECTED")
  522. [ -z "$desc" ] && desc="$DETECTED"
  523. if [ -f "/run/assets/$DETECTED.xml" ]; then
  524. [[ "$MANUAL" != [Yy1]* ]] && XML="$DETECTED.xml"
  525. info "Detected: $desc"
  526. else
  527. warn "detected $desc, but no matching XML file exists, $FB."
  528. fi
  529. return 0
  530. }
  531. prepareXP() {
  532. local iso="$1"
  533. local dir="$2"
  534. local arch="x86"
  535. local target="$dir/I386"
  536. if [ -d "$dir/AMD64" ]; then
  537. arch="amd64"
  538. target="$dir/AMD64"
  539. fi
  540. MACHINE="pc-q35-2.10"
  541. BOOT_MODE="windows_legacy"
  542. ETFS="[BOOT]/Boot-NoEmul.img"
  543. [[ "$MANUAL" == [Yy1]* ]] && return 0
  544. local drivers="$TMP/drivers"
  545. rm -rf "$drivers"
  546. if ! 7z x /run/drivers.iso -o"$drivers" > /dev/null; then
  547. error "Failed to extract driver ISO file!"
  548. exit 66
  549. fi
  550. cp "$drivers/viostor/xp/$arch/viostor.sys" "$target"
  551. mkdir -p "$dir/\$OEM\$/\$1/Drivers/viostor"
  552. cp "$drivers/viostor/xp/$arch/viostor.cat" "$dir/\$OEM\$/\$1/Drivers/viostor"
  553. cp "$drivers/viostor/xp/$arch/viostor.inf" "$dir/\$OEM\$/\$1/Drivers/viostor"
  554. cp "$drivers/viostor/xp/$arch/viostor.sys" "$dir/\$OEM\$/\$1/Drivers/viostor"
  555. mkdir -p "$dir/\$OEM\$/\$1/Drivers/NetKVM"
  556. cp "$drivers/NetKVM/xp/$arch/netkvm.cat" "$dir/\$OEM\$/\$1/Drivers/NetKVM"
  557. cp "$drivers/NetKVM/xp/$arch/netkvm.inf" "$dir/\$OEM\$/\$1/Drivers/NetKVM"
  558. cp "$drivers/NetKVM/xp/$arch/netkvm.sys" "$dir/\$OEM\$/\$1/Drivers/NetKVM"
  559. sed -i '/^\[SCSI.Load\]/s/$/\nviostor=viostor.sys,4/' "$target/TXTSETUP.SIF"
  560. sed -i '/^\[SourceDisksFiles.'"$arch"'\]/s/$/\nviostor.sys=1,,,,,,4_,4,1,,,1,4/' "$target/TXTSETUP.SIF"
  561. sed -i '/^\[SCSI\]/s/$/\nviostor=\"Red Hat VirtIO SCSI Disk Device\"/' "$target/TXTSETUP.SIF"
  562. sed -i '/^\[HardwareIdsDatabase\]/s/$/\nPCI\\VEN_1AF4\&DEV_1001\&SUBSYS_00000000=\"viostor\"/' "$target/TXTSETUP.SIF"
  563. sed -i '/^\[HardwareIdsDatabase\]/s/$/\nPCI\\VEN_1AF4\&DEV_1001\&SUBSYS_00020000=\"viostor\"/' "$target/TXTSETUP.SIF"
  564. sed -i '/^\[HardwareIdsDatabase\]/s/$/\nPCI\\VEN_1AF4\&DEV_1001\&SUBSYS_00021AF4=\"viostor\"/' "$target/TXTSETUP.SIF"
  565. sed -i '/^\[HardwareIdsDatabase\]/s/$/\nPCI\\VEN_1AF4\&DEV_1001\&SUBSYS_00000000=\"viostor\"/' "$target/TXTSETUP.SIF"
  566. mkdir -p "$dir/\$OEM\$/\$1/Drivers/sata"
  567. cp -a "$drivers/sata/xp/$arch/." "$dir/\$OEM\$/\$1/Drivers/sata"
  568. cp -a "$drivers/sata/xp/$arch/." "$target"
  569. sed -i '/^\[SCSI.Load\]/s/$/\niaStor=iaStor.sys,4/' "$target/TXTSETUP.SIF"
  570. sed -i '/^\[FileFlags\]/s/$/\niaStor.sys = 16/' "$target/TXTSETUP.SIF"
  571. sed -i '/^\[SourceDisksFiles.'"$arch"'\]/s/$/\niaStor.cat = 1,,,,,,,1,0,0/' "$target/TXTSETUP.SIF"
  572. sed -i '/^\[SourceDisksFiles.'"$arch"'\]/s/$/\niaStor.inf = 1,,,,,,,1,0,0/' "$target/TXTSETUP.SIF"
  573. sed -i '/^\[SourceDisksFiles.'"$arch"'\]/s/$/\niaStor.sys = 1,,,,,,4_,4,1,,,1,4/' "$target/TXTSETUP.SIF"
  574. sed -i '/^\[SourceDisksFiles.'"$arch"'\]/s/$/\niaStor.sys = 1,,,,,,,1,0,0/' "$target/TXTSETUP.SIF"
  575. sed -i '/^\[SourceDisksFiles.'"$arch"'\]/s/$/\niaahci.cat = 1,,,,,,,1,0,0/' "$target/TXTSETUP.SIF"
  576. sed -i '/^\[SourceDisksFiles.'"$arch"'\]/s/$/\niaAHCI.inf = 1,,,,,,,1,0,0/' "$target/TXTSETUP.SIF"
  577. sed -i '/^\[SCSI\]/s/$/\niaStor=\"Intel\(R\) SATA RAID\/AHCI Controller\"/' "$target/TXTSETUP.SIF"
  578. sed -i '/^\[HardwareIdsDatabase\]/s/$/\nPCI\\VEN_8086\&DEV_2922\&CC_0106=\"iaStor\"/' "$target/TXTSETUP.SIF"
  579. # Windows XP Pro generic key (no activation)
  580. local key="DR8GV-C8V6J-BYXHG-7PYJR-DB66Y"
  581. find "$target" -maxdepth 1 -type f -iname winnt.sif -exec rm {} \;
  582. { echo "[Data]"
  583. echo "AutoPartition=1"
  584. echo "MsDosInitiated=\"0\""
  585. echo "UnattendedInstall=\"Yes\""
  586. echo "AutomaticUpdates=\"Yes\""
  587. echo ""
  588. echo "[Unattended]"
  589. echo "UnattendSwitch=Yes"
  590. echo "UnattendMode=FullUnattended"
  591. echo "FileSystem=NTFS"
  592. echo "OemSkipEula=Yes"
  593. echo "OemPreinstall=Yes"
  594. echo "Repartition=Yes"
  595. echo "WaitForReboot=\"No\""
  596. echo "DriverSigningPolicy=\"Ignore\""
  597. echo "NonDriverSigningPolicy=\"Ignore\""
  598. echo "OemPnPDriversPath=\"Drivers\viostor;Drivers\NetKVM;Drivers\sata\""
  599. echo "NoWaitAfterTextMode=1"
  600. echo "NoWaitAfterGUIMode=1"
  601. echo "FileSystem-ConvertNTFS"
  602. echo "ExtendOemPartition=0"
  603. echo "Hibernation=\"No\""
  604. echo ""
  605. echo "[GuiUnattended]"
  606. echo "OEMSkipRegional=1"
  607. echo "OemSkipWelcome=1"
  608. echo "AdminPassword=*"
  609. echo "TimeZone=0"
  610. echo "AutoLogon=Yes"
  611. echo "AutoLogonCount=65432"
  612. echo ""
  613. echo "[UserData]"
  614. echo "FullName=\"Docker\""
  615. echo "ComputerName=\"*\""
  616. echo "OrgName=\"Windows for Docker\""
  617. echo "ProductKey=$key"
  618. echo ""
  619. echo "[Identification]"
  620. echo "JoinWorkgroup = WORKGROUP"
  621. echo ""
  622. echo "[Networking]"
  623. echo "InstallDefaultComponents=Yes"
  624. echo ""
  625. echo "[Branding]"
  626. echo "BrandIEUsingUnattended=Yes"
  627. echo ""
  628. echo "[URL]"
  629. echo "Home_Page = http://www.google.com"
  630. echo "Search_Page = http://www.google.com"
  631. echo ""
  632. echo "[RegionalSettings]"
  633. echo "Language=00000409"
  634. echo ""
  635. echo "[TerminalServices]"
  636. echo "AllowConnections=1"
  637. } | unix2dos > "$target/WINNT.SIF"
  638. { echo "Windows Registry Editor Version 5.00"
  639. echo ""
  640. echo "[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Security]"
  641. echo "\"FirstRunDisabled\"=dword:00000001"
  642. echo "\"AntiVirusOverride\"=dword:00000001"
  643. echo "\"FirewallOverride\"=dword:00000001"
  644. echo "\"FirewallDisableNotify\"=dword:00000001"
  645. echo "\"UpdatesDisableNotify\"=dword:00000001"
  646. echo "\"AntiVirusDisableNotify\"=dword:00000001"
  647. echo ""
  648. echo "[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\wscsvc]"
  649. echo "\"Start\"=dword:00000004"
  650. echo ""
  651. echo "[HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\WindowsFirewall\StandardProfile]"
  652. echo "\"EnableFirewall\"=dword:00000000"
  653. echo ""
  654. echo "[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SharedAccess]"
  655. echo "\"Start\"=dword:00000004"
  656. echo
  657. echo "[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\StandardProfile\GloballyOpenPorts\List]"
  658. echo "\"3389:TCP\"=\"3389:TCP:*:Enabled:@xpsp2res.dll,-22009\""
  659. echo ""
  660. echo "[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa]"
  661. echo "\"LimitBlankPasswordUse\"=dword:00000000"
  662. echo ""
  663. echo "[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Applets\Tour]"
  664. echo "\"RunCount\"=dword:00000000"
  665. echo ""
  666. echo "[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced]"
  667. echo "\"HideFileExt\"=dword:00000000"
  668. echo ""
  669. echo "[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon]"
  670. echo "\"DefaultUserName\"=\"Docker\""
  671. echo "\"DefaultDomainName\"=\"Dockur\""
  672. echo "\"AltDefaultUserName\"=\"Docker\""
  673. echo "\"AltDefaultDomainName\"=\"Dockur\""
  674. echo "\"AutoAdminLogon\"=\"1\""
  675. } | unix2dos > "$dir/\$OEM\$/install.reg"
  676. { echo "Set WshShell = WScript.CreateObject(\"WScript.Shell\")"
  677. echo "Set WshNetwork = WScript.CreateObject(\"WScript.Network\")"
  678. echo "Set oMachine = GetObject(\"WinNT://\" & WshNetwork.ComputerName)"
  679. echo "Set oInfoUser = GetObject(\"WinNT://\" & WshNetwork.ComputerName & \"/Administrator,user\")"
  680. echo "Set oUser = oMachine.MoveHere(oInfoUser.ADsPath,\"Docker\")"
  681. } | unix2dos > "$dir/\$OEM\$/admin.vbs"
  682. { echo "[COMMANDS]"
  683. echo "\"REGEDIT /s install.reg\""
  684. echo "\"Wscript admin.vbs\""
  685. } | unix2dos > "$dir/\$OEM\$/cmdlines.txt"
  686. rm -rf "$drivers"
  687. return 0
  688. }
  689. prepareLegacy() {
  690. local iso="$1"
  691. local dir="$2"
  692. ETFS="boot.img"
  693. BOOT_MODE="windows_legacy"
  694. rm -f "$dir/$ETFS"
  695. local len offset
  696. len=$(isoinfo -d -i "$iso" | grep "Nsect " | grep -o "[^ ]*$")
  697. offset=$(isoinfo -d -i "$iso" | grep "Bootoff " | grep -o "[^ ]*$")
  698. if ! dd "if=$iso" "of=$dir/$ETFS" bs=2048 "count=$len" "skip=$offset" status=none; then
  699. error "Failed to extract boot image from ISO!"
  700. exit 67
  701. fi
  702. return 0
  703. }
  704. prepareImage() {
  705. local iso="$1"
  706. local dir="$2"
  707. if [[ "${BOOT_MODE,,}" != "windows_legacy" ]]; then
  708. if [[ "${DETECTED,,}" != "winxp"* ]] && [[ "${DETECTED,,}" != "win2008"* ]]; then
  709. if [[ "${DETECTED,,}" != "winvista"* ]] && [[ "${DETECTED,,}" != "win7"* ]]; then
  710. if [ -f "$dir/$ETFS" ] && [ -f "$dir/$EFISYS" ]; then
  711. return 0
  712. fi
  713. if [ ! -f "$dir/$ETFS" ]; then
  714. warn "failed to locate file 'etfsboot.com' in ISO image, falling back to legacy boot!"
  715. else
  716. warn "failed to locate file 'efisys_noprompt.bin' in ISO image, falling back to legacy boot!"
  717. fi
  718. fi
  719. fi
  720. fi
  721. if [[ "${DETECTED,,}" == "winxp"* ]]; then
  722. if ! prepareXP "$iso" "$dir"; then
  723. error "Failed to prepare Windows XP ISO!"
  724. return 1
  725. fi
  726. else
  727. if ! prepareLegacy "$iso" "$dir"; then
  728. error "Failed to prepare Windows ISO!"
  729. return 1
  730. fi
  731. fi
  732. return 0
  733. }
  734. updateImage() {
  735. local iso="$1"
  736. local dir="$2"
  737. local asset="/run/assets/$3"
  738. local path src loc index result
  739. [ ! -f "$asset" ] && return 0
  740. path=$(find "$dir" -maxdepth 1 -type f -iname autounattend.xml | head -n 1)
  741. [ -n "$path" ] && cp "$asset" "$path"
  742. src=$(find "$dir" -maxdepth 1 -type d -iname sources | head -n 1)
  743. if [ ! -d "$src" ]; then
  744. warn "failed to locate 'sources' folder in ISO image, $FB"
  745. BOOT_MODE="windows_legacy"
  746. return 1
  747. fi
  748. loc=$(find "$src" -maxdepth 1 -type f -iname boot.wim | head -n 1)
  749. [ ! -f "$loc" ] && loc=$(find "$src" -maxdepth 1 -type f -iname boot.esd | head -n 1)
  750. if [ ! -f "$loc" ]; then
  751. warn "failed to locate 'boot.wim' or 'boot.esd' in ISO image, $FB"
  752. BOOT_MODE="windows_legacy"
  753. return 1
  754. fi
  755. info "Adding XML file for automatic installation..."
  756. index="1"
  757. result=$(wimlib-imagex info -xml "$loc" | tr -d '\000')
  758. if [[ "${result^^}" == *"<IMAGE INDEX=\"2\">"* ]]; then
  759. index="2"
  760. fi
  761. if ! wimlib-imagex update "$loc" "$index" --command "add $asset /autounattend.xml" > /dev/null; then
  762. warn "failed to add XML to ISO image, $FB"
  763. return 1
  764. fi
  765. return 0
  766. }
  767. buildImage() {
  768. local dir="$1"
  769. local cat="BOOT.CAT"
  770. local label="${BASE%.*}"
  771. local log="/run/shm/iso.log"
  772. local size size_gb space space_gb desc
  773. label="${label::30}"
  774. local out="$TMP/$label.tmp"
  775. rm -f "$out"
  776. desc=$(printVersion "$DETECTED")
  777. [ -z "$desc" ] && desc="ISO"
  778. local msg="Building $desc image..."
  779. info "$msg" && html "$msg"
  780. size=$(du -h -b --max-depth=0 "$dir" | cut -f1)
  781. size_gb=$(( (size + 1073741823)/1073741824 ))
  782. space=$(df --output=avail -B 1 "$TMP" | tail -n 1)
  783. space_gb=$(( (space + 1073741823)/1073741824 ))
  784. if (( size > space )); then
  785. error "Not enough free space in $STORAGE, have $space_gb GB available but need at least $size_gb GB."
  786. return 1
  787. fi
  788. if [[ "${BOOT_MODE,,}" != "windows_legacy" ]]; then
  789. if ! genisoimage -o "$out" -b "$ETFS" -no-emul-boot -c "$cat" -iso-level 4 -J -l -D -N -joliet-long -relaxed-filenames -V "$label" \
  790. -udf -boot-info-table -eltorito-alt-boot -eltorito-boot "$EFISYS" -no-emul-boot -allow-limited-size -quiet "$dir" 2> "$log"; then
  791. [ -f "$log" ] && echo "$(<"$log")"
  792. return 1
  793. fi
  794. else
  795. if [[ "${DETECTED,,}" != "winxp"* ]]; then
  796. if ! genisoimage -o "$out" -b "$ETFS" -no-emul-boot -c "$cat" -iso-level 2 -J -l -D -N -joliet-long -relaxed-filenames -V "$label" \
  797. -udf -allow-limited-size -quiet "$dir" 2> "$log"; then
  798. [ -f "$log" ] && echo "$(<"$log")"
  799. return 1
  800. fi
  801. else
  802. if ! genisoimage -o "$out" -b "$ETFS" -no-emul-boot -boot-load-seg 1984 -boot-load-size 4 -c "$cat" -iso-level 2 -J -l -D -N -joliet-long \
  803. -relaxed-filenames -V "$label" -quiet "$dir" 2> "$log"; then
  804. [ -f "$log" ] && echo "$(<"$log")"
  805. return 1
  806. fi
  807. fi
  808. fi
  809. local error=""
  810. local hide="Warning: creating filesystem that does not conform to ISO-9660."
  811. [ -f "$log" ] && error="$(<"$log")"
  812. [[ "$error" != "$hide" ]] && echo "$error"
  813. if [ -f "$STORAGE/$BASE" ]; then
  814. error "File $STORAGE/$BASE does already exist?!"
  815. return 1
  816. fi
  817. mv "$out" "$STORAGE/$BASE"
  818. return 0
  819. }
  820. ######################################
  821. if ! startInstall; then
  822. if [ -f "$STORAGE/windows.old" ]; then
  823. MACHINE=$(<"$STORAGE/windows.old")
  824. [ -z "$MACHINE" ] && MACHINE="q35"
  825. BOOT_MODE="windows_legacy"
  826. fi
  827. rm -rf "$TMP"
  828. return 0
  829. fi
  830. if [ ! -f "$ISO" ]; then
  831. if ! downloadImage "$ISO" "$VERSION"; then
  832. error "Failed to download $VERSION"
  833. exit 61
  834. fi
  835. fi
  836. if ! extractImage "$ISO" "$DIR"; then
  837. abortInstall "$ISO"
  838. return 0
  839. fi
  840. if ! detectImage "$DIR"; then
  841. abortInstall "$ISO"
  842. return 0
  843. fi
  844. if ! prepareImage "$ISO" "$DIR"; then
  845. abortInstall "$ISO"
  846. return 0
  847. fi
  848. if ! updateImage "$ISO" "$DIR" "$XML"; then
  849. abortInstall "$ISO"
  850. return 0
  851. fi
  852. rm -f "$ISO"
  853. if ! buildImage "$DIR"; then
  854. error "Failed to build image!"
  855. exit 65
  856. fi
  857. finishInstall "$STORAGE/$BASE"
  858. html "Successfully prepared image for installation..."
  859. return 0