diff --git a/mkosi.extra/usr/lib/auto-hide-bootloader b/mkosi.extra/usr/lib/auto-hide-bootloader new file mode 100755 index 0000000..9b157db --- /dev/null +++ b/mkosi.extra/usr/lib/auto-hide-bootloader @@ -0,0 +1,30 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL +# SPDX-FileCopyrightText: 2025 Thomas Duckworth + +set -eu + +case "${1:-}" in + show) + /usr/bin/bootctl set-timeout "" + ;; + hide) + OTHER_OS_COUNT="$(bootctl list | grep "^\s*id:" | grep -vE "kde-linux_.*\.efi|auto-efi-shell|auto-reboot-to-firmware-setup" | wc -l)" + if [ "$OTHER_OS_COUNT" -gt 0 ]; then + echo "Multiple operating systems detected, not hiding bootloader." + exit 0 + fi + UPTIME_SECONDS="$(cut -d. -f1 /proc/uptime)" + if [ "$UPTIME_SECONDS" -lt 300 ]; then + echo "System uptime was less than 5 minutes, not hiding bootloader." + exit 0 + fi + if [ "$(systemctl show -p Result --value kde-linux-bless-boot.service 2>/dev/null || echo "failed")" = "success" ]; then + /usr/bin/bootctl set-timeout 0 + fi + ;; + *) + echo "Usage: $0 {show|hide}" + exit 1 + ;; +esac diff --git a/mkosi.extra/usr/lib/systemd/system-preset/50-kde-linux.preset b/mkosi.extra/usr/lib/systemd/system-preset/50-kde-linux.preset index c264bda..e021196 100644 --- a/mkosi.extra/usr/lib/systemd/system-preset/50-kde-linux.preset +++ b/mkosi.extra/usr/lib/systemd/system-preset/50-kde-linux.preset @@ -30,6 +30,7 @@ enable nvidia-resume.service enable kde-linux-btrfs.service enable kde-linux-live-setup.service enable kde-linux-volatile-var-lib-flatpak.service +enable kde-linux-auto-hide-bootloader.service enable plasma-setup-live-system.service enable var-lib-snapd-snap.mount # also one of ours but not prefixed with kde-linux- so others can use it too diff --git a/mkosi.extra/usr/lib/systemd/system/kde-linux-auto-hide-bootloader.service b/mkosi.extra/usr/lib/systemd/system/kde-linux-auto-hide-bootloader.service new file mode 100644 index 0000000..7ed2835 --- /dev/null +++ b/mkosi.extra/usr/lib/systemd/system/kde-linux-auto-hide-bootloader.service @@ -0,0 +1,21 @@ +# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL +# SPDX-FileCopyrightText: 2025 Thomas Duckworth + +[Unit] +Description=Automatically hide the bootloader if the image is good +After=local-fs.target +Before=kde-linux-bless-boot.service + +[Service] +Type=oneshot +RemainAfterExit=yes +# If the system either is not blessed or is forcibly shut down for some reason, +# the boot menu timeout is reset to default, and the menu is shown. +ExecStart=/usr/lib/auto-hide-bootloader show +# If the boot was blessed, the user shuts the system down normally, and the uptime +# is greater than 5 minutes, the bootloader is hidden, because the current image should work. +# This is idempotent if more than one operating system is installed. +ExecStop=/usr/lib/auto-hide-bootloader hide + +[Install] +WantedBy=kde-linux-bless-boot.service