Skip to content

Commit

Permalink
#2 * Grub: always overwrite
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeslattery committed Feb 8, 2020
1 parent e9fa812 commit 2829c6c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 35 deletions.
4 changes: 2 additions & 2 deletions files/grub.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
67 changes: 34 additions & 33 deletions tunic.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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:"
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 ) {
Expand Down

0 comments on commit 2829c6c

Please sign in to comment.