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
|
import Gio from "gi://Gio";
import { ExecCommand, Log, LogWarning } from './utils.js';
/**
* Represents efibootmgr
*/
export class EFIBootManager {
/**
* Get's all available boot options
* @returns {[Map, string]} Map(title, id), defaultOption
*/
static async GetBootOptions() {
const [status, stdout, stderr] = await ExecCommand(['efibootmgr'],);
const lines = stdout.split("\n");
let boot_first = "0000";
const boot_options = new Map();
for (let l = 0; l < lines.length; l++) {
const line = lines[l];
if (line.startsWith("BootOrder:")) {
boot_first = line.split(" ")[1].split(",")[0];
continue;
}
const regex = /(Boot[0-9]{4})/;
const vLine = regex.exec(line)
if (vLine && vLine.length) {
const option = line.replace("Boot", "").split("*");
const title = option[1];
if (title.includes("HD") || title.includes("RC")) {
const trimed_title = title.replace(/(?<=[\S\s]*)(HD|RC)([\s\S()]*|$)/, "").trim();
boot_options.set(trimed_title, option[0].trim());
}
else {
boot_options.set(option[1].trim(), option[0].trim());
}
}
}
return [boot_options, boot_first];
}
/**
* Set's the next boot option
* @param {string} id
* @returns True if the boot option was set, otherwise false
*/
static async SetBootOption(id) {
if (!this.IsUseable()) return false;
const [status, stdout, stderr] = await ExecCommand(['/usr/bin/pkexec', 'efibootmgr', '-n', id],);
if (status === 0) {
Log(`Set boot option to ${id}`);
return true;
}
LogWarning("Unable to set boot option using efibootmgr");
return false;
}
/**
* Can we use this bootloader?
* @returns True if useable otherwise false
*/
static async IsUseable() {
return await this.GetBinary() !== "";
}
/**
* Get's efibootmgr binary path
* @returns A string containing the location of the binary, if none is found returns a blank string
*/
static async GetBinary() {
let paths = ["/usr/bin/efibootmgr", "/usr/sbin/efibootmgr"];
let file;
for (let i = 0; i < paths.length; i++) {
file = Gio.file_new_for_path(paths[i]);
if (file.query_exists(null)) {
return paths[i];
}
}
return "";
}
/**
* This boot loader cannot be quick rebooted
*/
static async CanQuickReboot() {
return false;
}
/**
* This boot loader cannot be quick rebooted
*/
static async QuickRebootEnabled() {
return false;
}
}
|