summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Whitaker <mageia@martin-whitaker.me.uk>2022-08-08 19:11:51 +0100
committerMartin Whitaker <mageia@martin-whitaker.me.uk>2022-08-08 19:11:51 +0100
commit2b7a152fd09cf684597da4ae0c6193a1adb4c5b0 (patch)
treed873756a3b013663af71d7e7255246bcf649d917
parentf7b10cc052f7ed068cce865c8725c31b1b24ef59 (diff)
downloaddrakx-2b7a152fd09cf684597da4ae0c6193a1adb4c5b0.tar
drakx-2b7a152fd09cf684597da4ae0c6193a1adb4c5b0.tar.gz
drakx-2b7a152fd09cf684597da4ae0c6193a1adb4c5b0.tar.bz2
drakx-2b7a152fd09cf684597da4ae0c6193a1adb4c5b0.tar.xz
drakx-2b7a152fd09cf684597da4ae0c6193a1adb4c5b0.zip
bootloader: rework reading/writing of main rEFInd config file.
At the moment we only use and modify one setting, but the next commit will change that.
-rw-r--r--perl-install/bootloader.pm69
1 files changed, 54 insertions, 15 deletions
diff --git a/perl-install/bootloader.pm b/perl-install/bootloader.pm
index 4a0e1a4bc..e43b51215 100644
--- a/perl-install/bootloader.pm
+++ b/perl-install/bootloader.pm
@@ -705,17 +705,30 @@ sub read_refind() {
}
}
$bootloader{method} = 'refind';
- #- Try both possible locations for the main config file. The default is to use NVRAM if the
- #- config file isn't found.
- $bootloader{use_nvram} = get_refind_use_nvram("$::prefix/boot/EFI/EFI/refind/refind.conf")
- && get_refind_use_nvram("$::prefix/boot/EFI/EFI/BOOT/refind.conf");
+ read_refind_config(\%bootloader);
\%bootloader;
}
-sub get_refind_use_nvram {
- my ($path) = @_;
- #- The default is to use NVRAM, so test if it is explicitly disabled.
- -r $path && (grep { /^\s*use_nvram\s+(false|off|0)/ } cat_utf8($path)) ? 0 : 1;
+sub read_refind_config {
+ my ($bootloader) = @_;
+
+ #- These are the rEFInd default values.
+ $bootloader->{use_nvram} = 1;
+
+ if (-r "$::prefix/boot/EFI/EFI/refind/refind.conf") {
+ read_refind_conf($bootloader, "$::prefix/boot/EFI/EFI/refind/refind.conf");
+ } elsif (-r "$::prefix/boot/EFI/EFI/BOOT/refind.conf") {
+ read_refind_conf($bootloader, "$::prefix/boot/EFI/EFI/BOOT/refind.conf");
+ }
+}
+
+sub read_refind_conf {
+ my ($bootloader, $config_file) = @_;
+ foreach (cat_utf8($config_file)) {
+ if ($_ =~ /^\s*use_nvram\s+(false|off|0)/) {
+ $bootloader->{use_nvram} = 0;
+ }
+ }
}
# FIXME: actually read back previous conf
@@ -2498,17 +2511,43 @@ sub install_refind {
run_program::rooted($::prefix, '/sbin/refind-install', '2>', \$error, @options)
or die "refind-install failed: $error";
}
+
#- Try both possible locations for the main config file.
- set_refind_use_nvram($bootloader->{use_nvram}, "$::prefix/boot/EFI/EFI/refind/refind.conf");
- set_refind_use_nvram($bootloader->{use_nvram}, "$::prefix/boot/EFI/EFI/BOOT/refind.conf");
+ modify_refind_config($bootloader, "$::prefix/boot/EFI/EFI/refind");
+ modify_refind_config($bootloader, "$::prefix/boot/EFI/EFI/BOOT");
+
write_refind($bootloader, $all_hds);
}
-sub set_refind_use_nvram {
- my ($use_nvram, $path) = @_;
- return if ! -w $path;
- my $setting = $use_nvram ? 'true' : 'false';
- substInFile { s/^#?\s*use_nvram\s+.*/use_nvram $setting/ } $path;
+sub modify_refind_config {
+ my ($bootloader, $esp_dir) = @_;
+
+ my $config_file = "$esp_dir/refind.conf";
+ return if ! -f $config_file || ! -w $config_file;
+
+ my $use_nvram = $bootloader->{use_nvram} ? 'true' : 'false';
+
+ my @config;
+
+ %done;
+ foreach (cat_utf8($config_file)) {
+ if ($_ =~ /^#?use_nvram\s/) {
+ if (! $done{use_nvram}) {
+ push @config, "use_nvram $use_nvram\n" ;
+ $done{use_nvram} = 1;
+ }
+ } else {
+ push @config, $_;
+ }
+ }
+
+ if (@config) {
+ log::l("writing rEFInd config to $config_file");
+ renamef($config_file, $config_file . '.old');
+ output_with_perm($config_file, 0600, @config);
+ } else {
+ log::l("config has no entries - rEFInd config file not written");
+ }
}
sub when_config_changed_refind {