Files
omarchy/bin/omarchy-update-system-pkgs
T
David Heinemeier HanssonandClaude Fable 5 f5194e3ff5 Shield Omarchy pacman transactions from desktop session teardown
Upgrading systemd runs its post_upgrade scriptlet mid-transaction, which
reexecs both the system manager and every user manager. When pacman runs
inside a user-session scope (the floating update terminal), that reexec
can SIGKILL it and abandon the transaction halfway, with packages
upgraded but none of the post-transaction hooks run.

Route every Omarchy-owned system mutation through a new hidden
omarchy-update-pacman helper that registers the transaction as a PID 1
scope via systemd-run, keeping it out of the user manager's cgroups.
System scopes survive the system manager's own reexec, and as a bonus the
transaction now also survives its terminal window closing. On unbooted
systems (the installer chroot) the helper runs pacman directly.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-09-13 10:21:38 +02:00

40 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
# omarchy:summary=Update system packages with pacman
# omarchy:requires-sudo=true
set -e
# The conflict handler's last resort: pacman puts its questions to the person
# running the update instead of answering them itself. Nothing here may capture
# a stream, because an upgrade without --noconfirm prompts on stderr. The
# handler has already said why, so no heading here either.
if [[ ${OMARCHY_UPDATE_CONFLICT:-} == 1 && ${OMARCHY_UPDATE_INTERACTIVE:-} == 1 ]]; then
exec omarchy-update-pacman -Syu --overwrite '/usr/share/omarchy/*'
fi
echo -e "\e[32m\nUpdate system packages\e[0m"
errors=$(mktemp)
trap 'rm -f "$errors"' EXIT
# /usr/share/omarchy is wholly Omarchy's; files can land there unowned and would
# otherwise abort the upgrade. Packaged content wins there.
#
# Progress bars stay on stdout. Errors are on stderr, kept for the conflict
# handler below; LC_ALL=C is what keeps them parseable in any locale.
if LC_ALL=C omarchy-update-pacman -Syu --noconfirm \
--overwrite '/usr/share/omarchy/*' 2>"$errors"; then
cat "$errors" >&2
exit 0
fi
cat "$errors" >&2
# The handler takes it from here: it clears files pacman doesn't own yet and
# runs this again, and puts a package conflict to whoever started the update.
# Anything else, including a second failure, is for a human.
[[ ${OMARCHY_UPDATE_RETRY:-} != 1 ]] || exit 1
# exec, so the EXIT trap above does not fire and the handler can still read the
# report. It takes over deleting it.
exec env OMARCHY_UPDATE_CONFLICT=1 omarchy-update-system-pkgs-when-conflicted "$errors"