Skip to content

Commit 6474239

Browse files
authored
Merge pull request #841 from champtar/grub2-password
Rework grub2 default static config
2 parents 63f05bc + 741e9a5 commit 6474239

9 files changed

+42
-45
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ install:
4040
.PHONY: install-grub-static
4141
install-grub-static:
4242
install -m 644 -D -t ${DESTDIR}$(PREFIX)/lib/bootupd/grub2-static src/grub2/*.cfg
43-
install -m 755 -d ${DESTDIR}$(PREFIX)/lib/bootupd/grub2-static/configs.d
43+
install -m 644 -D -t ${DESTDIR}$(PREFIX)/lib/bootupd/grub2-static/configs.d src/grub2/configs.d/*.cfg
4444

4545
.PHONY: install-systemd-unit
4646
install-systemd-unit:

src/grub2/configs.d/01_users.cfg

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Keep the comment for grub2-set-password
2+
### BEGIN /etc/grub.d/01_users ###
3+
if [ -f ${prefix}/user.cfg ]; then
4+
source ${prefix}/user.cfg
5+
if [ -n "${GRUB2_PASSWORD}" ]; then
6+
set superusers="root"
7+
export superusers
8+
password_pbkdf2 root ${GRUB2_PASSWORD}
9+
fi
10+
fi

src/grub2/configs.d/10_blscfg.cfg

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
blscfg
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Force the menu to be shown once, with a timeout of ${menu_show_once_timeout}
2+
# if requested by ${menu_show_once_timeout} being set in the env.
3+
if [ "${menu_show_once_timeout}" ]; then
4+
set timeout_style=menu
5+
set timeout="${menu_show_once_timeout}"
6+
unset menu_show_once_timeout
7+
save_env menu_show_once_timeout
8+
fi
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
if [ "$grub_platform" = "efi" ]; then
2+
menuentry 'UEFI Firmware Settings' $menuentry_id_option 'uefi-firmware' {
3+
fwsetup
4+
}
5+
fi

src/grub2/configs.d/41_custom.cfg

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
if [ -f $prefix/custom.cfg ]; then
2+
source $prefix/custom.cfg
3+
fi

src/grub2/grub-static-post.cfg

-17
This file was deleted.

src/grub2/grub-static-pre.cfg

+5-16
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,13 @@ if [ -f $prefix/console.cfg ]; then
4343
source $prefix/console.cfg
4444
fi
4545

46-
if [ x"${feature_menuentry_id}" = xy ]; then
47-
menuentry_id_option="--id"
48-
else
49-
menuentry_id_option=""
50-
fi
46+
menuentry_id_option="--id"
5147

5248
function load_video {
53-
if [ x$feature_all_video_module = xy ]; then
54-
insmod all_video
55-
else
56-
insmod efi_gop
57-
insmod efi_uga
58-
insmod ieee1275_fb
59-
insmod vbe
60-
insmod vga
61-
insmod video_bochs
62-
insmod video_cirrus
63-
fi
49+
insmod all_video
6450
}
6551

52+
set timeout_style=menu
53+
set timeout=1
54+
6655
# Other package code will be injected from here

src/grubconfigs.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ pub(crate) fn install(
2929
bootdir.create_dir(GRUB2DIR, 0o700)?;
3030
}
3131

32-
let mut config = std::fs::read_to_string(Path::new(CONFIGDIR).join("grub-static-pre.cfg"))?;
32+
let mut config = String::from("# Generated by bootupd / do not edit\n\n");
33+
34+
let pre = std::fs::read_to_string(Path::new(CONFIGDIR).join("grub-static-pre.cfg"))?;
35+
config.push_str(pre.as_str());
3336

3437
let dropindir = openat::Dir::open(&Path::new(CONFIGDIR).join(DROPINDIR))?;
3538
// Sort the files for reproducibility
@@ -47,16 +50,11 @@ pub(crate) fn install(
4750
log::debug!("Ignoring {name}");
4851
continue;
4952
}
50-
writeln!(config, "source $prefix/{name}")?;
51-
dropindir
52-
.copy_file_at(name, bootdir, format!("{GRUB2DIR}/{name}"))
53-
.with_context(|| format!("Copying {name}"))?;
54-
println!("Installed {name}");
55-
}
56-
57-
{
58-
let post = std::fs::read_to_string(Path::new(CONFIGDIR).join("grub-static-post.cfg"))?;
59-
config.push_str(post.as_str());
53+
writeln!(config, "\n### BEGIN {name} ###")?;
54+
let dropin = std::fs::read_to_string(Path::new(CONFIGDIR).join(DROPINDIR).join(name))?;
55+
config.push_str(dropin.as_str());
56+
writeln!(config, "### END {name} ###")?;
57+
println!("Added {name}");
6058
}
6159

6260
bootdir

0 commit comments

Comments
 (0)