1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870
|
; Debian-Installer Loader - Installation
;
; Copyright (C) 2007,2008,2009 Robert Millan <rmh@aybabtu.com>
; Copyright (C) 2010,2011 Didier Raboud <odyx@debian.org>
;
; This program is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation, either version 3 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program. If not, see <http://www.gnu.org/licenses/>.
!define EFI_FOLDER "EFI\debian"
!define EFI_LOADER "shimx64.efi"
!define GRUB2_CFG_FILE "grub.cfg"
!define GRUB2_EFI_FILE "grubx64.efi"
!define GRUB2_PREFIX_DI "debian-installer\amd64\grub"
!ifdef NOCD
!define SHIM_EFI_FILE "bootnetx64.efi"
!else
!define CD_EFI_FOLDER "EFI\boot"
!define SHIM_EFI_FILE "bootx64.efi"
!endif
!include StrFunc.nsh
!ifndef StrRep_INCLUDED
${StrRep}
!endif
; Create boot entry and add it to display list of boot manager
; Parameter:
; guid - global unique identifier of boot entry
; label - brief description of boot entry
Function AddBootEntry
System::Store 'S'
Pop $3
Pop $2
System::Call 'kernel32::QueryDosDevice(t "$c", t .r4, \
i${NSIS_MAX_STRLEN}) i.r0'
; guid=$2, label=$3, systempartition=$4
${If} $2 != ""
${AndIf} $0 != 0
${BOOTCFG_ConnectWMI} $R0 $R1 $0
${If} $0 == 0
${BOOTCFG_GetObject} $R1 "BcdStore" $R2 $0
${If} $0 == 0
${BOOTCFG_GetObject} $R1 "BcdObject" $R3 $0
${If} $0 == 0
${BOOTCFG_OpenDefaultBcdStore} $R1 $R2 $R4 $0
${If} $0 == 0
${BOOTCFG_CreateObject} $R1 $R2 $R4 \
${BOOTCFG_BOOT_SECTOR} $2 $5 $0
${If} $0 == 0
; Associate data with boot sector object
${BOOTCFG_SetDescription} $R1 $R3 $5 "$3" $1 $0
${If} $0 == 0
${BOOTCFG_SetPartition} $R1 $R3 $5 $4 $1 $0
${If} $0 == 0
StrLen $0 $c
StrCpy $0 "$INSTDIR" "" $0
; $0=Directory without drive letter
${BOOTCFG_SetPath} $R1 $R3 $5 "$0\g2ldr.mbr" $1 $0
${EndIf}
${EndIf}
; Release boot sector object and its associated data
${BOOTCFG_ReleaseObject} $5
${If} $0 == 0
; Append boot entry to list
${BOOTCFG_AppendBootEntry} $R1 $R2 \
$R4 $R3 $2 $1 $0
${If} $0 == 0
; Release result
${BOOTCFG_ReleaseObject} $1
${EndIf}
${EndIf}
${EndIf}
${BOOTCFG_ReleaseObject} $R4
${EndIf}
${BOOTCFG_ReleaseObject} $R3
${EndIf}
${BOOTCFG_ReleaseObject} $R2
${EndIf}
${BOOTCFG_ReleaseObject} $R1
${BOOTCFG_ReleaseObject} $R0
${EndIf}
${EndIf}
${If} $0 != 0
IntFmt $2 "0x%08X" $0
DetailPrint "$1: $2"
${EndIf}
System::Store 'L'
FunctionEnd
; Write GUID to the registry
; Parameter:
; guid - GUID of boot entry
Function WriteRegGUID
Exch $0
WriteRegStr HKLM "${REGSTR_WIN32}" "bootmgr" "$0"
Pop $0
FunctionEnd
Function CreateBootEntry
ReadRegStr $0 HKLM "${REGSTR_WIN32}" "bootmgr"
${If} $0 == ""
${BOOTCFG_CreateGUID} $2
${If} $2 != ""
Push "$2"
!ifdef PXE
${If} $pxe_mode == "true"
Push "$(pxe)"
${Else}
!endif ; PXE
Push "$(d-i)"
!ifdef PXE
${EndIf} ; $pxe_mode == "true"
!endif ; PXE
Call AddBootEntry
Push $2
Call WriteRegGUID
${Else}
MessageBox MB_OK|MB_ICONSTOP "$(error_bcdedit_extract_id)"
Quit
${EndIf}
${Endif}
FunctionEnd
; ********************************************** grub.cfg
; Generate grub.cfg file
; Return value:
; file handle of grub.cfg file
Function GenerateGrubConfig
Push $0
StrCpy $0 "$INSTDIR\${GRUB2_CFG_FILE}"
DetailPrint "$(generating)"
ClearErrors
FileOpen $0 "$0" w
${IfNot} ${Errors}
FileWrite $0 "set gfxpayload=auto$\n"
${Else}
DetailPrint "$(error) ${GRUB2_CFG_FILE}"
StrCpy $0 ""
${EndIf}
Exch $0
FunctionEnd
; Write grub.cfg file for Linux kernel
Function WriteGrubConfigLinux
Call GenerateGrubConfig
Exch $0
${If} $0 != ""
FileWrite $0 "\
linux $$prefix/linux $preseed_cmdline$\n\
initrd $$prefix/initrd.gz$\n\
boot$\n"
FileClose $0
${EndIf}
Pop $0
FunctionEnd
; Write grub.cfg file for kFreeBSD kernel
Function WriteGrubConfigkFreeBSD
Call GenerateGrubConfig
Exch $0
${If} $0 != ""
FileWrite $0 "\
kfreebsd $$prefix/kfreebsd.gz$\n\
kfreebsd_module $$prefix/initrd.gz type=mfs_root$\n\
set kFreeBSD.vfs.root.mountfrom=ufs:/dev/md0$\n\
set kFreeBSD.hw.ata.ata_dma=0 # needed for qemu hard disk # TODO: delete$\n\
set kFreeBSD.hw.ata.atapi_dma=0 # needed for qemu cd # TODO: 1$\n\
boot$\n"
FileClose $0
${EndIf}
Pop $0
FunctionEnd
; Write grub.cfg file for Hurd kernel
Function WriteGrubConfigHurd
Call GenerateGrubConfig
Exch $0
${If} $0 != ""
FileWrite $0 "\
multiboot $$prefix/gnumach.gz root=gunzip:device:rd0 $preseed_cmdline$\n\
module --nounzip $$prefix/initrd.gz initrd '$$(ramdisk-create)'$\n\
module $$prefix/ext2fs.static ext2fs \$\n\
--multiboot-command-line='$${kernel-command-line}' \$\n\
--host-priv-port='$${host-port}' \$\n\
--device-master-port='$${device-port}' \$\n\
--exec-server-task='$${exec-task}' -T typed '$${root}' \$\n\
'$$(task-create)' '$$(task-resume)'$\n\
module $$prefix/ld.so.1 exec /hurd/exec '$$(exec-task=task-create)'$\n\
boot$\n"
FileClose $0
${EndIf}
Pop $0
FunctionEnd
!ifdef PXE
Function WriteGrubConfigPXE
Call GenerateGrubConfig
Exch $0
${If} $0 != ""
FileWrite $0 "\
linux16 $$prefix/pxe.lkrn$\n\
boot$\n"
FileClose $0
${EndIf}
Pop $0
FunctionEnd
!endif ; PXE
; Adding the preseed file to the installer's initrd.gz
Function PreSeedLinux
System::Store 'S'
StrCpy $1 ${PRESEED_CFG}
StrCpy $2 "initrd.gz"
StrCpy $0 "$INSTDIR\$2"
DetailPrint "$(appending_preseeding)"
; IMPORTANT!! All accessed files must be in the same
; filesystem as the script itself, because cmd.exe/command.com gets
; confused when using absolute paths. This is why $INSTDIR is used
; instead of $PLUGINSDIR.
StrCpy $0 "$1"
${If} ${FileExists} $1
StrCpy $0 "$2"
ClearErrors
FileOpen $3 "$2" a
${IfNot} ${Errors}
FileSeek $3 0 END
${MINIZ_CPIO_GZ_Open} $3 $4
${If} $4 P<> 0
${MINIZ_CPIO_GZ_Write} $4 $1 $0
${If} $0 == 0
${MINIZ_CPIO_GZ_Write} $4 "" $0
${EndIf}
${MINIZ_CPIO_GZ_Close} $4 $4
${If} $0 != 0
${OrIf} $4 != 0
StrCpy $0 "$2"
${Else}
; Indicate success
StrCpy $0 ""
${EndIf}
${EndIf}
FileClose $3
${EndIf}
${EndIf}
${If} $0 != ""
MessageBox MB_OK|MB_ICONSTOP "$(^ErrorCreating)$0"
Quit
${EndIf}
System::Store 'L'
FunctionEnd
; ******************************************************************************
; ***************************************** THIS IS WHERE THE REAL ACTION STARTS
; ******************************************************************************
Section "Preparation" sec_prep
; We're about to write down our preseed line. This would be a nice place
; to add post-install parameters.
StrCpy $preseed_cmdline "$preseed_cmdline ---"
; ********************************************** preseed quietness
${If} $expert == false
StrCpy $preseed_cmdline "$preseed_cmdline quiet"
${Endif}
; Up to this point, we haven't modified host system. The first modification
; we want to do is preparing the Uninstaller (so that in case something went
; wrong, our half-install can be undone).
WriteUninstaller "$INSTDIR\Uninstall.exe"
WriteRegStr HKLM "${REGSTR_UNINST}" "DisplayName" $(program_name)
WriteRegStr HKLM "${REGSTR_UNINST}" "UninstallString" "$INSTDIR\Uninstall.exe"
; Add more branding (see branding.nsi)
WriteRegStr HKLM "${REGSTR_UNINST}" "Publisher" "${_COMPANY_NAME}"
WriteRegStr HKLM "${REGSTR_UNINST}" "DisplayIcon" "$INSTDIR\Uninstall.exe"
WriteRegStr HKLM "${REGSTR_UNINST}" "NoModify" "1"
WriteRegStr HKLM "${REGSTR_UNINST}" "NoRepair" "1"
WriteRegStr HKLM "${REGSTR_UNINST}" "DisplayVersion" "${VERSION_OPT}"
WriteRegStr HKLM "${REGSTR_UNINST}" "ProductID" "${4DIGITS_DATE}"
SectionEnd
!ifndef NOCD
!macro CopyFile SOURCE DEST
StrCpy $0 "$EXEDIR\${SOURCE}"
StrCpy $1 "$INSTDIR\${DEST}"
CopyFiles /FILESONLY "$0" "$1"
${If} ${Errors}
MessageBox MB_OK|MB_ICONSTOP "$(error_copyfiles)"
Quit
${EndIf}
!macroend
Function CopyGrub2Bootloader
Push $0
Push $1
ClearErrors
!insertmacro CopyFile "$g2ldr_mbr" g2ldr_mbr
StrCpy $0 "$EXEDIR\$g2ldr"
StrCpy $1 "$c\g2ldr"
CopyFiles /FILESONLY "$0" "$1"
${If} ${Errors}
MessageBox MB_OK|MB_ICONSTOP "$(error_copyfiles)"
Quit
${EndIf}
Pop $1
Pop $0
FunctionEnd
Section /o "Linux" sec_linux
ClearErrors
!insertmacro CopyFile "$linux" linux
!insertmacro CopyFile "$initrd" initrd.gz
Call WriteGrubConfig${__SECTION__}
Call PreSeed${__SECTION__}
SectionEnd
Section /o "kFreeBSD" sec_kfreebsd
ClearErrors
!insertmacro CopyFile "$kfreebsd" kfreebsd.gz
!insertmacro CopyFile "$kfreebsd_module" initrd.gz
Call WriteGrubConfig${__SECTION__}
SectionEnd
Section /o "Hurd" sec_hurd
ClearErrors
!insertmacro CopyFile "$gnumach" gnumach.gz
!insertmacro CopyFile "$ext2fs" ext2fs.static
!insertmacro CopyFile "$initrd" initrd.gz
!insertmacro CopyFile "$ld" ld.so.1
Call WriteGrubConfig${__SECTION__}
SectionEnd
Section /o "GRUB 2 EFI" sec_grub2_efi
${If} $arch == "amd64"
ClearErrors
!insertmacro CopyFile "${CD_EFI_FOLDER}\${GRUB2_EFI_FILE}" "${GRUB2_EFI_FILE}"
!insertmacro CopyFile "${CD_EFI_FOLDER}\${SHIM_EFI_FILE}" "${SHIM_EFI_FILE}"
${EndIf}
SectionEnd
Section /o "GRUB 2 boot loader for bootmgr" sec_g2ldr_bootmgr
Call CopyGrub2Bootloader
SectionEnd
Section /o "GRUB 2 boot loader for NTLDR" sec_g2ldr_ntldr
Call CopyGrub2Bootloader
SectionEnd
Section /o "Linux boot loader loadlin" sec_loadlin
File "${BUILD_DIR}/loadlin.exe"
File "${BUILD_DIR}/loadlin.pif"
SectionEnd
!else ;NOCD
Function ExtractGrub2Bootloader
File /oname=$c\g2ldr "${BUILD_DIR}/g2ldr"
File "${BUILD_DIR}/g2ldr.mbr"
FunctionEnd
Section "Download" sec_download
!ifdef PXE
${If} $pxe_mode != "true"
!endif
; Enable cancel button and make download controls visible
EnableWindow $mui.Button.Cancel 1
Push 1
Call Download_ShowControls
${If} $base_path_hashes != ""
; Remove trailing / from $base_url
StrCpy $1 "$base_url" -1
; Download the Release and Release.gpg files
Push "false"
Push "false"
Push "Release"
Push "$PLUGINSDIR"
Push "$1"
Call Download
Pop $0
Push "false"
Push "false"
Push "Release.gpg"
Push "$PLUGINSDIR"
Push "$1"
Call Download
Pop $0
EnableWindow $mui.Button.Cancel 0
; Now check gpg validity of this
File /oname=$PLUGINSDIR\gpgv.exe /usr/share/win32/gpgv.exe
File /oname=$PLUGINSDIR\debian-archive-keyring.gpg /usr/share/keyrings/debian-archive-keyring.gpg
File /oname=$PLUGINSDIR\debian-archive-removed-keys.gpg /usr/share/keyrings/debian-archive-removed-keys.gpg
StrCpy $0 "Release"
DetailPrint $(gpg_checking_release)
Push "$OUTDIR"
SetOutPath "$PLUGINSDIR"
nsExec::Exec 'gpgv.exe --keyring ".\debian-archive-removed-keys.gpg" --keyring ".\debian-archive-keyring.gpg" Release.gpg Release'
Pop $0
${If} $0 != 0
StrCpy $0 "Release"
MessageBox MB_OK|MB_ICONSTOP "$(unsecure_release)"
Quit
${EndIf}
Pop $0
SetOutPath "$0"
EnableWindow $mui.Button.Cancel 1
; Get SHA256SUMS file
Push "$PLUGINSDIR\Release"
Push "$base_path_hashesSHA256SUMS"
Call Get_SHA256_ref
; SHA-256 is on the stack.
${Else}
Push "false" ; Don't try to compare the SHA256SUM (daily images don't have that).
${EndIf}
; Download the SHA256SUMS file
; SHA-256 or "false" is on the stack
Push "false"
Push "SHA256SUMS"
Push "$PLUGINSDIR"
Push "$base_url$base_path_hashes"
Call Download
Pop $0
!ifdef PXE
${EndIf}
!endif
SectionEnd
!ifdef NETWORK_BASE_URL
; ********************************************** if ${NETWORK_BASE_URL} provides a preseed.cfg, use it
Section "Custom preseeding" sec_preseeding
Push ${NETWORK_BASE_URL_CHECKSUM}
Push true
Push "preseed.cfg"
Push "$PLUGINSDIR"
Push "${NETWORK_BASE_URL}"
Call Download
Pop $0
${If} $0 == "success"
StrCpy $preseed_cfg "$preseed_cfg$\n$\n"
ClearErrors
FileOpen $0 $PLUGINSDIR\preseed.cfg r
${Do}
FileRead $0 $1
${If} ${Errors}
${ExitDo}
${EndIf}
StrCpy $preseed_cfg "\
$preseed_cfg\
$1"
${Loop}
FileClose $0
StrCpy $preseed_cfg "$preseed_cfg$\n"
${Endif}
SectionEnd
!endif ; NETWORK_BASE_URL
Section /o "Linux" sec_linux
Push "$PLUGINSDIR\SHA256SUMS"
Push "$base_path_images/linux"
Call Get_SHA256_ref
; SHA256 is on stack
Push "false"
Push "linux"
Push "$INSTDIR"
Push "$base_url$base_path_hashes$base_path_images"
Call Download
Pop $0
Push "$PLUGINSDIR\SHA256SUMS"
Push "$base_path_images/initrd.gz"
Call Get_SHA256_ref
; SHA256 is on stack
Push "false"
Push "initrd.gz"
Push "$INSTDIR"
Push "$base_url$base_path_hashes$base_path_images"
Call Download
Pop $0
Call WriteGrubConfig${__SECTION__}
Call PreSeed${__SECTION__}
SectionEnd
Section /o "kFreeBSD" sec_kfreebsd
Push "$PLUGINSDIR\SHA256SUMS"
Push "$base_path_images/kfreebsd.gz"
Call Get_SHA256_ref
; SHA256 is on stack
Push "false"
Push "kfreebsd.gz"
Push "$INSTDIR"
Push "$base_url$base_path_hashes$base_path_images"
Call Download
Pop $0
Push "$PLUGINSDIR\SHA256SUMS"
Push "$base_path_images/initrd.gz"
Call Get_SHA256_ref
; SHA256 is on stack
Push "false"
Push "initrd.gz"
Push "$INSTDIR"
Push "$base_url$base_path_hashes$base_path_images"
Call Download
Pop $0
Call WriteGrubConfig${__SECTION__}
SectionEnd
Section /o "Hurd" sec_hurd
Push "$PLUGINSDIR\SHA256SUMS"
Push "$base_path_images/gnumach.gz"
Call Get_SHA256_ref
; SHA256 is on stack
Push "false"
Push "gnumach.gz"
Push "$INSTDIR"
Push "$base_url$base_path_hashes$base_path_images"
Call Download
Pop $0
Push "$PLUGINSDIR\SHA256SUMS"
Push "$base_path_images/ext2fs.static"
Call Get_SHA256_ref
; SHA256 is on stack
Push "false"
Push "ext2fs.static"
Push "$INSTDIR"
Push "$base_url$base_path_hashes$base_path_images"
Call Download
Pop $0
Push "$PLUGINSDIR\SHA256SUMS"
Push "$base_path_images/initrd.gz"
Call Get_SHA256_ref
; SHA256 is on stack
Push "false"
Push "initrd.gz"
Push "$INSTDIR"
Push "$base_url$base_path_hashes$base_path_images"
Call Download
Pop $0
Push "$PLUGINSDIR\SHA256SUMS"
Push "$base_path_images/ld.so.1"
Call Get_SHA256_ref
; SHA256 is on stack
Push "false"
Push "ld.so.1"
Push "$INSTDIR"
Push "$base_url$base_path_hashes$base_path_images"
Call Download
Pop $0
Call WriteGrubConfig${__SECTION__}
SectionEnd
!endif
!ifdef PXE
Section /o "PXE" sec_pxe
File /oname=$INSTDIR\pxe.lkrn "${BUILD_DIR}/pxe.lkrn"
Call WriteGrubConfig${__SECTION__}
SectionEnd
!endif
!ifdef NOCD
Section /o "GRUB 2 EFI" sec_grub2_efi
${If} $arch == "amd64"
; TODO: Remove work around
; Use signed grub efi file of testing instead of stable branch (buster)
;
; https://deb.debian.org/debian/dists/buster/main/installer-amd64/
; current/images/netboot/gtk/debian-installer/amd64/grubx64.efi
; sets the prefix to ($root)debian-installer/amd64/grub
; This prefix lacks the leading /.
;
; ---
StrCpy $0 $base_url
StrLen $1 $0
${If} $1 > 0
; Skip trailing /
IntOp $1 $1 - 1
${DoWhile} $1 > 0
IntOp $1 $1 - 1
StrCpy $2 $0 1 $1
${If} $2 == '/'
IntOp $1 $1 + 1
StrCpy $2 $0 -1 $1
StrCpy $1 $0 $1
${ExitDo}
${EndIf}
${Loop}
${EndIf}
Push "$PLUGINSDIR\SHA256SUMS"
Push "$base_path_images/${GRUB2_EFI_FILE}"
Call Get_SHA256_ref
Pop $0
${If} $2 == "stable"
${AndIf} $0 == "bef7969d0425f89417ab0dd90542a1bace4ebc592ec4ff2d8641795bc8d06001"
StrCpy $1 "$1testing/"
Push "false"
Push "false"
Push "${GRUB2_EFI_FILE}"
Push "$INSTDIR"
Push "$1$base_path_hashes$base_path_images"
Call Download
Pop $0
${Else}
Push $0 ; SHA256 fingerprint
Push "false"
Push "${GRUB2_EFI_FILE}"
Push "$INSTDIR"
Push "$base_url$base_path_hashes$base_path_images"
Call Download
Pop $0
${EndIf}
; ---
Push "$PLUGINSDIR\SHA256SUMS"
Push "$base_path_images/${SHIM_EFI_FILE}"
Call Get_SHA256_ref
; SHA256 is on stack
Push "false"
Push "${SHIM_EFI_FILE}"
Push "$INSTDIR"
Push "$base_url$base_path_hashes$base_path_images"
Call Download
Pop $0
${EndIf}
SectionEnd
Section /o "GRUB 2 boot loader for bootmgr" sec_g2ldr_bootmgr
Call ExtractGrub2Bootloader
SectionEnd
Section /o "GRUB 2 boot loader for NTLDR" sec_g2ldr_ntldr
Call ExtractGrub2Bootloader
SectionEnd
Section /o "Linux boot loader loadlin" sec_loadlin
File "${BUILD_DIR}/loadlin.exe"
File "${BUILD_DIR}/loadlin.pif"
SectionEnd
Section "Download completed" sec_download_done
; Hide download controls and disable cancel button
Push 0
Call Download_ShowControls
EnableWindow $mui.Button.Cancel 0
SectionEnd
!endif
; ********************************************** Do bootloader last, because it's the most dangerous
Section /o "Firmware Boot Manager" sec_fwbootmgr
System::Store 'S'
DetailPrint "${__SECTION__}"
!ifdef PXE
${If} $pxe_mode == "true"
DetailPrint "$(^Skipped)$(pxe)"
Return
${EndIf}
!endif
${BOOTCFG_ConnectWMI} $R0 $R1 $0
${If} $0 == 0
${BOOTCFG_GetObject} $R1 "BcdStore" $R2 $0
${If} $0 == 0
${BOOTCFG_GetObject} $R1 "BcdObject" $R3 $0
${If} $0 == 0
${BOOTCFG_OpenDefaultBcdStore} $R1 $R2 $R4 $0
${If} $0 == 0
${BOOTCFG_GetESPVolume} $R1 $R2 $R4 $R3 $1 $0
${If} $0 != 0
DetailPrint "Unable to identify ESP volume: $1 [$0]"
${Else}
DetailPrint "ESP volume: $1"
; Save ESP volume
Push $1
${BOOTCFG_GetVolumeUUID} "\\?\GLOBALROOT$1" $1 $0
${If} $0 == 0
; Terminating backslash is required for SetVolumeMountPoint
StrCpy $2 "$PLUGINSDIR_esp\"
ClearErrors
CreateDirectory $2
${If} ${Errors}
DetailPrint "Unable to create $2 directory"
StrCpy $0 ${ERROR_ACCESS_DENIED}
${Else}
; Terminating backslash is required for SetVolumeMountPoint
StrCpy $1 "\\?\Volume$1\"
DetailPrint "Volume Name: $1"
System::Call \
"kernel32::SetVolumeMountPoint(t r2, t r1) i.r0 ?e"
${If} $0 != 0
StrCpy $0 0
Exch $0
${EndIf}
Pop $0
${If} $0 == 0
Push $2
StrCpy $2 "$2${EFI_FOLDER}"
ClearErrors
CreateDirectory $2
${If} ${Errors}
DetailPrint \
"Unable to create ${EFI_FOLDER} directory"
StrCpy $0 ${ERROR_ACCESS_DENIED}
${Else}
CopyFiles /FILESONLY "$INSTDIR\${SHIM_EFI_FILE}" "$2\${EFI_LOADER}"
CopyFiles /FILESONLY "$INSTDIR\${GRUB2_EFI_FILE}" "$2\${GRUB2_EFI_FILE}"
${BOOTCFG_GetFileSystemUUID} "C:" $3
${If} $3 != ""
!ifdef NOCD
Pop $2
Push $2
StrCpy $2 "$2${GRUB2_PREFIX_DI}"
CreateDirectory $2
!endif
ClearErrors
FileOpen $4 "$2\${GRUB2_CFG_FILE}" w
${IfNot} ${Errors}
StrLen $0 $c
StrCpy $0 "$INSTDIR" "" $0
${StrRep} $0 "$0" "\" "/"
FileWrite $4 "\
search --set --fs-uuid $3$\n\
set prefix=($$root)$0$\n\
normal$\n"
FileClose $4
${EndIf}
${EndIf}
${EndIf}
Pop $2
System::Call "kernel32::DeleteVolumeMountPoint(t r2)"
${EndIf}
${EndIf}
${EndIf}
; Restore ESP volume
Pop $3
${BOOTCFG_CreateGUID} $2
DetailPrint "GUID=$2 Label=$(d-i) Volume=$3"
${BOOTCFG_CreateObject} $R1 $R2 $R4 \
${BOOTCFG_BOOT_MANAGER} $2 $5 $0
${If} $0 == 0
; Associate data with boot manager object
${BOOTCFG_SetDescription} $R1 $R3 $5 "$(d-i)" $1 $0
${If} $0 == 0
${BOOTCFG_SetPartition} $R1 $R3 $5 $3 $1 $0
${If} $0 == 0
${BOOTCFG_SetPath} $R1 $R3 $5 "\${EFI_FOLDER}\${EFI_LOADER}" $1 $0
${EndIf}
${EndIf}
; Release boot manager object and its associated data
${BOOTCFG_ReleaseObject} $5
${BOOTCFG_AppendFwBootEntry} $R1 $R2 $R4 $R3 $2 $1 $0
${If} $0 == 0
${BOOTCFG_ReleaseObject} $1
${Else}
DetailPrint "AppendFwBootEntry: $1 [$0]"
${EndIf}
${BOOTCFG_SetActiveFwBootEntry} $R1 $R2 $R4 $R3 $2 $1 $0
${If} $0 == 0
${BOOTCFG_ReleaseObject} $1
${Else}
DetailPrint "SetActiveFwBootEntry: $1 [$0]"
${EndIf}
${EndIf}
Push $2
Call WriteRegGUID
${BOOTCFG_ReleaseObject} $R4
${EndIf}
${BOOTCFG_ReleaseObject} $R3
${EndIf}
${BOOTCFG_ReleaseObject} $R2
${EndIf}
${BOOTCFG_ReleaseObject} $R1
${BOOTCFG_ReleaseObject} $R0
${EndIf}
${EndIf}
System::Store 'L'
SectionEnd
Section /o "Boot Manager" sec_bootmgr
DetailPrint "$(registering_bootmgr)"
Call CreateBootEntry
SectionEnd
Section /o "Windows NT Loader" sec_ntldr
DetailPrint "$(registering_ntldr)"
SetFileAttributes "$c\boot.ini" NORMAL
SetFileAttributes "$c\boot.ini" SYSTEM|HIDDEN
; Sometimes timeout isn't set. This may result in ntldr booting straight to
; Windows (bad) or straight to Debian-Installer (also bad)! Force it to 30
; just in case. Store its eventual old value alongside
; Read the already defined timeout
ReadIniStr $0 "$c\boot.ini" "boot loader" "timeout"
${If} ${Errors}
ClearErrors
WriteIniStr "$c\boot.ini" "boot loader" "old_timeout_win32-loader" $0
${EndIf}
WriteIniStr "$c\boot.ini" "boot loader" "timeout" "30"
!ifdef PXE
${If} $pxe_mode == "true"
StrCpy $1 "$(pxe)"
${Else}
!endif ; PXE
StrCpy $1 "$(d-i)"
!ifdef PXE
${EndIf} ; $pxe_mode == "true"
!endif ; PXE
System::Call "kernel32::WideCharToMultiByte(i 850, i 0, w r1, i -1, \
m.r2, i${NSIS_MAX_STRLEN}, p 0, p 0) i.r0"
WriteIniStr "$c\boot.ini" "operating systems" "$INSTDIR\g2ldr.mbr" '"$2"'
SectionEnd
Section /o "Direct via loadlin" sec_direct
SectionEnd
; Make preparations for installation
; Note:
; Function has to be placed below defintion of sections
; in order to select sections based on their identifiers.
Function Preparation
!ifdef PXE
${If} $pxe_mode != "true"
!endif
${If} $kernel != ""
${AndIf} $kernel > 0
Push $0
IntOp $0 $kernel - 1
IntOp $0 $0 + ${sec_linux}
SectionSetFlags $0 ${SF_SELECTED}
Pop $0
${Else}
SectionSetFlags ${sec_linux} ${SF_SELECTED}
${EndIf}
!ifdef PXE
${Else}
SectionSetFlags ${sec_pxe} ${SF_SELECTED}
${EndIf}
${If} $windows_boot_method != ""
${AndIf} $windows_boot_method > 0
Push $0
Push $1
; Select section to copy respectively download
; required files for booting
IntOp $0 $windows_boot_method - 1
IntOp $1 $0 + ${sec_grub2_efi}
SectionSetFlags $1 ${SF_SELECTED}
; Select section to configure boot loader
IntOp $1 $0 + ${sec_fwbootmgr}
SectionSetFlags $1 ${SF_SELECTED}
Pop $1
Pop $0
${EndIf}
!endif
FunctionEnd
|