Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions bin/omarchy-refresh-limine
Original file line number Diff line number Diff line change
@@ -1,8 +1,32 @@
#!/bin/bash
#!/bin/bash -p

# omarchy:summary=Overwrite the user config for the Limine bootloader and rebuild it.
# omarchy:requires-sudo=true

# Privileged Bash startup prevents BASH_ENV and exported functions from running
# before the environment can be sanitized.
if [[ $- != *p* ]]; then
echo "Refusing an unsafe Bash startup." >&2
exit 126
fi

security_entrypoint=$(/usr/bin/readlink -e -- "${BASH_SOURCE[0]}") || exit 126
source "${security_entrypoint%/*}/omarchy-security-functions" || exit 126
omarchy_security_require_privileged_bash_startup || exit 126
set -e
omarchy_security_sanitize_bash_environment "$0" "$@"
omarchy_security_require_source_root "$0"
# Root copies bootloader config out of $OMARCHY_PATH into /boot, so the same
# source-root rule the other privileged refresh commands apply binds that read
# to the packaged tree (or an omarchy dev link'ed checkout) rather than to
# whatever a caller's environment points at.
omarchy_security_install_sudo_cleanup_traps
omarchy_security_revoke_sudo_timestamp || exit 1
# Authorize once, then run the privileged steps behind the command-scoped sudo
# wrapper so they reuse that timestamp and sudo resolves from a fixed PATH.
/usr/bin/sudo /usr/bin/true || exit 1
omarchy_security_enable_no_update_sudo

legacy_uki="/boot/EFI/Linux/$(cat /etc/machine-id)_linux.efi"

if sudo test -f /boot/EFI/Linux/omarchy_linux.efi && sudo test -f "$legacy_uki"; then
Expand All @@ -11,7 +35,9 @@ if sudo test -f /boot/EFI/Linux/omarchy_linux.efi && sudo test -f "$legacy_uki";
fi
echo "Resetting limine config"

sudo mv /boot/limine.conf /boot/limine.conf.bak
if sudo test -f /boot/limine.conf; then
sudo mv /boot/limine.conf /boot/limine.conf.bak
fi

sudo cp "$OMARCHY_PATH/default/limine/limine.conf" /boot/limine.conf

Expand Down
6 changes: 5 additions & 1 deletion test/shell.d/fixtures/sudo-boundary-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

# Test the real orchestration with fixed privileged paths redirected to harmless
# stand-ins. No host sudo, package transaction, namespace root, or exploit runs.
boundary_tmp=$(mktemp -d)
# copy_boundary_file splices fixture paths into script text, quoted or not, so
# the fixture root must not contain whitespace even if the runner's TMPDIR does.
boundary_tmp_base=${TMPDIR:-/tmp}
[[ $boundary_tmp_base != *[[:space:]]* ]] || boundary_tmp_base=/tmp
boundary_tmp=$(TMPDIR=$boundary_tmp_base mktemp -d)
trap 'rm -rf "$boundary_tmp"' EXIT
export SUDO_TEST_ROOT="$boundary_tmp/omarchy"
export SUDO_TEST_LOG="$boundary_tmp/events"
Expand Down
74 changes: 74 additions & 0 deletions test/shell.d/refresh-limine-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/bin/bash

set -euo pipefail

source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"
source "$SHELL_TEST_DIR/fixtures/sudo-boundary-test.sh"

copy_boundary_file bin/omarchy-refresh-limine

# Keep every bootloader operation inside the fixture. The sudo stand-in logs
# each request and runs only commands against these temporary paths.
boot_dir="$boundary_tmp/boot"
mkdir -p "$boot_dir" "$SUDO_TEST_ROOT/default/limine"
printf 'fixture-machine\n' >"$boundary_tmp/machine-id"
printf 'new limine config\n' >"$SUDO_TEST_ROOT/default/limine/limine.conf"
python3 - "$SUDO_TEST_ROOT/bin/omarchy-refresh-limine" "$boot_dir" "$boundary_tmp/machine-id" <<'PY'
import sys
from pathlib import Path

