Commit c1843ddb authored by Philip Müller's avatar Philip Müller

[pkg-upd] 2.03.0-10

- add grub-quiet patchset
parent 4c503ccb
......@@ -19,7 +19,7 @@ _UNIFONT_VER="10.0.06"
pkgname="grub"
pkgdesc="GNU GRand Unified Bootloader (2)"
pkgver=2.03.0
pkgrel=9
pkgrel=10
url="https://www.gnu.org/software/grub/"
arch=('x86_64' 'i686')
license=('GPL3')
......@@ -27,9 +27,11 @@ backup=('boot/grub/grub.cfg' 'etc/default/grub' 'etc/grub.d/40_custom')
install="${pkgname}.install"
options=('!makeflags')
conflicts=('grub-common' 'grub-bios' "grub-efi-${_EFI_ARCH}" 'grub-legacy')
replaces=('grub-common' 'grub-bios' "grub-efi-${_EFI_ARCH}")
provides=('grub-common' 'grub-bios' "grub-efi-${_EFI_ARCH}")
conflicts=('grub-common' 'grub-bios' "grub-efi-${_EFI_ARCH}"
'grub-legacy' 'grub-fedora' 'grub-quiet-fedora' 'grub-quiet-test' 'grub-quiet')
replaces=('grub-common' 'grub-bios' "grub-efi-${_EFI_ARCH}" 'grub-quiet')
provides=('grub-common' 'grub-bios' "grub-efi-${_EFI_ARCH}" "grub=$pkgver-$pkgrel"
"grub-quiet=$pkgver-$pkgrel")
makedepends=('git' 'rsync' 'xz' 'freetype2' 'ttf-dejavu' 'python' 'autogen'
'texinfo' 'help2man' 'gettext' 'device-mapper' 'fuse')
......@@ -50,9 +52,23 @@ source=(#"grub-${_pkgver}::git+git://git.sv.gnu.org/grub.git#tag=${_GRUB_GIT_TAG
'grub-revert-6400613.patch'
'grub-export-path.patch'
'grub-add-GRUB_COLOR_variables.patch'
'grub-gettext_quiet.patch'
'grub-manjaro-modifications.patch'
'grub-use-efivarfs.patch'
#'grub-efi-console-do-not-set-text-mode-until-we-actually-need-it.patch'
'grub-efi-console-implement-getkeystatus-support.patch'
'grub-efi-console-add-grub_console_read_key_stroke-helper-function.patch'
'grub-make-grub_getkeystatus-helper-function-available-ever.patch'
'grub-accept-esc-f8-and-holding-shift-as-user-interrupt-key.patch'
'grub-rename-00_menu_auto_hide.in-to-01_menu_auto_hide.in.patch'
'grub-grub-boot-success.timer-add-a-few-conditions-for-run.patch'
'grub-docs-stop-using-polkit-pkexec-for-grub-boot-success.patch'
'grub-add-grub-set-bootflag-utility.patch'
'grub-add-auto-hide-menu-support.patch'
'grub-00_menu_auto_hide-use-a-timeout-of-60s-for-menu_show.patch'
'grub-00_menu_auto_hide-reduce-number-of-save_env-calls.patch'
'grub-add-grub-boot-indeterminate.service.patch'
'grub-maybe_quiet.patch'
'grub-gettext_quiet.patch'
'background.png'
'grub.default'
'grub.cfg'
......@@ -65,11 +81,24 @@ sha256sums=('83f559c61510760ea7d8484d9609948eedfc090ae2ea9d704936b81cde9ab582'
'40401632b8d790976a80f3075fc9bfe8197b9b3b21080bbba517e7dd0784389a'
'63c611189a60d68c6ae094f2ced91ac576b3921b7fd2e75a551c2dc6baefc35e'
'a5198267ceb04dceb6d2ea7800281a42b3f91fd02da55d2cc9ea20d47273ca29'
'39d7843dfe1e10ead912a81be370813b8621794a7967b3cc5e4d4188b5bf7264'
'cf00c96aee37e0a73c1ab6ed6ccfe74fa2b2859f55cd315a4caa6c880ce7aeba'
'20b2b6e7f501596b5cce6ffa05906980427f760c03d308d0e045cf2ecf47bb0e'
'b218ade00670bad6095e0284b17d85f6f92900d5ebd156a2ec1cbc5ccad92fcb'
'd49236776e53a7ffdc5845205c94b3276b116d1f476bbccadcea1aa0a3f57b38'
'3803a487dce21f29bff829c391651705a9253431af5b20ca4ed9fe8f7ea7db6d'
'efdf468c2a7a55657b7172eea2803f2fb8a3021413f475006429f69202ba540a'
'7e46f081c08dec87d522b8db642e55e51fe89a02b9d9bfd4760f58a7692ede4a'
'54a0a0591b38b82c96a6e400cd9212f8e916120701cc9d91daca56b4c185c768'
'05a3b96970f78a2440847d1852fa2d79586aa9a047e774f41ee862a2bcb645ca'
'3f67b4c18e9d573a7a63543e8727dc701ebb20710770a53a415a31bc0c4721f4'
'0579636531ee5e0bf0de489b88bd1deda678cfdfd714afef49bb62e971b3644b'
'42212498678d8049115cbb7363d0bdd9ba4cff48e4d1b88a6b1fa174576e6011'
'1ab0b9da5af1e4aba25ade5cc7f496610ec7828023ad1ba0b613be535683f881'
'468c6edc9a3a7595d8d09fe1cd34e22f1375be61ce1003160b5d2c4c9c22182a'
'9a0ef2efe572f3e206d8f145cb9a00098f44d41eaf396110810f6f79885bd5de'
'39d7843dfe1e10ead912a81be370813b8621794a7967b3cc5e4d4188b5bf7264'
'01264c247283b7bbdef65d7646541c022440ddaf54f8eaf5aeb3a02eb98b4dd8'
'0e37ff13f57fede9914508e0a240572ab92d7c67fb91c307043e74727f9f4fd8'
'6558399b3745ca34511761e472ba114bf3a3f02c8f64fa77a237395030fa79f6'
'7fc95d49c0febe98a76e56b606a280565cb736580adecf163bc6b5aca8e7cbd8'
'467b0101154076fee99d9574a5fb6b772a3923cc200a1f4ca08fe17be8d68111'
'1488d7f3924bd7385a222e3e9685cdb1ecb39f3d6f882da6b5907b898f5b8f08')
......@@ -104,13 +133,30 @@ prepare() {
patch -Np1 -i "${srcdir}/grub-add-GRUB_COLOR_variables.patch"
echo
msg "Patch to fall back to untranslated text"
# If no translations are available, fall back to untranslated text.
patch -Np1 -i "${srcdir}/grub-gettext_quiet.patch"
msg "Patch to include Manjaro Linux Modifications"
patch -Np1 -i "${srcdir}/grub-manjaro-modifications.patch"
echo
msg "Add Grub-Quiet patches"
# Disable this patch for now. Creates black screens on some Lenovo laptops
#patch -Np1 -i "${srcdir}/grub-efi-console-do-not-set-text-mode-until-we-actually-need-it.patch"
patch -Np1 -i "${srcdir}/grub-efi-console-add-grub_console_read_key_stroke-helper-function.patch"
patch -Np1 -i "${srcdir}/grub-efi-console-implement-getkeystatus-support.patch"
patch -Np1 -i "${srcdir}/grub-make-grub_getkeystatus-helper-function-available-ever.patch"
patch -Np1 -i "${srcdir}/grub-accept-esc-f8-and-holding-shift-as-user-interrupt-key.patch"
patch -Np1 -i "${srcdir}/grub-add-grub-set-bootflag-utility.patch"
patch -Np1 -i "${srcdir}/grub-add-auto-hide-menu-support.patch"
patch -Np1 -i "${srcdir}/grub-00_menu_auto_hide-use-a-timeout-of-60s-for-menu_show.patch"
patch -Np1 -i "${srcdir}/grub-00_menu_auto_hide-reduce-number-of-save_env-calls.patch"
patch -Np1 -i "${srcdir}/grub-rename-00_menu_auto_hide.in-to-01_menu_auto_hide.in.patch"
patch -Np1 -i "${srcdir}/grub-grub-boot-success.timer-add-a-few-conditions-for-run.patch"
patch -Np1 -i "${srcdir}/grub-docs-stop-using-polkit-pkexec-for-grub-boot-success.patch"
patch -Np1 -i "${srcdir}/grub-maybe_quiet.patch"
patch -Np1 -i "${srcdir}/grub-gettext_quiet.patch"
patch -Np1 -i "${srcdir}/grub-add-grub-boot-indeterminate.service.patch"
# delete line due man h2m
sed -i -e '1369d' "${srcdir}/grub-${_pkgver}/Makefile.util.def"
echo
msg "Fix DejaVuSans.ttf location so that grub-mkfont can create *.pf2 files for starfield theme"
sed 's|/usr/share/fonts/dejavu|/usr/share/fonts/dejavu /usr/share/fonts/TTF|g' -i "${srcdir}/grub-${_pkgver}/configure.ac"
......@@ -180,6 +226,8 @@ _build_grub-common_and_bios() {
--program-prefix="" \
--with-bootdir="/boot" \
--with-grubdir="grub" \
--enable-quiet-boot \
--enable-quick-boot \
--disable-silent-rules \
--disable-werror
echo
......@@ -230,6 +278,8 @@ _build_grub-efi() {
--program-prefix="" \
--with-bootdir="/boot" \
--with-grubdir="grub" \
--enable-quiet-boot \
--enable-quick-boot \
--disable-silent-rules \
--disable-werror
echo
......@@ -296,7 +346,6 @@ _package_grub-efi() {
}
package() {
msg "Package grub ${_EFI_ARCH} efi stuff"
_package_grub-efi
......@@ -304,4 +353,15 @@ package() {
_package_grub-common_and_bios
install -D -m644 "${srcdir}/${pkgname}.hook" "${pkgdir}/usr/share/libalpm/hooks/99-${pkgname}.hook"
# install example files
mkdir -p "${pkgdir}/usr/lib/systemd/user/timers.target.wants"
install -D -m644 "${srcdir}/grub-${_pkgver}/docs/grub-boot-success.timer" "${pkgdir}/usr/lib/systemd/user/grub-boot-success.timer"
install -D -m644 "${srcdir}/grub-${_pkgver}/docs/grub-boot-success.service" "${pkgdir}/usr/lib/systemd/user/grub-boot-success.service"
ln -sfv '../grub-boot-success.timer' "${pkgdir}/usr/lib/systemd/user/timers.target.wants/grub-boot-success.timer"
chmod +s "${pkgdir}/usr/bin/grub-set-bootflag"
mkdir -p "${pkgdir}/usr/lib/systemd/system/sysinit.target.wants/"
install -D -m644 "${srcdir}/grub-${_pkgver}/docs/grub-boot-indeterminate.service" "${pkgdir}/usr/lib/systemd/system/grub-boot-indeterminate.service"
ln -sfv '../grub-boot-indeterminate.service' "${pkgdir}/usr/lib/systemd/system/sysinit.target.wants/grub-boot-indeterminate.service"
}
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Hans de Goede <hdegoede@redhat.com>
Date: Wed, 27 Jun 2018 13:33:43 +0200
Subject: [PATCH] 00_menu_auto_hide: Reduce number of save_env calls
Normally boot_success will be 1 on every boot (as normally the
previous boot will have been successful). This means that we end
up in the code-path to set boot_indeterminate to 0 every boot.
So we do 2 separate save_env calls each boot, one for boot_indeterminate
and one for boot_success. This results in 2 writes to the disk.
This commit makes us save both boot_success and boot_indeterminate
in a single call, reducing the number of writes, this reducing wear
and tear on the underlying storage.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
util/grub.d/00_menu_auto_hide.in | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/util/grub.d/00_menu_auto_hide.in b/util/grub.d/00_menu_auto_hide.in
index ca95c0d1c9f..ad175870a54 100644
--- a/util/grub.d/00_menu_auto_hide.in
+++ b/util/grub.d/00_menu_auto_hide.in
@@ -19,14 +19,12 @@ fi
# Reset boot_indeterminate after a successful boot
if [ "\${boot_success}" = "1" ] ; then
set boot_indeterminate=0
- save_env boot_indeterminate
# Avoid boot_indeterminate causing the menu to be hidden more then once
elif [ "\${boot_indeterminate}" = "1" ]; then
set boot_indeterminate=2
- save_env boot_indeterminate
fi
set boot_success=0
-save_env boot_success
+save_env boot_success boot_indeterminate
if [ x\$feature_timeout_style = xy ] ; then
if [ "\${menu_show_once}" ]; then
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Hans de Goede <hdegoede@redhat.com>
Date: Tue, 26 Jun 2018 12:44:29 +0200
Subject: [PATCH] 00_menu_auto_hide: Use a timeout of 60s for menu_show_once,
rather then no timeout
On some UEFI systems with fastboot enabled (USB) keyboards don't work at
all, not even when explictly asking for keyboard input.
So lets change the timeout from not set (no timeout) to 60 seconds, so
that on such systems if the menu was requested we continue with the
default choice after 60 seconds.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
util/grub.d/00_menu_auto_hide.in | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/util/grub.d/00_menu_auto_hide.in b/util/grub.d/00_menu_auto_hide.in
index a10fe45bb2c..ca95c0d1c9f 100644
--- a/util/grub.d/00_menu_auto_hide.in
+++ b/util/grub.d/00_menu_auto_hide.in
@@ -33,7 +33,7 @@ if [ x\$feature_timeout_style = xy ] ; then
unset menu_show_once
save_env menu_show_once
set timeout_style=menu
- unset timeout
+ set timeout=60
elif [ "\${menu_auto_hide}" -a "\${last_boot_ok}" = "1" ]; then
set orig_timeout_style=\${timeout_style}
set orig_timeout=\${timeout}
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Hans de Goede <hdegoede@redhat.com>
Date: Mon, 26 Mar 2018 16:15:53 +0200
Subject: [PATCH] Accept ESC, F8 and holding SHIFT as user interrupt keys
On some devices the ESC key is the hotkey to enter the BIOS/EFI setup
screen, making it really hard to time pressing it right. Besides that
ESC is also pretty hard to discover for a user who does not know it
will unhide the menu.
This commit makes F8, which used to be the hotkey to show the Windows
boot menu during boot for a long long time, also interrupt sleeps /
stop the menu countdown.
This solves the ESC gets into the BIOS setup and also somewhat solves
the discoverability issue, but leaves the timing issue unresolved.
This commit fixes the timing issue by also adding support for keeping
SHIFT pressed during boot to stop the menu countdown. This matches
what Ubuntu is doing, which should also help with discoverability.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
grub-core/commands/sleep.c | 2 +-
grub-core/kern/term.c | 16 ++++++++++++++++
grub-core/normal/menu.c | 2 +-
include/grub/term.h | 1 +
4 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/grub-core/commands/sleep.c b/grub-core/commands/sleep.c
index e77e7900fac..a1370b710c9 100644
--- a/grub-core/commands/sleep.c
+++ b/grub-core/commands/sleep.c
@@ -55,7 +55,7 @@ grub_interruptible_millisleep (grub_uint32_t ms)
start = grub_get_time_ms ();
while (grub_get_time_ms () - start < ms)
- if (grub_getkey_noblock () == GRUB_TERM_ESC)
+ if (grub_key_is_interrupt (grub_getkey_noblock ()))
return 1;
return 0;
diff --git a/grub-core/kern/term.c b/grub-core/kern/term.c
index 93bd3378d18..6cae4c23e7a 100644
--- a/grub-core/kern/term.c
+++ b/grub-core/kern/term.c
@@ -138,6 +138,22 @@ grub_getkeystatus (void)
return status;
}
+int
+grub_key_is_interrupt (int key)
+{
+ /* ESC sometimes is the BIOS setup hotkey and may be hard to discover, also
+ check F8, which was the key to get the Windows bootmenu for a long time. */
+ if (key == GRUB_TERM_ESC || key == GRUB_TERM_KEY_F8)
+ return 1;
+
+ /* Pressing keys at the right time during boot is hard to time, also allow
+ interrupting sleeps / the menu countdown by keeping shift pressed. */
+ if (grub_getkeystatus() & (GRUB_TERM_STATUS_LSHIFT|GRUB_TERM_STATUS_RSHIFT))
+ return 1;
+
+ return 0;
+}
+
void
grub_refresh (void)
{
diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c
index 5e2f5283d3d..6cb2a071490 100644
--- a/grub-core/normal/menu.c
+++ b/grub-core/normal/menu.c
@@ -655,7 +655,7 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot)
if (entry >= 0)
break;
}
- if (key == GRUB_TERM_ESC)
+ if (grub_key_is_interrupt (key))
{
timeout = -1;
break;
diff --git a/include/grub/term.h b/include/grub/term.h
index c215133383f..2b079c29b80 100644
--- a/include/grub/term.h
+++ b/include/grub/term.h
@@ -328,6 +328,7 @@ void grub_putcode (grub_uint32_t code, struct grub_term_output *term);
int EXPORT_FUNC(grub_getkey) (void);
int EXPORT_FUNC(grub_getkey_noblock) (void);
int EXPORT_FUNC(grub_getkeystatus) (void);
+int EXPORT_FUNC(grub_key_is_interrupt) (int key);
void grub_cls (void);
void EXPORT_FUNC(grub_refresh) (void);
void grub_puts_terminal (const char *str, struct grub_term_output *term);
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Hans de Goede <hdegoede@redhat.com>
Date: Wed, 6 Jun 2018 08:44:11 +0200
Subject: [PATCH] Add auto-hide menu support
On single-os systems we do not want to show the menu, unless something
went wrong with the previous boot, in which case the user may need the
menu to debug/fix the problem.
This commit adds a new grub.d/00_menu_auto_hide file which emits a
config snippet implementing this. I've chosen to do this in a separate
grub.d file because chances of this going upstream are small and this way
it will be easier to rebase.
Since auto-hiding the menu requires detecting the previous boot was ok,
we get fastboot support (where we don't check for a key at all) for free
so this commit also adds support for this.
The new config-file code uses the following variables:
menu_auto_hide Set this to "1" to activate the new auto-hide feature
Set this to "2" to auto-hide the menu even when multiple
operating systems are installed. Note the menu will still
auto show after booting an other os as that won't set
boot_success.
menu_show_once Set this to "1" to force showing the menu once.
boot_success The OS sets this to "1" to indicate a successful boot.
boot_indeterminate The OS increments this integer when rebooting after e.g.
installing updates or a selinux relabel.
fastboot If set to "1" and the conditions for auto-hiding the menu
are met, the menu is not shown and all checks for keypresses
are skipped, booting the default immediately.
30_os-prober.in changes somewhat inspired by:
https://git.launchpad.net/~ubuntu-core-dev/grub/+git/ubuntu/tree/debian/patches/quick_boot.patch
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
Changes in v2:
-Drop shutdown_success tests, there is no meaningful way for systemd to set
this flag (by the time it knows all filesystems are unmounted or read-only
-Drop fwsetup_once support, systemd already supports booting directly into
the fwsetup by doing "systemctl reboot --firmware"
---
Makefile.util.def | 6 +++++
util/grub.d/00_menu_auto_hide.in | 50 ++++++++++++++++++++++++++++++++++++++++
util/grub.d/30_os-prober.in | 18 +++++++++++++++
3 files changed, 74 insertions(+)
create mode 100644 util/grub.d/00_menu_auto_hide.in
diff --git a/Makefile.util.def b/Makefile.util.def
index cbd661d6348..0fdfdd91fb0 100644
--- a/Makefile.util.def
+++ b/Makefile.util.def
@@ -448,6 +448,12 @@ script = {
installdir = grubconf;
};
+script = {
+ name = '00_menu_auto_hide';
+ common = util/grub.d/00_menu_auto_hide.in;
+ installdir = grubconf;
+};
+
script = {
name = '01_users';
common = util/grub.d/01_users.in;
diff --git a/util/grub.d/00_menu_auto_hide.in b/util/grub.d/00_menu_auto_hide.in
new file mode 100644
index 00000000000..a10fe45bb2c
--- /dev/null
+++ b/util/grub.d/00_menu_auto_hide.in
@@ -0,0 +1,50 @@
+#! /bin/sh
+
+# Disable / skip generating menu-auto-hide config parts on serial terminals
+for x in ${GRUB_TERMINAL_INPUT} ${GRUB_TERMINAL_OUTPUT}; do
+ case "$x" in
+ serial*)
+ exit 0
+ ;;
+ esac
+done
+
+cat << EOF
+if [ "\${boot_success}" = "1" -o "\${boot_indeterminate}" = "1" ]; then
+ set last_boot_ok=1
+else
+ set last_boot_ok=0
+fi
+
+# Reset boot_indeterminate after a successful boot
+if [ "\${boot_success}" = "1" ] ; then
+ set boot_indeterminate=0
+ save_env boot_indeterminate
+# Avoid boot_indeterminate causing the menu to be hidden more then once
+elif [ "\${boot_indeterminate}" = "1" ]; then
+ set boot_indeterminate=2
+ save_env boot_indeterminate
+fi
+set boot_success=0
+save_env boot_success
+
+if [ x\$feature_timeout_style = xy ] ; then
+ if [ "\${menu_show_once}" ]; then
+ unset menu_show_once
+ save_env menu_show_once
+ set timeout_style=menu
+ unset timeout
+ elif [ "\${menu_auto_hide}" -a "\${last_boot_ok}" = "1" ]; then
+ set orig_timeout_style=\${timeout_style}
+ set orig_timeout=\${timeout}
+ if [ "\${fastboot}" = "1" ]; then
+ # timeout_style=menu + timeout=0 avoids the countdown code keypress check
+ set timeout_style=menu
+ set timeout=0
+ else
+ set timeout_style=hidden
+ set timeout=1
+ fi
+ fi
+fi
+EOF
diff --git a/util/grub.d/30_os-prober.in b/util/grub.d/30_os-prober.in
index 13a3a6bc752..ab634393a31 100644
--- a/util/grub.d/30_os-prober.in
+++ b/util/grub.d/30_os-prober.in
@@ -43,6 +43,7 @@ if [ -z "${OSPROBED}" ] ; then
fi
osx_entry() {
+ found_other_os=1
if [ x$2 = x32 ]; then
# TRANSLATORS: it refers to kernel architecture (32-bit)
bitstr="$(gettext "(32-bit)")"
@@ -146,6 +147,7 @@ for OS in ${OSPROBED} ; do
case ${BOOT} in
chain)
+ found_other_os=1
onstr="$(gettext_printf "(on %s)" "${DEVICE}")"
cat << EOF
@@ -176,6 +178,7 @@ EOF
EOF
;;
efi)
+ found_other_os=1
EFIPATH=${DEVICE#*@}
DEVICE=${DEVICE%@*}
@@ -220,6 +223,7 @@ EOF
LINITRD="${LINITRD#/boot}"
fi
+ found_other_os=1
onstr="$(gettext_printf "(on %s)" "${DEVICE}")"
recovery_params="$(echo "${LPARAMS}" | grep single)" || true
counter=1
@@ -292,6 +296,7 @@ EOF
fi
;;
hurd)
+ found_other_os=1
onstr="$(gettext_printf "(on %s)" "${DEVICE}")"
cat << EOF
menuentry '$(echo "${LONGNAME} $onstr" | grub_quote)' --class hurd --class gnu --class os \$menuentry_id_option 'osprober-gnuhurd-/boot/gnumach.gz-false-$(grub_get_device_id "${DEVICE}")' {
@@ -318,6 +323,7 @@ EOF
EOF
;;
minix)
+ found_other_os=1
cat << EOF
menuentry "${LONGNAME} (on ${DEVICE}, Multiboot)" {
EOF
@@ -334,3 +340,15 @@ EOF
;;
esac
done
+
+# We override the results of the menu_auto_hide code here, this is a bit ugly,
+# but grub-mkconfig writes out the file linearly, so this is the only way
+if [ "${found_other_os}" = "1" ]; then
+ cat << EOF
+# Other OS found, undo autohiding of menu unless menu_auto_hide=2
+if [ "\${orig_timeout_style}" -a "\${menu_auto_hide}" != "2" ]; then
+ set timeout_style=\${orig_timeout_style}
+ set timeout=\${orig_timeout}
+fi
+EOF
+fi
From ca163ee67597a6ae4ba78abfb24cf3aa2817c3a1 Mon Sep 17 00:00:00 2001
From: Hans de Goede <hdegoede@redhat.com>
Date: Tue, 19 Jun 2018 15:20:54 +0200
Subject: [PATCH] docs: Add grub-boot-indeterminate.service example
This is an example service file, for use from
/lib/systemd/system/system-update.target.wants
to increment the boot_indeterminate variable when
doing offline updates.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
docs/grub-boot-indeterminate.service | 11 +++++++++++
1 file changed, 11 insertions(+)
create mode 100644 docs/grub-boot-indeterminate.service
diff --git a/docs/grub-boot-indeterminate.service b/docs/grub-boot-indeterminate.service
new file mode 100644
index 000000000..6c8dcb186
--- /dev/null
+++ b/docs/grub-boot-indeterminate.service
@@ -0,0 +1,11 @@
+[Unit]
+Description=Mark boot as indeterminate
+DefaultDependencies=false
+Requires=sysinit.target
+After=sysinit.target
+Wants=system-update-pre.target
+Before=system-update-pre.target
+
+[Service]
+Type=oneshot
+ExecStart=/usr/bin/grub2-editenv - incr boot_indeterminate
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Hans de Goede <hdegoede@redhat.com>
Date: Tue, 12 Jun 2018 13:25:16 +0200
Subject: [PATCH] Add grub-set-bootflag utility
This commit adds a new grub-set-bootflag utility, which can be used
to set known bootflags in the grubenv: boot_success or menu_show_once.
grub-set-bootflag is different from grub-editenv in 2 ways:
1) It is intended to be executed by regular users through pkexec, so
running as root if the polkit policy allows this. As such it is written
to not use any existing grubenv related code for easy auditing.
2) Since it can be executed by regular users it only allows setting
(assigning a value of 1 to) bootflags which it knows about. Currently
those are just boot_success and menu_show_once.
This commit also adds a couple of example systemd and polkit files which
show how this can be used to set boot_success from a user-session:
docs/grub-boot-success.service
docs/grub-boot-success.timer
docs/org.gnu.grub.policy
The 2 grub-boot-success.systemd files should be placed in /lib/systemd/user
and a symlink to grub-boot-success.timer should be added to
/lib/systemd/user/timers.target.wants.
The org.gnu.grub.policy polkit file should be placed in
/usr/share/polkit-1/actions.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
Makefile.util.def | 7 ++
util/grub-set-bootflag.c | 158 +++++++++++++++++++++++++++++++++++++++++
.gitignore | 2 +
conf/Makefile.extra-dist | 3 +
docs/grub-boot-success.service | 6 ++
docs/grub-boot-success.timer | 5 ++
docs/org.gnu.grub.policy | 20 ++++++
util/grub-set-bootflag.1 | 20 ++++++
8 files changed, 221 insertions(+)
create mode 100644 util/grub-set-bootflag.c
create mode 100644 docs/grub-boot-success.service
create mode 100644 docs/grub-boot-success.timer
create mode 100644 docs/org.gnu.grub.policy
create mode 100644 util/grub-set-bootflag.1
diff --git a/Makefile.util.def b/Makefile.util.def
index 5a8c390a1da..5da55393291 100644
--- a/Makefile.util.def
+++ b/Makefile.util.def
@@ -1435,3 +1435,10 @@ program = {
ldadd = grub-core/gnulib/libgnu.a;
ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)';
};
+
+program = {
+ name = grub-set-bootflag;
+ installdir = bin;
+ mansection = 1;
+ common = util/grub-set-bootflag.c;
+};
diff --git a/util/grub-set-bootflag.c b/util/grub-set-bootflag.c
new file mode 100644
index 00000000000..f8dc310909a
--- /dev/null
+++ b/util/grub-set-bootflag.c
@@ -0,0 +1,158 @@
+/* grub-set-bootflag.c - tool to set boot-flags in the grubenv. */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2018 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * NOTE this gets run by users as root (through pkexec), so this does not
+ * use any grub library / util functions to allow for easy auditing.
+ * The grub headers are only included to get certain defines.
+ */
+
+#include <config-util.h> /* For *_DIR_NAME defines */
+#include <grub/types.h>
+#include <grub/lib/envblk.h> /* For GRUB_ENVBLK_DEFCFG define */
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#define GRUBENV "/" GRUB_BOOT_DIR_NAME "/" GRUB_DIR_NAME "/" GRUB_ENVBLK_DEFCFG
+#define GRUBENV_SIZE 1024
+
+const char *bootflags[] = {
+ "boot_success",
+ "menu_show_once",
+ NULL
+};
+
+static void usage(void)
+{
+ int i;
+
+ fprintf (stderr, "Usage: 'grub-set-bootflag <bootflag>', where <bootflag> is one of:\n");
+ for (i = 0; bootflags[i]; i++)
+ fprintf (stderr, " %s\n", bootflags[i]);
+}
+
+int main(int argc, char *argv[])
+{
+ /* NOTE buf must be at least the longest bootflag length + 4 bytes */
+ char env[GRUBENV_SIZE + 1], buf[64], *s;
+ const char *bootflag;
+ int i, len, ret;
+ FILE *f;
+
+ if (argc != 2)
+ {
+ usage();
+ return 1;
+ }
+
+ for (i = 0; bootflags[i]; i++)
+ if (!strcmp (argv[1], bootflags[i]))
+ break;
+ if (!bootflags[i])
+ {
+ fprintf (stderr, "Invalid bootflag: '%s'\n", argv[1]);
+ usage();
+ return 1;
+ }
+
+ bootflag = bootflags[i];
+ len = strlen (bootflag);
+
+ f = fopen (GRUBENV, "r");
+ if (!f)
+ {
+ perror ("Error opening " GRUBENV " for reading");
+ return 1;
+ }
+
+ ret = fread (env, 1, GRUBENV_SIZE, f);
+ fclose (f);
+ if (ret != GRUBENV_SIZE)
+ {
+ perror ("Error reading from " GRUBENV);
+ return 1;
+ }
+
+ /* 0 terminate env */
+ env[GRUBENV_SIZE] = 0;
+
+ if (strncmp (env, GRUB_ENVBLK_SIGNATURE, strlen (GRUB_ENVBLK_SIGNATURE)))
+ {
+ fprintf (stderr, "Error invalid environment block\n");
+ return 1;
+ }
+
+ /* Find a pre-existing definition of the bootflag */
+ s = strstr (env, bootflag);
+ while (s && s[len] != '=')
+ s = strstr (s + len, bootflag);
+
+ if (s && ((s[len + 1] != '0' && s[len + 1] != '1') || s[len + 2] != '\n'))
+ {
+ fprintf (stderr, "Pre-existing bootflag '%s' has unexpected value\n", bootflag);
+ return 1;
+ }
+
+ /* No pre-existing bootflag? -> find free space */
+ if (!s)
+ {
+ for (i = 0; i < (len + 3); i++)
+ buf[i] = '#';
+ buf[i] = 0;
+ s = strstr (env, buf);
+ }
+
+ if (!s)
+ {
+ fprintf (stderr, "No space in grubenv to store bootflag '%s'\n", bootflag);
+ return 1;
+ }
+
+ /* The grubenv is not 0 terminated, so memcpy the name + '=' , '1', '\n' */