mirror of
https://github.com/Metabolix/HackBGRT.git
synced 2026-09-12 07:06:06 -07:00
Detect issues with boot= option
This commit is contained in:
@@ -33,6 +33,7 @@ When booting on a UEFI-based computer, Windows may show a vendor-defined logo wh
|
|||||||
* `enable-overwrite` – overwrite the MS boot loader.
|
* `enable-overwrite` – overwrite the MS boot loader.
|
||||||
* `disable-overwrite` – restore the MS boot loader.
|
* `disable-overwrite` – restore the MS boot loader.
|
||||||
* `allow-secure-boot` – ignore Secure Boot in subsequent commands.
|
* `allow-secure-boot` – ignore Secure Boot in subsequent commands.
|
||||||
|
* `allow-bad-loader` – ignore bad boot loader configuration in subsequent commands.
|
||||||
* `disable` – run all relevant `disable-*` commands.
|
* `disable` – run all relevant `disable-*` commands.
|
||||||
* `uninstall` – disable and remove completely.
|
* `uninstall` – disable and remove completely.
|
||||||
* For example, run `setup.exe batch install allow-secure-boot enable-overwrite` to copy files and overwrite the MS boot loader regardless of Secure Boot status.
|
* For example, run `setup.exe batch install allow-secure-boot enable-overwrite` to copy files and overwrite the MS boot loader regardless of Secure Boot status.
|
||||||
|
|||||||
+57
-1
@@ -54,6 +54,7 @@ public class Setup {
|
|||||||
protected static readonly string[] privilegedActions = new string[] {
|
protected static readonly string[] privilegedActions = new string[] {
|
||||||
"install",
|
"install",
|
||||||
"allow-secure-boot",
|
"allow-secure-boot",
|
||||||
|
"allow-bad-loader",
|
||||||
"enable-entry", "disable-entry",
|
"enable-entry", "disable-entry",
|
||||||
"enable-overwrite", "disable-overwrite",
|
"enable-overwrite", "disable-overwrite",
|
||||||
"disable",
|
"disable",
|
||||||
@@ -381,6 +382,43 @@ public class Setup {
|
|||||||
InstallFile(BackupLoaderPath, ms, false);
|
InstallFile(BackupLoaderPath, ms, false);
|
||||||
WriteLine($"{ms} has been restored.");
|
WriteLine($"{ms} has been restored.");
|
||||||
}
|
}
|
||||||
|
if (DetectLoader(BackupLoaderPath) == BootLoaderType.Own) {
|
||||||
|
File.Delete(BackupLoaderPath);
|
||||||
|
WriteLine($"{BackupLoaderPath} was messed up and has been removed.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check that config.txt has a reasonable boot loader line.
|
||||||
|
*/
|
||||||
|
protected void VerifyLoaderConfig() {
|
||||||
|
var lines = File.ReadAllLines("config.txt");
|
||||||
|
var loader = lines.Where(s => s.StartsWith("boot=")).Select(s => s.Substring(5)).Prepend("").Last();
|
||||||
|
if (loader == null) {
|
||||||
|
throw new SetupException("config.txt does not contain a boot=... line!");
|
||||||
|
}
|
||||||
|
WriteLine($"Verifying config: boot={loader}");
|
||||||
|
if (loader == "MS") {
|
||||||
|
var backup = BackupLoaderPath;
|
||||||
|
var type = DetectLoader(backup);
|
||||||
|
if (type == BootLoaderType.Own) {
|
||||||
|
throw new SetupException($"boot=MS = {backup} = HackBGRT. Prepare your rescue disk!");
|
||||||
|
}
|
||||||
|
if (type == BootLoaderType.None) {
|
||||||
|
if (DetectLoader(Esp.MsLoaderPath) != BootLoaderType.Microsoft) {
|
||||||
|
throw new SetupException("config.txt contains boot=MS, but MS boot loader is not found!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (!loader.StartsWith("\\")) {
|
||||||
|
throw new SetupException($"Boot loader must be boot=MS or boot=\\valid\\path!");
|
||||||
|
} else {
|
||||||
|
switch (DetectLoader(Path.Combine(Esp.Location, loader.Substring(1).Replace("\\", Path.DirectorySeparatorChar.ToString())))) {
|
||||||
|
case BootLoaderType.Own:
|
||||||
|
throw new SetupException($"Boot loader points back to HackBGRT!");
|
||||||
|
case BootLoaderType.None:
|
||||||
|
throw new SetupException($"Boot loader does not exist!");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -594,21 +632,39 @@ public class Setup {
|
|||||||
|
|
||||||
InitEspPath();
|
InitEspPath();
|
||||||
InitEspInfo();
|
InitEspInfo();
|
||||||
bool allowSecureBoot = false;
|
bool allowSecureBoot = false, allowBadLoader = false;
|
||||||
|
Action<Action> verify = (Action revert) => {
|
||||||
|
try {
|
||||||
|
VerifyLoaderConfig();
|
||||||
|
} catch (SetupException e) {
|
||||||
|
if (allowBadLoader) {
|
||||||
|
WriteLine($"Warning: {e.Message}");
|
||||||
|
} else {
|
||||||
|
WriteLine($"Error: {e.Message}");
|
||||||
|
WriteLine($"Reverting. Use batch mode with allow-bad-loader to override.");
|
||||||
|
revert();
|
||||||
|
throw new SetupException("Check your configuration and try again.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
foreach (var arg in actions) {
|
foreach (var arg in actions) {
|
||||||
Log($"Running action '{arg}'.");
|
Log($"Running action '{arg}'.");
|
||||||
if (arg == "install") {
|
if (arg == "install") {
|
||||||
InstallFiles();
|
InstallFiles();
|
||||||
} else if (arg == "allow-secure-boot") {
|
} else if (arg == "allow-secure-boot") {
|
||||||
allowSecureBoot = true;
|
allowSecureBoot = true;
|
||||||
|
} else if (arg == "allow-bad-loader") {
|
||||||
|
allowBadLoader = true;
|
||||||
} else if (arg == "enable-entry") {
|
} else if (arg == "enable-entry") {
|
||||||
HandleSecureBoot(allowSecureBoot);
|
HandleSecureBoot(allowSecureBoot);
|
||||||
EnableEntry();
|
EnableEntry();
|
||||||
|
verify(() => DisableEntry());
|
||||||
} else if (arg == "disable-entry") {
|
} else if (arg == "disable-entry") {
|
||||||
DisableEntry();
|
DisableEntry();
|
||||||
} else if (arg == "enable-overwrite") {
|
} else if (arg == "enable-overwrite") {
|
||||||
HandleSecureBoot(allowSecureBoot);
|
HandleSecureBoot(allowSecureBoot);
|
||||||
OverwriteMsLoader();
|
OverwriteMsLoader();
|
||||||
|
verify(() => RestoreMsLoader());
|
||||||
} else if (arg == "disable-overwrite") {
|
} else if (arg == "disable-overwrite") {
|
||||||
RestoreMsLoader();
|
RestoreMsLoader();
|
||||||
} else if (arg == "disable") {
|
} else if (arg == "disable") {
|
||||||
|
|||||||
Reference in New Issue
Block a user