Review: enroll keeps foreign db keys, configurable paths, on-demand eac-run, launcher ebuild, db dedupe tool

This commit is contained in:
2026-12-04 08:35:52 +01:00
parent dec92adb08
commit 7cf69ae701
18 changed files with 509 additions and 122 deletions
@@ -0,0 +1 @@
DIST epic-games-launcher-bin-0.127.0.deb 71836680 BLAKE2B 59670ac2f267f155e54988a4d6d5bf013a163b024b97fd26d652fa22a5c5e078cfe2b704bd0e1a4d03d585e34b4c51f3510543b557756e40fe68189267061e49 SHA512 ebaeb89eb677ae92c8e3e559564d0f565f8a3588d6c3eda1bbbe363a9eaed8b776681f59aef62c70df5766f590c2787ca9b8503e7da8e6d8f45aab572a435a4a
@@ -0,0 +1,54 @@
# Copyright 2026 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=8
inherit desktop unpacker xdg
# Epic's build id; the version alone does not name a download.
EGL_BUILD=gc5cf008
DESCRIPTION="Epic Games Launcher (official Linux preview)"
HOMEPAGE="https://store.epicgames.com/"
SRC_URI="https://content-download-egs.distro.on.epicgames.com/Builds/EGLv2/${PV}%2B${EGL_BUILD}/Linux/EpicGamesLauncher-x86_64.deb -> ${P}.deb"
S=${WORKDIR}
LICENSE="all-rights-reserved"
SLOT="0"
KEYWORDS="-* ~amd64"
RESTRICT="bindist mirror strip"
QA_PREBUILT="*"
RDEPEND="
dev-libs/glib:2
dev-libs/libayatana-appindicator
net-libs/libsoup:3.0
net-libs/webkit-gtk:4.1
sys-apps/dbus
x11-libs/cairo
x11-libs/gdk-pixbuf:2
x11-libs/gtk+:3
x11-libs/libX11
x11-misc/xdg-utils
"
src_install() {
local dir=/opt/epic-games-launcher
# The binary's RUNPATH is $ORIGIN/../lib/epic-games-launcher: keep the .deb layout.
exeinto ${dir}/bin
doexe usr/bin/EpicGamesLauncher
exeinto ${dir}/lib/epic-games-launcher
doexe usr/lib/epic-games-launcher/libEOSSDK-Linux-Shipping.so
insinto ${dir}/lib/epic-games-launcher/resources
doins usr/lib/epic-games-launcher/resources/ThirdPartyNotices.txt
dobin "${FILESDIR}"/EpicGamesLauncher
dosym EpicGamesLauncher /usr/bin/epic-games-launcher
domenu usr/share/applications/epic-games-launcher.desktop
local size
for size in 32 128 256; do
doicon -s ${size} usr/share/icons/hicolor/${size}x${size}/apps/EpicGamesLauncher.png
done
}
@@ -0,0 +1,7 @@
#!/bin/sh
# The package manager installs updates, so the launcher's self-update is off.
export EGL_DISABLE_SELF_UPDATE="${EGL_DISABLE_SELF_UPDATE:-1}"
egl=/opt/epic-games-launcher/bin/EpicGamesLauncher
# On OpenRC, eac-run (sys-apps/eac-openrc-compat) provides what Easy Anti-Cheat needs while the launcher runs.
command -v eac-run >/dev/null 2>&1 && exec eac-run "$egl" "$@"
exec "$egl" "$@"
@@ -23,13 +23,19 @@ RDEPEND="
sys-apps/util-linux
sys-auth/elogind
sys-auth/polkit
sys-process/procps
"
src_install() {
dobin "${FILESDIR}"/systemctl "${FILESDIR}"/systemd-run
exeinto /usr/libexec/${PN}
doexe "${FILESDIR}"/systemd-run-agent "${FILESDIR}"/socket-activate
python_fix_shebang "${ED}"/usr/bin/systemd-run "${ED}"/usr/libexec/${PN}
local lib=/usr/libexec/${PN}
dobin "${FILESDIR}"/systemctl "${FILESDIR}"/systemd-run "${FILESDIR}"/eac-run
exeinto ${lib}
doexe "${FILESDIR}"/systemd-run-agent "${FILESDIR}"/socket-activate "${FILESDIR}"/socket-activate-ctl
python_fix_shebang "${ED}"/usr/bin/systemd-run "${ED}"${lib}/systemd-run-agent "${ED}"${lib}/socket-activate
insinto /usr/share/polkit-1/actions
doins "${FILESDIR}"/org.gentoo.eac-openrc-compat.policy
newinitd "${FILESDIR}"/socket-activate.initd socket-activate
dosym socket-activate /etc/init.d/socket-activate.easyanticheat_eos
@@ -42,7 +48,7 @@ src_install() {
}
pkg_postinst() {
elog "Start ${EPREFIX}/usr/libexec/${PN}/systemd-run-agent from your compositor's autostart,"
elog "and run a session-wide polkit authentication agent there (not pkttyagent)."
elog "Start game launchers through eac-run, e.g. eac-run EpicGamesLauncher,"
elog "and run a session-wide polkit authentication agent (not pkttyagent)."
elog "Details: ${EROOT}/usr/share/doc/${PF}/README.md*"
}
@@ -30,6 +30,9 @@ Logs: `~/.cache/com.epicgames.easyanticheat/service.log` (setup),
| File | Role |
| --- | --- |
| `/usr/bin/eac-run` | `eac-run COMMAND [ARGS...]`: runs a game launcher with the two pieces below, which run only as long as it does |
| `/usr/libexec/eac-openrc-compat/socket-activate-ctl` | `{start\|stop} NAME` for `socket-activate.NAME`, as root through pkexec; `stop` does nothing while the service it started still runs |
| `/usr/share/polkit-1/actions/org.gentoo.eac-openrc-compat.policy` | lets the active local session run `socket-activate-ctl` without a password; anyone else needs an admin password |
| `/usr/lib64/libsystemd.so.0` | link to elogind's library, which exports the same `LIBSYSTEMD_*` symbols the setup uses (`sd_listen_fds`, `sd_is_socket_unix`, `sd_notify`) |
| `/usr/bin/systemd-run` | the `--user` form only, forwarded to `systemd-run-agent`; anything else fails as on a host without a user manager |
| `/usr/libexec/eac-openrc-compat/systemd-run-agent` | runs those commands in the graphical session, with the session's environment, outside the caller's process tree |
@@ -64,8 +67,20 @@ Logs: `~/.cache/com.epicgames.easyanticheat/service.log` (setup),
## Setup
1. Start the agent in the graphical session, e.g. Hyprland:
`hl.exec_cmd("/usr/libexec/eac-openrc-compat/systemd-run-agent")`.
1. Start the launcher through `eac-run`, e.g. `eac-run EpicGamesLauncher`
(`games-util/epic-games-launcher-bin`'s `EpicGamesLauncher` does this
itself). From the graphical session, so the agent gets its environment and
polkit sees the active session. `eac-run`:
- starts `systemd-run-agent` unless one already runs for the user;
- starts `socket-activate.easyanticheat_eos` through pkexec once EAC is
installed (before that, the setup starts it itself);
- when the launcher exits, stops both, unless the listener was already
running before or is in the default runlevel. The listener stays
while the EAC service still serves a game.
Nothing runs at boot or in the background between game sessions. To keep
the listener running instead: `rc-update add socket-activate.easyanticheat_eos default`
(or `systemctl enable easyanticheat_eos.socket`); `eac-run` leaves it alone then.
2. Run a session-wide polkit authentication agent in that session
(hyprpolkitagent, polkit-gnome, lxqt-policykit, ...). `pkttyagent` does not
work: without `--process` it registers only for its parent shell, so polkit
@@ -73,8 +88,10 @@ Logs: `~/.cache/com.epicgames.easyanticheat/service.log` (setup),
in the setup's log). Check with
`systemd-run --user --wait --pipe pkexec --disable-internal-agent /usr/bin/true`:
"No authentication agent found" means none is registered for the session.
3. Launch the game and accept the service installation. The setup enables
`socket-activate.easyanticheat_eos` in the default runlevel itself.
3. Launch the game and accept the service installation. The setup runs
`systemctl start`; it never runs `enable`, since systemd would start the
socket at boot through EAC's `sockets.target.d` drop-in, which OpenRC does
not read.
Remove EAC's files again with `pkexec /usr/local/bin/easyanticheat_eos
uninstall standalone`, then `rc-update del socket-activate.easyanticheat_eos`.
uninstall standalone`.
+34
View File
@@ -0,0 +1,34 @@
#!/bin/sh
# Usage: eac-run COMMAND [ARGS...]
# Runs COMMAND (a game launcher) with what Easy Anti-Cheat needs on OpenRC, and only for as long
# as it runs: systemd-run-agent for the user, and the socket-activate.easyanticheat_eos listener,
# started through pkexec (no password for the active local session, see the polkit action).
[ $# -gt 0 ] || { echo "usage: eac-run COMMAND [ARGS...]" >&2; exit 2; }
lib=/usr/libexec/eac-openrc-compat
name=easyanticheat_eos
svc=socket-activate.$name
running() { rc-service "$svc" status >/dev/null 2>&1; }
at_boot() { rc-update show default 2>/dev/null | grep -qwF "$svc"; }
"$lib/systemd-run-agent" 2>/dev/null &
agent=$!
was_running=
running && was_running=1
# Before EAC's first install the binary is missing; its setup then starts the listener itself.
if [ -z "$was_running" ] && [ -x /usr/local/bin/easyanticheat_eos ]; then
pkexec "$lib/socket-activate-ctl" start "$name" >/dev/null || echo "eac-run: could not start $svc" >&2
fi
cleanup() {
if [ -z "$was_running" ] && running && ! at_boot; then
pkexec "$lib/socket-activate-ctl" stop "$name" >/dev/null
fi
kill "$agent" 2>/dev/null
}
trap cleanup EXIT
trap 'exit 130' INT TERM HUP
"$@"
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE policyconfig PUBLIC "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
"http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd">
<policyconfig>
<vendor>eac-openrc-compat</vendor>
<action id="org.gentoo.eac-openrc-compat.socket-activate">
<description>Start or stop a socket-activated service</description>
<message>Authentication is required to start or stop a socket-activated service</message>
<defaults>
<allow_any>auth_admin</allow_any>
<allow_inactive>auth_admin</allow_inactive>
<allow_active>yes</allow_active>
</defaults>
<annotate key="org.freedesktop.policykit.exec.path">/usr/libexec/eac-openrc-compat/socket-activate-ctl</annotate>
</action>
</policyconfig>
@@ -0,0 +1,22 @@
#!/bin/sh
# Usage (as root, normally through pkexec): socket-activate-ctl {start|stop} NAME
# Starts or stops the OpenRC service socket-activate.NAME. stop leaves it running while the
# service it started is still serving a client (for EAC: a game that is still running).
set -eu
action=${1:-}
name=${2:-}
case $action in start|stop) ;; *) echo "usage: socket-activate-ctl {start|stop} NAME" >&2; exit 2 ;; esac
case $name in ''|*[!A-Za-z0-9_.-]*) echo "socket-activate-ctl: invalid name '$name'" >&2; exit 2 ;; esac
svc=socket-activate.$name
[ -e "/etc/init.d/$svc" ] || { echo "socket-activate-ctl: $svc does not exist" >&2; exit 1; }
if [ "$action" = start ]; then
exec rc-service -N "$svc" start
fi
socket_command=
. "/etc/conf.d/$svc"
if [ -n "$socket_command" ] && pgrep -xf -- "$socket_command" >/dev/null; then
echo "socket-activate-ctl: ${socket_command%% *} still runs, $svc stays started" >&2
exit 0
fi
exec rc-service -s "$svc" stop
@@ -1,7 +1,8 @@
#!/usr/bin/python3 -I
"""Runs commands for systemd-run (eac-openrc-compat) in the graphical session.
Start it once per session, from the compositor's autostart. Each request comes from the
eac-run starts it from the graphical session (or start it from the compositor's autostart); a
second instance exits while the first one answers. Each request comes from the
systemd-run in /usr/bin over $XDG_RUNTIME_DIR/systemd-run-agent.sock; only the agent's own user
may connect. The command gets the agent's environment plus the request's --setenv values and, with
--pipe, the caller's stdin/stdout/stderr. Every run is logged to syslog.
@@ -3,6 +3,8 @@
EAPI=8
inherit toolchain-funcs
MY_PV=${PV/_p/-}
MY_KV=${MY_PV}-cachyos-eac
SDBOOT_PV=262.2_1-1
@@ -28,6 +30,7 @@ KEYWORDS="~amd64"
RESTRICT="mirror strip"
RDEPEND="
app-crypt/efitools
app-crypt/sbctl
app-crypt/sbsigntools
app-crypt/tpm2-tools
@@ -36,7 +39,11 @@ RDEPEND="
sys-boot/efibootmgr
sys-kernel/dracut
"
BDEPEND="app-arch/zstd"
BDEPEND="
app-arch/zstd
sys-apps/kmod
virtual/pkgconfig
"
src_unpack() {
local f
@@ -47,21 +54,32 @@ src_unpack() {
src_prepare() {
default
sed -i 's#esp=$(bootctl --print-esp-path 2>/dev/null || echo /boot)#esp=$(eac-boot esp)#' \
# eac-status takes the ESP, kernel and boot loader locations from eac-boot.
sed -i \
-e 's#esp=$(bootctl --print-esp-path 2>/dev/null || echo /boot)#esp=$(eac-boot esp)#' \
-e 's#"$esp/$(cat /etc/machine-id)/linux-cachyos-eac#"$(eac-boot kernel-dir)#' \
-e 's#"$esp/EFI/cachyos-eac/systemd-bootx64.efi"#"$(eac-boot loader)"#' \
usr/bin/eac-status || die
grep -q 'esp=$(eac-boot esp)' usr/bin/eac-status || die "eac-status: ESP patch did not apply"
[[ $(grep -c '$(eac-boot kernel-dir)' usr/bin/eac-status) == 2 ]] || die "eac-status: kernel-dir patch did not apply"
grep -q '"$(eac-boot loader)"' usr/bin/eac-status || die "eac-status: loader patch did not apply"
}
src_install() {
dodir /lib/modules
cp -a "usr/lib/modules/${MY_KV}" "${ED}/lib/modules/" || die
fowners -R root:root "/lib/modules/${MY_KV}"
# Wherever this system's kmod looks for modules (/lib/modules on Gentoo).
MODULES_DIR=$($(tc-getPKG_CONFIG) --variable=module_directory kmod)
: "${MODULES_DIR:=/lib/modules}"
dodir "${MODULES_DIR}"
cp -a "usr/lib/modules/${MY_KV}" "${ED}${MODULES_DIR}/" || die
fowners -R root:root "${MODULES_DIR}/${MY_KV}"
insinto /usr/lib/cachyos-eac
doins usr/lib/systemd/boot/efi/systemd-bootx64.efi.signed
insinto /usr/share/cachyos-eac
doins usr/share/cachyos-eac/cachyos-eac-ca.{crt,der}
# Only used by `sbctl enroll-keys --custom` with sbctl's default keydir; eac-boot enroll reads the copy above.
insinto /var/lib/sbctl/keys/custom/db
doins var/lib/sbctl/keys/custom/db/cachyos-eac-ca.der
@@ -72,7 +90,7 @@ src_install() {
pkg_postinst() {
depmod -b "${EROOT:-/}" "${MY_KV}" || die
if [[ -z ${ROOT} && -d $(eac-boot esp 2>/dev/null)/EFI/cachyos-eac ]]; then
if [[ -z ${ROOT} && -f $(eac-boot loader 2>/dev/null) ]]; then
eac-boot update || ewarn "eac-boot update failed, run it by hand"
else
elog "First-time setup: eac-boot enroll, eac-boot setup, then enable Secure Boot."
@@ -83,5 +101,6 @@ pkg_postinst() {
pkg_postrm() {
# depmod output is not owned by the package
[[ -d ${EROOT}/lib/modules/${MY_KV}/kernel ]] || rm -rf "${EROOT}/lib/modules/${MY_KV}"
[[ -n ${MODULES_DIR} && ! -d ${EROOT}${MODULES_DIR}/${MY_KV}/kernel ]] || return 0
rm -rf "${EROOT}${MODULES_DIR}/${MY_KV}"
}
@@ -4,10 +4,10 @@ Repackages the CachyOS Easy Anti-Cheat Linux v2 boot chain unchanged:
| From CachyOS | Installed to |
|---|---|
| `linux-cachyos-eac` (kernel + signed modules) | `/lib/modules/<ver>-cachyos-eac/` (kernel at `vmlinuz`) |
| `linux-cachyos-eac` (kernel + signed modules) | `<modules>/<ver>-cachyos-eac/` (kernel at `vmlinuz`); `<modules>` is kmod's `module_directory`, `/lib/modules` on Gentoo |
| `systemd-boot-cachyos-signed` | `/usr/lib/cachyos-eac/systemd-bootx64.efi.signed` |
| `cachyos-eac-signing-key` (CachyOS EAC CA) | `/usr/share/cachyos-eac/`, `/var/lib/sbctl/keys/custom/db/` |
| `eac-status` from `cachyos-settings` | `/usr/sbin/eac-status` (ESP lookup patched to `eac-boot esp`) |
| `eac-status` from `cachyos-settings` | `/usr/sbin/eac-status` (ESP, kernel and loader paths patched to ask `eac-boot`) |
The kernel is not handled by installkernel or uefi-mkconfig, and nothing is
re-signed. A second signature, or a kernel started without the CachyOS-signed
@@ -17,37 +17,57 @@ systemd-boot, fails the EAC checks.
| Command | Does |
|---|---|
| `eac-boot enroll` | rewrites the Secure Boot db as: your sbctl db key, the Microsoft certificates, the CachyOS EAC CA |
| `eac-boot setup [bootnum]` | `update`, then creates the `CachyOS EAC` firmware entry and puts it at the end of BootOrder; `bootnum` (4 hex digits) replaces the entry with that number |
| `eac-boot enroll` | appends the CachyOS EAC CA to the Secure Boot db, signed with your KEK; every other entry stays |
| `eac-boot setup [bootnum]` | `update`, then creates the firmware entry and puts it at the end of BootOrder; `bootnum` (4 hex digits) replaces the entry with that number |
| `eac-boot update` | dracut initramfs, kernel and systemd-boot to the ESP, writes the loader entry |
| `eac-boot boot` | sets BootNext to the EAC entry and reboots |
| `eac-boot cmdline` | prints the EAC entry's kernel command line |
| `eac-boot esp` | prints the ESP mount point |
| `eac-boot boot` | starts the EAC entry once (BootNext, and systemd-boot's one-shot entry) and reboots |
| `eac-boot cmdline`, `esp`, `kernel-dir`, `loader` | print the command line and the paths in use |
ESP layout (same as CachyOS with Limine, which `eac-status` checks):
ESP layout with the defaults:
```
<esp>/<machine-id>/linux-cachyos-eac/{vmlinuz,initramfs}
<esp>/EFI/cachyos-eac/systemd-bootx64.efi
<esp>/<machine-id>/linux-cachyos-eac/{vmlinuz,initramfs} KERNEL_DIR
<esp>/EFI/cachyos-eac/systemd-bootx64.efi LOADER_DIR
<esp>/loader/entries/cachyos-eac.conf ENTRY
<esp>/loader/loader.conf
<esp>/loader/entries/cachyos-eac.conf
```
Settings:
`<esp>/loader/` is where every systemd-boot looks, whatever its own directory.
If the ESP already has a `loader.conf` from another systemd-boot, it is kept;
`eac-boot boot` then picks the EAC entry through `LoaderEntryOneShot`.
- `EAC_ESP`: ESP mount point. Default: the first vfat mount of `/efi`, `/boot/efi`, `/boot`.
- `/etc/kernel/cmdline`: base kernel command line. Default: `/proc/cmdline`.
The EAC options are appended.
## Settings: `/etc/eac-boot.conf`
Shell `KEY=value` lines, all optional:
| Key | Default |
| --- | --- |
| `ESP` | first vfat mount of `/efi`, `/boot/efi`, `/boot` |
| `KERNEL_DIR` | `<machine-id>/linux-cachyos-eac` (relative to the ESP) |
| `LOADER_DIR` | `EFI/cachyos-eac` (relative to the ESP) |
| `ENTRY` | `cachyos-eac.conf` |
| `LABEL` | `CachyOS EAC` (firmware entry name) |
| `CMDLINE` | `/etc/kernel/cmdline`, else `/proc/cmdline`; the EAC options are appended |
| `MODULES_DIR` | kmod's `module_directory` |
| `KEK_KEY`, `KEK_CERT` | `KEK/KEK.key`, `KEK/KEK.pem` in sbctl's `keydir` (`/etc/sbctl/sbctl.conf`, default `/var/lib/sbctl/keys`) |
| `OWNER_GUID` | sbctl's GUID file, else random |
`eac-status` checks the kernel only under `KERNEL_DIR` and the loader only
under `LOADER_DIR`, and expects the kernel modules where kmod looks for them.
After the first `setup`, every package update runs `eac-boot update` from
`pkg_postinst`.
`pkg_postinst`. Changing `KERNEL_DIR`, `LOADER_DIR`, `ENTRY` or `LABEL` after
`setup` leaves the old files and firmware entry behind: remove them by hand.
## One-time setup
1. `eac-boot enroll`: the db needs your own `Database Key`, the Microsoft
certificates and `CachyOS EAC CA`. It is written with your sbctl KEK, so
Setup Mode is not needed. Do not use `sbctl enroll-keys --append`: it adds
every key again, and the firmware keeps the duplicates.
1. `eac-boot enroll`: appends `CachyOS EAC CA` to db with an authenticated
write signed by your KEK, so Setup Mode is not needed and nothing else in
db changes: your own keys, Microsoft's and any other vendor's stay. Run it
again and it sees the CA and does nothing. Do not use
`sbctl enroll-keys --append`: it re-adds sbctl's keys and the Microsoft
certificates, and the firmware keeps the duplicates. To remove duplicates
that are already there, see the troubleshooting doc.
`sbctl list-enrolled-keys` prints the issuer of each certificate, so some
names appear twice in a correct db.
2. Your normal kernels must be signed with the sbctl db key. With `USE=secureboot`
@@ -1,34 +1,55 @@
#!/usr/bin/env bash
# Boot chain for linux-cachyos-eac: CachyOS-signed systemd-boot on the ESP,
# started once through its own firmware entry (BootNext).
# Settings: /etc/eac-boot.conf (KEY=value), documented in the README.
set -euo pipefail
EAC_OPTS="lockdown=integrity lsm=landlock,lockdown,yama,integrity,bpf iommu.passthrough=0 intel_iommu=on module.sig_enforce=1 sysctl.kernel.kexec_load_disabled=1"
LABEL="CachyOS EAC"
SDBOOT=/usr/lib/cachyos-eac/systemd-bootx64.efi.signed
CA=/usr/share/cachyos-eac/cachyos-eac-ca
LOADER_GUID=4a67b082-0a4c-41cf-b6c7-440b29bb8c4f
EFIVARS=/sys/firmware/efi/efivars
die() { echo "eac-boot: $*" >&2; exit 1; }
sbctl_conf() { sed -n "s/^$1: *//p" /etc/sbctl/sbctl.conf 2>/dev/null | head -n1; }
ESP= KERNEL_DIR= LOADER_DIR=EFI/cachyos-eac ENTRY=cachyos-eac.conf LABEL="CachyOS EAC" CMDLINE=
MODULES_DIR=$(pkg-config --variable=module_directory kmod 2>/dev/null || true)
KEYDIR=$(sbctl_conf keydir)
KEK_KEY=${KEYDIR:-/var/lib/sbctl/keys}/KEK/KEK.key
KEK_CERT=${KEYDIR:-/var/lib/sbctl/keys}/KEK/KEK.pem
OWNER_GUID=
[[ -r /etc/eac-boot.conf ]] && . /etc/eac-boot.conf
MODULES_DIR=${MODULES_DIR:-/lib/modules}
KERNEL_DIR=${KERNEL_DIR:-$(</etc/machine-id)/linux-cachyos-eac}
[[ $ENTRY =~ ^[A-Za-z0-9._-]+\.conf$ ]] || die "ENTRY must be a file name ending in .conf: $ENTRY"
esp() {
local d
for d in ${EAC_ESP:-} /efi /boot/efi /boot; do
for d in $ESP /efi /boot/efi /boot; do
[[ $(findmnt -no FSTYPE --mountpoint "$d" 2>/dev/null) == vfat ]] && { echo "$d"; return; }
done
die "no mounted vfat ESP found, set EAC_ESP"
die "no mounted vfat ESP found, set ESP in /etc/eac-boot.conf"
}
kernel_dir() { echo "$(esp)/$KERNEL_DIR"; }
loader() { echo "$(esp)/$LOADER_DIR/systemd-bootx64.efi"; }
kver() {
local k
k=$(ls -d /lib/modules/*-cachyos-eac 2>/dev/null | sort -V | tail -n1) || true
[[ -f $k/vmlinuz ]] || die "no linux-cachyos-eac kernel in /lib/modules"
k=$(ls -d "$MODULES_DIR"/*-cachyos-eac 2>/dev/null | sort -V | tail -n1) || true
[[ -f $k/vmlinuz ]] || die "no linux-cachyos-eac kernel in $MODULES_DIR"
echo "${k##*/}"
}
# Base command line from /etc/kernel/cmdline or the running system, plus the EAC options.
# Base command line (CMDLINE, /etc/kernel/cmdline or the running system), plus the EAC options.
cmdline() {
local src=/proc/cmdline opt out=()
[[ -f /etc/kernel/cmdline ]] && src=/etc/kernel/cmdline
for opt in $(<"$src"); do
local base=$CMDLINE opt out=()
if [[ -z $base ]]; then
if [[ -f /etc/kernel/cmdline ]]; then base=$(</etc/kernel/cmdline); else base=$(</proc/cmdline); fi
fi
for opt in $base; do
case $opt in BOOT_IMAGE=*|initrd=*) continue ;; esac
[[ " $EAC_OPTS " == *" $opt "* ]] && continue
out+=("$opt")
@@ -41,28 +62,60 @@ bootnum() {
}
update() {
local esp kv mid dir
local esp kv dir conf
esp=$(esp)
kv=$(kver)
mid=$(</etc/machine-id)
dir=$esp/$mid/linux-cachyos-eac
mkdir -p "$dir" "$esp/EFI/cachyos-eac" "$esp/loader/entries"
dir=$esp/$KERNEL_DIR
mkdir -p "$dir" "$esp/$LOADER_DIR" "$esp/loader/entries"
dracut --force --hostonly --kver "$kv" "$dir/initramfs.new"
install -m644 "/lib/modules/$kv/vmlinuz" "$dir/vmlinuz.new"
install -m644 "$MODULES_DIR/$kv/vmlinuz" "$dir/vmlinuz.new"
mv -f "$dir/initramfs.new" "$dir/initramfs"
mv -f "$dir/vmlinuz.new" "$dir/vmlinuz"
install -m644 "$SDBOOT" "$esp/EFI/cachyos-eac/systemd-bootx64.efi"
install -m644 "$SDBOOT" "$esp/$LOADER_DIR/systemd-bootx64.efi"
printf 'title CachyOS (EAC)\nlinux /%s/linux-cachyos-eac/vmlinuz\ninitrd /%s/linux-cachyos-eac/initramfs\noptions %s\n' \
"$mid" "$mid" "$(cmdline)" > "$esp/loader/entries/cachyos-eac.conf"
printf 'default cachyos-eac.conf\ntimeout 0\n' > "$esp/loader/loader.conf"
printf 'title CachyOS (EAC)\nlinux /%s/vmlinuz\ninitrd /%s/initramfs\noptions %s\n' \
"$KERNEL_DIR" "$KERNEL_DIR" "$(cmdline)" > "$esp/loader/entries/$ENTRY"
# loader.conf is shared by every systemd-boot on this ESP: only write our own.
conf=$(printf 'default %s\ntimeout 0\n' "$ENTRY")
if [[ ! -e $esp/loader/loader.conf || $(<"$esp/loader/loader.conf") == "$conf" ]]; then
printf '%s\n' "$conf" > "$esp/loader/loader.conf"
else
echo "eac-boot: kept the existing $esp/loader/loader.conf; eac-boot boot selects $ENTRY once"
fi
echo "eac-boot: $kv installed to $dir"
}
# The whole db is rewritten: sbctl --append adds every key again, and firmware keeps duplicates.
# Same file contents as a certificate in a signature database variable?
in_sigdb() {
local var=$1 der=$2 f
efi-readvar -v "$var" -o "$tmp/$var.esl" >/dev/null
(cd "$tmp" && sig-list-to-certs "$var.esl" "$var" >/dev/null 2>&1) || true
for f in "$tmp/$var"-*.der; do
[[ -f $f ]] && cmp -s "$f" "$der" && return 0
done
return 1
}
# Appends only the CachyOS EAC CA. Every other db entry stays, and nothing is added twice.
enroll() {
sbctl enroll-keys --partial db --microsoft --custom --ignore-immutable
tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT
if in_sigdb db "$CA.der"; then
echo "eac-boot: the CachyOS EAC CA is already in db, nothing to do"
return
fi
[[ -r $KEK_KEY && -r $KEK_CERT ]] || die "KEK key or certificate not found ($KEK_KEY, $KEK_CERT); set KEK_KEY and KEK_CERT in /etc/eac-boot.conf"
openssl x509 -in "$KEK_CERT" -outform DER -out "$tmp/kek.der"
in_sigdb KEK "$tmp/kek.der" || die "$KEK_CERT is not enrolled in KEK, so the firmware would reject the update"
local guid=${OWNER_GUID:-$(cat "$(sbctl_conf guid)" 2>/dev/null || cat /proc/sys/kernel/random/uuid)}
cert-to-efi-sig-list -g "$guid" "$CA.crt" "$tmp/ca.esl" >/dev/null
sign-efi-sig-list -a -g "$guid" -c "$KEK_CERT" -k "$KEK_KEY" db "$tmp/ca.esl" "$tmp/ca.auth" >/dev/null
chattr -i "$EFIVARS/db-d719b2cb-3d3a-4596-a3bc-dad00e67656f" 2>/dev/null || true
efi-updatevar -a -f "$tmp/ca.auth" db
in_sigdb db "$CA.der" || die "the firmware did not take the CachyOS EAC CA"
echo "eac-boot: appended the CachyOS EAC CA to db; existing entries were kept"
}
# With a boot number, the entry is created there and replaces the entry that has it.
@@ -93,7 +146,7 @@ create() {
local have=$1 want=$2 old esp src
[[ -n $have ]] && efibootmgr -b "$have" -B >/dev/null
if [[ -n $want ]]; then
old=$(efibootmgr | sed -n "s/^Boot$want\*\{0,1\} \([^ ]*\).*/\1/p")
old=$(efibootmgr | sed -n "s/^Boot$want\*\{0,1\} \([^\t]*\).*/\1/p")
if [[ -n $old ]]; then
efibootmgr -b "$want" -B >/dev/null
echo "eac-boot: removed Boot$want \"$old\""
@@ -103,24 +156,37 @@ create() {
src=$(findmnt -no SOURCE --mountpoint "$esp")
efibootmgr --create-only ${want:+--bootnum "$want"} --disk "/dev/$(lsblk -no PKNAME "$src")" \
--part "$(<"/sys/class/block/${src##*/}/partition")" \
--label "$LABEL" --loader '\EFI\cachyos-eac\systemd-bootx64.efi' >/dev/null
--label "$LABEL" --loader "\\${LOADER_DIR//\//\\}\\systemd-bootx64.efi" >/dev/null
echo "eac-boot: created firmware entry Boot$(bootnum) \"$LABEL\""
}
# systemd-boot reads LoaderEntryOneShot (UTF-16LE, NUL-terminated) and deletes it.
oneshot() {
local var=$EFIVARS/LoaderEntryOneShot-$LOADER_GUID tmp i data='\x07\x00\x00\x00'
for ((i = 0; i < ${#ENTRY}; i++)); do data+="${ENTRY:i:1}\\x00"; done
tmp=$(mktemp)
printf "$data"'\x00\x00' > "$tmp"
[[ -e $var ]] && chattr -i "$var" 2>/dev/null
cat "$tmp" > "$var"
rm -f "$tmp"
}
boot() {
local n
n=$(bootnum)
[[ -n $n ]] || die "no \"$LABEL\" firmware entry, run: eac-boot setup"
oneshot
efibootmgr --bootnext "$n" >/dev/null
reboot
}
case ${1:-} in
esp|cmdline) "$1"; exit ;;
esp|cmdline|loader) "$1"; exit ;;
kernel-dir) kernel_dir; exit ;;
esac
[[ $(id -u) == 0 ]] || die "run as root"
case ${1:-} in
enroll|update|boot) "$1" ;;
enroll|update|boot|oneshot) "$1" ;;
setup) setup "${2:-}" ;;
*) echo "usage: eac-boot {enroll|setup [bootnum]|update|boot|cmdline|esp}" >&2; exit 2 ;;
*) echo "usage: eac-boot {enroll|setup [bootnum]|update|boot|cmdline|esp|kernel-dir|loader}" >&2; exit 2 ;;
esac