From 2829c6cbd308924edca493ead8c49521b0d2ca6a Mon Sep 17 00:00:00 2001 From: Mike Slattery Date: Fri, 7 Feb 2020 19:18:29 -0500 Subject: [PATCH] #2 * Grub: always overwrite --- files/grub.cfg | 4 +-- tunic.ps1 | 67 +++++++++++++++++++++++++------------------------- 2 files changed, 36 insertions(+), 35 deletions(-) diff --git a/files/grub.cfg b/files/grub.cfg index 6f84fbd..c4687e2 100644 --- a/files/grub.cfg +++ b/files/grub.cfg @@ -14,7 +14,7 @@ insmod part_gpt insmod ntfs menuentry "Tunic Automatic Linux Installer" { - echo "Loopback: ${iso_path}" + echo "ISO: ${iso_path}" search --set=root --file $iso_path loopback loop ($root)$iso_path @@ -32,7 +32,7 @@ menuentry "Tunic Automatic Linux Installer" { } menuentry "Try out Linux without install" { - echo "Loopback: ${iso_path}" + echo "ISO: ${iso_path}" search --set=root --file $iso_path loopback loop ($root)$iso_path diff --git a/tunic.ps1 b/tunic.ps1 index a6f7404..5c1e6c0 100644 --- a/tunic.ps1 +++ b/tunic.ps1 @@ -348,6 +348,16 @@ function expandTemplate($filename) { } function installGrub() { + # Install 7z, if needed + + $7z = '7z.exe' + if( (get-command "7z" -errorAction silentlyContinue).count -eq 0 ) { + (New-Object System.Net.WebClient).DownloadFile('https://www.7-zip.org/a/7z1900.exe', "$env:TEMP\7zi.exe") + start-process "$env:TEMP\7zi.exe" /S -wait + remove-item -path "$env:TEMP\7zi.exe" -errorAction silentlyContinue + $7z = 'C:\Program Files (x86)\7-Zip\7z.exe' + } + # TODO: allocate drive letter. try..finally #$efi = (ls function:[d-z]: -n | ?{ !(test-path $_) } | random) $efi = "S:" @@ -363,38 +373,29 @@ function installGrub() { $grub_dir="\boot\grub" $grub_path="${efi}${grub_dir}" - if ( -not (Test-Path "$grub_path\grub.var.cfg") ) { - $iso_path = getUrlFilepath($global:data.iso_url) - $iso_grub_path = getGrubPath($iso_path) - - # Install 7z, if needed - $7z = '7z.exe' - if( (get-command "7z" -errorAction silentlyContinue).count -eq 0 ) { - (New-Object System.Net.WebClient).DownloadFile('https://www.7-zip.org/a/7z1900.exe', "$env:TEMP\7zi.exe") - start-process "$env:TEMP\7zi.exe" /S -wait - remove-item -path "$env:TEMP\7zi.exe" -errorAction silentlyContinue - $7z = 'C:\Program Files (x86)\7-Zip\7z.exe' - } - - # Extract grub files - mkdir "$grub_path" -force | out-null - & "$7z" x -r "$iso_path" boot\grub "-o$efi\" -y -bb0 > $null - # grubx64.efi - (New-Object System.Net.WebClient).DownloadFile($global:grubx64_url, "$env:TEMP\signed.deb") - & "$7z" e -y "$env:TEMP\signed.deb" "-o${env:TEMP}" > $null - & "$7z" e -y "$env:TEMP\data.tar" .\usr\lib\grub\x86_64-efi-signed\gcdx64.efi.signed "-o${env:TEMP}" > $null - move "${env:TEMP}\gcdx64.efi.signed" "${efi}\EFI\BOOT\grubx64.efi" -force - rm "${env:TEMP}\signed.deb" - rm "${env:TEMP}\data.tar" - # shim64.efi - if( $secureBootEnabled ) { - (New-Object System.Net.WebClient).DownloadFile($shim_url, "${efi}\EFI\BOOT\shimx64.efi") - } - # config - move "$grub_path\grub.cfg" "$grub_path\grub.orig.cfg" -errorAction silentlyContinue - copy "files\grub.cfg" "$grub_path\." - set-content -path "$grub_path\grub.var.cfg" -value "set iso_path='$iso_grub_path'" + $iso_path = getUrlFilepath($global:data.iso_url) + $iso_grub_path = getGrubPath($iso_path) + + # Extract grub files + + mkdir "${efi}\EFI\BOOT" -force | out-null + mkdir "$grub_path" -force | out-null + & "$7z" x -r "$iso_path" boot\grub "-o$efi\" -y -bb0 > $null + # grubx64.efi + (New-Object System.Net.WebClient).DownloadFile($global:grubx64_url, "$env:TEMP\signed.deb") + & "$7z" e -y "$env:TEMP\signed.deb" "-o${env:TEMP}" > $null + & "$7z" e -y "$env:TEMP\data.tar" .\usr\lib\grub\x86_64-efi-signed\gcdx64.efi.signed "-o${env:TEMP}" > $null + move "${env:TEMP}\gcdx64.efi.signed" "${efi}\EFI\BOOT\grubx64.efi" -force + rm "${env:TEMP}\signed.deb" + rm "${env:TEMP}\data.tar" + # shim64.efi + if( $secureBootEnabled ) { + (New-Object System.Net.WebClient).DownloadFile($shim_url, "${efi}\EFI\BOOT\shimx64.efi") } + # config + move "$grub_path\grub.cfg" "$grub_path\grub.orig.cfg" -errorAction silentlyContinue + copy "files\grub.cfg" "$grub_path\." + set-content -path "$grub_path\grub.var.cfg" -value "set iso_path='$iso_grub_path'" if ( -not (Test-Path "${global:tunic_dir}\bcd-before.bak" ) ) { bcdedit /export "${global:tunic_dir}\bcd-before.bak" | out-null @@ -404,7 +405,7 @@ function installGrub() { #TODO: idempotent if( test-path("${global:tunic_dir}\bcd.id") ) { $osloader = (get-content "${global:tunic_dir}\bcd.id") - bcdedit /delete "$osloader" /f | out-null + bcdedit /delete "$osloader" /cleanup /f | out-null } $osloader = (bcdedit /copy '{bootmgr}' /d ubuntu).replace('The entry was successfully copied to ','').replace('.','') bcdedit /set "$osloader" device "partition=$efi" | out-null @@ -1130,8 +1131,8 @@ function fullDisk() { $global:data.password = 'tunic' # copied from distros.ps1 $url = 'http://releases.ubuntu.com/18.04.3/ubuntu-18.04.3-desktop-amd64.iso' - $url = 'http://releases.ubuntu.com/19.10/ubuntu-19.10-desktop-amd64.iso' $url = 'http://mirrors.gigenet.com/linuxmint/iso/stable/19.3/linuxmint-19.3-xfce-64bit.iso' + $url = 'http://releases.ubuntu.com/19.10/ubuntu-19.10-desktop-amd64.iso' $global:data.iso_url = $url if( $global:data.installType -eq $DUALBOOT ) {