mirror of
https://github.com/Metabolix/HackBGRT.git
synced 2025-12-06 17:15:42 -08:00
Properly handle skip-shim with enable-overwrite
This commit is contained in:
33
src/Setup.cs
33
src/Setup.cs
@@ -523,11 +523,22 @@ public class Setup {
|
|||||||
WriteLine("Disabled NVRAM entry for HackBGRT.");
|
WriteLine("Disabled NVRAM entry for HackBGRT.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get paths related to MS boot loader.
|
||||||
|
*/
|
||||||
|
protected (string Ms, string MsDir, string MsGrub, string MsMokManager) GetMsLoaderPaths() {
|
||||||
|
var ms = Esp.MsLoaderPath;
|
||||||
|
var msDir = Path.GetDirectoryName(ms);
|
||||||
|
var msGrub = Path.Combine(msDir, $"grub{EfiArch}.efi");
|
||||||
|
var msMm = Path.Combine(msDir, $"mm{EfiArch}.efi");
|
||||||
|
return (ms, msDir, msGrub, msMm);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enable HackBGRT by overwriting the MS boot loader.
|
* Enable HackBGRT by overwriting the MS boot loader.
|
||||||
*/
|
*/
|
||||||
protected void OverwriteMsLoader() {
|
protected void OverwriteMsLoader() {
|
||||||
var ms = Esp.MsLoaderPath;
|
var (ms, msDir, msGrub, msMm) = GetMsLoaderPaths();
|
||||||
var backup = BackupLoaderPath;
|
var backup = BackupLoaderPath;
|
||||||
|
|
||||||
if (DetectLoader(ms) == BootLoaderType.Microsoft) {
|
if (DetectLoader(ms) == BootLoaderType.Microsoft) {
|
||||||
@@ -537,13 +548,16 @@ public class Setup {
|
|||||||
// Duplicate check, but better to be sure...
|
// Duplicate check, but better to be sure...
|
||||||
throw new SetupException("Missing MS boot loader backup!");
|
throw new SetupException("Missing MS boot loader backup!");
|
||||||
}
|
}
|
||||||
var msDir = Path.GetDirectoryName(ms);
|
var loader = Path.Combine(InstallPath, "loader.efi");
|
||||||
var msGrub = Path.Combine(msDir, $"grub{EfiArch}.efi");
|
if (SkipShim == (DetectLoader(loader) == BootLoaderType.Shim)) {
|
||||||
var msMm = Path.Combine(msDir, $"mm{EfiArch}.efi");
|
throw new SetupException("Bad skip-shim usage. Install and enable with consistent options.");
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
InstallFile(Path.Combine(InstallPath, "loader.efi"), ms, false);
|
InstallFile(loader, ms, false);
|
||||||
InstallFile(Path.Combine(InstallPath, $"grub{EfiArch}.efi"), msGrub, false);
|
if (!SkipShim) {
|
||||||
InstallFile(Path.Combine(InstallPath, $"mm{EfiArch}.efi"), msMm, false);
|
InstallFile(Path.Combine(InstallPath, $"grub{EfiArch}.efi"), msGrub, false);
|
||||||
|
InstallFile(Path.Combine(InstallPath, $"mm{EfiArch}.efi"), msMm, false);
|
||||||
|
}
|
||||||
} catch (SetupException e) {
|
} catch (SetupException e) {
|
||||||
WriteLine(e.Message);
|
WriteLine(e.Message);
|
||||||
if (DetectLoader(ms) != BootLoaderType.Microsoft) {
|
if (DetectLoader(ms) != BootLoaderType.Microsoft) {
|
||||||
@@ -554,6 +568,7 @@ public class Setup {
|
|||||||
throw new SetupException("Rollback failed, your system may be unbootable! Create a rescue disk IMMEADIATELY!");
|
throw new SetupException("Rollback failed, your system may be unbootable! Create a rescue disk IMMEADIATELY!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -561,11 +576,13 @@ public class Setup {
|
|||||||
* Restore the MS boot loader if it was previously replaced.
|
* Restore the MS boot loader if it was previously replaced.
|
||||||
*/
|
*/
|
||||||
protected void RestoreMsLoader() {
|
protected void RestoreMsLoader() {
|
||||||
var ms = Esp.MsLoaderPath;
|
var (ms, msDir, msGrub, msMm) = GetMsLoaderPaths();
|
||||||
if (DetectLoader(ms) == BootLoaderType.Own || DetectLoader(ms) == BootLoaderType.Shim) {
|
if (DetectLoader(ms) == BootLoaderType.Own || DetectLoader(ms) == BootLoaderType.Shim) {
|
||||||
WriteLine("Disabling an old version of HackBGRT.");
|
WriteLine("Disabling an old version of HackBGRT.");
|
||||||
InstallFile(BackupLoaderPath, ms, false);
|
InstallFile(BackupLoaderPath, ms, false);
|
||||||
WriteLine($"{ms} has been restored.");
|
WriteLine($"{ms} has been restored.");
|
||||||
|
File.Delete(msGrub);
|
||||||
|
File.Delete(msMm);
|
||||||
}
|
}
|
||||||
if (DetectLoader(BackupLoaderPath) == BootLoaderType.Own) {
|
if (DetectLoader(BackupLoaderPath) == BootLoaderType.Own) {
|
||||||
File.Delete(BackupLoaderPath);
|
File.Delete(BackupLoaderPath);
|
||||||
|
|||||||
Reference in New Issue
Block a user