script, boot_dir, machine_id = map(Path, sys.argv[1:])
text = script.read_text().replace('/boot', str(boot_dir)).replace('/etc/machine-id', str(machine_id))
script.write_text(text)
PY
ln -s test-step "$SUDO_TEST_ROOT/bin/limine-update"
ln -s test-step "$SUDO_TEST_ROOT/bin/limine-snapper-sync"
# The shared fixture stubs cp for update tests; this test needs the real copy
# to verify the staged config reaches its temporary boot directory.
rm "$SUDO_TEST_ROOT/bin/cp"

for initial_config in present missing; do
reset_boundary
rm -f "$boot_dir/limine.conf" "$boot_dir/limine.conf.bak"
if [[ $initial_config == "present" ]]; then
printf 'old limine config\n' >"$boot_dir/limine.conf"
fi

PATH="$SUDO_TEST_ROOT/bin:$PATH" "$SUDO_TEST_ROOT/bin/omarchy-refresh-limine" >"$boundary_tmp/output" 2>&1 ||
fail "refresh failed with $initial_config boot config" "$(<"$boundary_tmp/output")"

[[ $(<"$boot_dir/limine.conf") == "new limine config" ]] || fail "refresh did not copy the default config"
if [[ $initial_config == "present" ]]; then
[[ $(<"$boot_dir/limine.conf.bak") == "old limine config" ]] || fail "refresh did not back up the existing config"
else
[[ ! -e $boot_dir/limine.conf.bak ]] || fail "refresh made a backup without an existing config"
fi

python3 - "$SUDO_TEST_LOG" "$initial_config" "$boot_dir" "$SUDO_TEST_ROOT" <<'PY'
import sys
from pathlib import Path

log, initial_config, boot_dir, root = sys.argv[1:]
events = Path(log).read_text().splitlines()
expected = [
'sudo -k',
'sudo /usr/bin/true',
'sudo -h',
f'sudo -N test -f {boot_dir}/EFI/Linux/omarchy_linux.efi',
f'sudo -N test -f {boot_dir}/limine.conf',
]
if initial_config == 'present':
expected.append(f'sudo -N mv {boot_dir}/limine.conf {boot_dir}/limine.conf.bak')
expected += [
f'sudo -N cp {root}/default/limine/limine.conf {boot_dir}/limine.conf',
'sudo -N limine-update',
'step:limine-update ',
'sudo -N limine-snapper-sync',
'step:limine-snapper-sync ',
'sudo -k',
]
assert events == expected, (events, expected)
PY
assert_boundary_cold "refresh with $initial_config boot config"
pass "refresh with $initial_config boot config copies and rebuilds, then revokes sudo"
done
14 changes: 13 additions & 1 deletion test/shell.d/security-source-root-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,27 @@ pass "a package link must resolve to its named command"
# Run the protected entrypoints themselves with a mismatched root. These must
# stop before any sudo or operational fixture command, not merely validate in
# an isolated library test.
for command in omarchy-update omarchy-refresh-pacman omarchy-update-stay-awake omarchy-channel-set; do
for command in omarchy-update omarchy-refresh-pacman omarchy-update-stay-awake omarchy-channel-set omarchy-refresh-limine; do
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved
rm -f "$SUDO_TEST_ROOT/bin/$command"
copy_boundary_file "bin/$command"
for root in "$boundary_tmp/other-root" .; do
reset_boundary
if OMARCHY_PATH="$root" "$SUDO_TEST_ROOT/bin/$command" >"$boundary_tmp/output" 2>&1; then
fail "$command accepted a mismatched root"
fi
if [[ $command == "omarchy-refresh-limine" ]]; then
grep -q 'OMARCHY_PATH does not match this Omarchy command\.' "$boundary_tmp/output" ||
fail "$command did not report the source-root rejection" "$(<"$boundary_tmp/output")"
fi
[[ ! -s $SUDO_TEST_LOG ]] || fail "$command ran work before rejecting its root"
done
if [[ $command == "omarchy-refresh-limine" ]]; then
reset_boundary
if /usr/bin/bash "$SUDO_TEST_ROOT/bin/$command" -p >"$boundary_tmp/output" 2>&1; then
fail "$command accepted a decoy privileged-mode argument"
fi
[[ ! -s $SUDO_TEST_LOG ]] || fail "$command ran work from an ordinary Bash launch"
pass "$command rejects an ordinary Bash launch before work"
fi
pass "$command rejects mismatched and relative roots before work"
done