Skip to content
API Documentation
BastionGuard™
BootOptionsBox.vala
Go to the documentation of this file.
1/*
2 * BootOptionsBox.vala
3 */
4
5using Gtk;
6using Gee;
7
13using TeeJee.System;
14using TeeJee.Misc;
15
16class BootOptionsBox : Gtk.Box{
17
18 private Gtk.Box option_box;
19 private Gtk.ComboBoxText cmb_grub_dev;
20 private Gee.ArrayList<Device?> grub_devices = new Gee.ArrayList<Device?>();
21
22 private Gtk.CheckButton chk_reinstall_grub;
23 private Gtk.CheckButton chk_update_initramfs;
24 private Gtk.CheckButton chk_update_grub;
25 private Gtk.Window parent_window;
26
27 public BootOptionsBox (Gtk.Window _parent_window) {
28
29 log_debug("BootOptionsBox: BootOptionsBox()");
30
31 GLib.Object(orientation: Gtk.Orientation.VERTICAL, spacing: 6);
32 parent_window = _parent_window;
33 margin_top = 12;
34 margin_bottom = 12;
35 margin_start = 12;
36 margin_end = 12;
37
38 option_box = new Gtk.Box(Gtk.Orientation.VERTICAL, 6);
39 append(option_box);
40
43
44 log_debug("BootOptionsBox: BootOptionsBox(): exit");
45 }
46
47 private void add_bootloader_options(){
49
50 var hbox = new Gtk.Box(Orientation.HORIZONTAL, 6);
51 hbox.margin_start = 12;
52 append (hbox);
53
54 cmb_grub_dev = new Gtk.ComboBoxText();
55 cmb_grub_dev.hexpand = true;
56 hbox.append(cmb_grub_dev);
57
58 cmb_grub_dev.changed.connect(()=>{
60 });
61
62 hbox = new Gtk.Box(Orientation.HORIZONTAL, 6);
63 append (hbox);
66 }
67
68 private void add_chk_reinstall_grub(){
69 var chk = new CheckButton.with_label(_("(Re)install GRUB2 on:"));
70 chk.active = false;
71 chk.set_tooltip_markup(_("Re-installs the GRUB2 bootloader on the selected device."));
72 append (chk);
74
75 chk.toggled.connect(()=>{
76 cmb_grub_dev.sensitive = chk_reinstall_grub.active;
77 App.reinstall_grub2 = chk_reinstall_grub.active;
79 });
80 }
81
82 private void add_chk_update_initramfs(Gtk.Box hbox){
83 var chk = new CheckButton.with_label(_("Update initramfs"));
84 chk.active = false;
85 chk.set_tooltip_markup(_("Re-generates initramfs for all installed kernels. This is generally not needed. Select this only if the restored system fails to boot."));
86 hbox.append (chk);
88
89 chk.toggled.connect(()=>{
90 App.update_initramfs = chk_update_initramfs.active;
91 });
92 }
93
94 private void add_chk_update_grub(Gtk.Box hbox){
95 var chk = new CheckButton.with_label(_("Update GRUB menu"));
96 chk.active = false;
97 chk.set_tooltip_markup(_("Updates the GRUB menu entries (recommended). This is safe to run and should be left selected."));
98 hbox.append (chk);
99 chk_update_grub = chk;
100
101 chk.toggled.connect(()=>{
102 App.update_grub = chk_update_grub.active;
103 });
104 }
105
107 App.grub_device = "";
108 if (!App.reinstall_grub2){
109 return;
110 }
111
112 int index = cmb_grub_dev.get_active();
113 if ((index < 0) || (index >= grub_devices.size)){
114 return;
115 }
116
117 Device? entry = grub_devices[index];
118 if (entry != null){
119 App.grub_device = entry.device;
120 }
121 }
122
123 private void refresh_options(){
125
126 chk_reinstall_grub.active = App.reinstall_grub2;
127 cmb_grub_dev.sensitive = chk_reinstall_grub.active;
128 chk_update_initramfs.active = App.update_initramfs;
129 chk_update_grub.active = App.update_grub;
130
131 chk_reinstall_grub.sensitive = true;
132 chk_update_initramfs.sensitive = true;
133 chk_update_grub.sensitive = true;
134
135 if (App.mirror_system){
136 chk_reinstall_grub.sensitive = false;
137 chk_update_initramfs.sensitive = false;
138 chk_update_grub.sensitive = false;
139 }
140 else if (App.snapshot_to_restore.distro.dist_id == "fedora"){
141 chk_reinstall_grub.sensitive = false;
142 }
143 }
144
145 private void refresh_cmb_grub_dev(){
146 grub_devices.clear();
147 cmb_grub_dev.remove_all();
148
150 if ((dev.type != "disk") && (dev.type != "part")){
151 continue;
152 }
153 if ((dev.fstype == "luks")||(dev.fstype == "lvm2")){
154 continue;
155 }
156 if (dev.size_bytes < 10 * KB){
157 continue;
158 }
159
160 grub_devices.add(dev);
161 string text = (dev.type == "disk")
162 ? _("%s (MBR)").printf(dev.description())
163 : dev.description();
164 cmb_grub_dev.append_text(text);
165 }
166
168 }
169
171 if (cmb_grub_dev == null){
172 return;
173 }
174
175 log_debug("BootOptionsBox: cmb_grub_dev_select_default()");
176
177 if (App.grub_device.length == 0){
178 cmb_grub_dev.active = -1;
179 return;
180 }
181
182 int active = -1;
183 for (int i = 0; i < grub_devices.size; i++){
184 Device? dev_iter = grub_devices[i];
185 if ((dev_iter != null) && (dev_iter.device == App.grub_device)){
186 active = i;
187 break;
188 }
189 }
190
191 cmb_grub_dev.active = active;
192 log_debug("BootOptionsBox: cmb_grub_dev_select_default(): exit");
193 }
194}
Main App
#define _(s)
void add_chk_update_initramfs(Gtk.Box hbox)
Gtk.CheckButton chk_update_initramfs
Gtk.CheckButton chk_update_grub
Gtk.ComboBoxText cmb_grub_dev
Gee.ArrayList< Device?> grub_devices
void add_chk_update_grub(Gtk.Box hbox)
BootOptionsBox(Gtk.Window _parent_window)
void add_bootloader_options()
void save_grub_device_selection()
void cmb_grub_dev_select_default()
Gtk.Window parent_window
Gtk.CheckButton chk_reinstall_grub
void add_chk_reinstall_grub()
string type
Definition Device.vala:64
uint64 size_bytes
Definition Device.vala:77
string description()
Definition Device.vala:1825
static Gee.ArrayList< Device > get_block_devices_using_lsblk(string dev_name="")
Definition Device.vala:420
string fstype
Definition Device.vala:65
string device
Definition Device.vala:44
string size
Definition Device.vala:126
bool update_initramfs
Definition Main.vala:139
Snapshot snapshot_to_restore
Definition Main.vala:136
bool update_grub
Definition Main.vala:140
bool mirror_system
Definition Main.vala:85
bool reinstall_grub2
Definition Main.vala:138
string grub_device
Definition Main.vala:141
LinuxDistro distro
Definition Snapshot.vala:52
void log_debug(string message)