Skip to content
Merged
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
91 changes: 24 additions & 67 deletions bin/omarchy-channel-set
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
#!/bin/bash -p
#!/bin/bash

# omarchy:summary=Set the Omarchy package channel.
# omarchy:args=<stable|rc|edge|dev>
# omarchy:requires-sudo=true

if [[ $- != *p* ]]; then
echo "Refusing an unsafe Bash startup for channel switching." >&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 -euo pipefail
omarchy_security_sanitize_bash_environment "$0" "$@"
omarchy_security_require_source_root "$0"
user_path=$PATH
# Traps first, so a signal or failure during the entry revocation still
# exits through the cleanup path.
omarchy_security_install_sudo_cleanup_traps
omarchy_security_revoke_sudo_timestamp || exit 1
omarchy_security_enable_no_update_sudo

# Exit on a signal even while a child survives it, so the switch never runs on.
trap 'exit 129' HUP
trap 'exit 130' INT
trap 'exit 143' TERM

usage() { echo "Usage: omarchy-channel-set [stable|rc|edge|dev]"; }
fail() { echo "Error: $*" >&2; exit 1; }
Expand Down Expand Up @@ -76,10 +66,9 @@ link_dev_checkout() {
validate_dev_region "$checkout"

# Check the destination before changing /etc/omarchy.conf or sudo's path.
# An existing checkout is not pulled automatically and may predate this policy.
for required in bin/omarchy-security-functions bin/omarchy-update bin/omarchy-refresh-pacman default/omarchy/sudo-no-update/sudo; do
if [[ ! -f $checkout/$required || ! -r $checkout/$required ||
( $required != "bin/omarchy-security-functions" && ! -x $checkout/$required ) ]]; then
# An existing checkout is not pulled automatically and may be too old.
for required in bin/omarchy-update bin/omarchy-refresh-pacman; do
if [[ ! -f $checkout/$required || ! -x $checkout/$required ]]; then
fail "Update the checkout before switching to dev; missing required update support in $required."
fi
done
Expand All @@ -104,43 +93,6 @@ link_dev_checkout() {
omarchy-dev-link "$checkout" --no-reboot
}

# A packaged destination cannot be inspected before its package is installed,
# and a package transaction can replace the running tree with a release that
# predates the command-scoped wrapper. After that, a bare sudo would resolve to
# /usr/bin/sudo and publish a timestamp, and the destination's own updater
# authenticates the same way. Neither may run from a flow that has just run
# user hooks: stop at a consistent point and say how to finish from a fresh
# session. That depends on whether the destination's packages are in: a
# transaction before the swap can have replaced the tree too.
stop_for_older_destination() {
local installed listed line
local -a names=()

# omarchy-dev provides omarchy, so this lists whichever pair is installed.
installed=$(pacman -Q omarchy omarchy-settings 2>/dev/null) || true
while read -r line; do
names+=("${line%% *}")
done <<<"$installed"
listed=${installed//$'\n'/, }

if [[ ${names[*]} == "${packages[*]}" ]]; then
cat >&2 <<EOF
The destination predates command-scoped sudo, so this switch stops before its update.
Packages are switched to $listed. Run 'omarchy update' from a new terminal to finish, then reboot if prompted.
EOF
else
cat >&2 <<EOF
A package transaction replaced Omarchy with a release that predates command-scoped sudo, so this switch stops before installing ${packages[*]}.
Installed now: ${listed:-neither omarchy nor omarchy-settings}. Run 'omarchy channel set $channel' from a new terminal to finish, then reboot if prompted.
EOF
fi
exit 3
}

wrapper_present() {
[[ -f $OMARCHY_PATH/default/omarchy/sudo-no-update/sudo && -x $OMARCHY_PATH/default/omarchy/sudo-no-update/sudo ]]
}

(( $# > 0 )) || { usage; exit 1; }

dev_checkout=""
Expand Down Expand Up @@ -196,25 +148,30 @@ fi
if [[ -n $dev_checkout ]]; then
link_dev_checkout "$dev_checkout"
export OMARCHY_PATH="$dev_checkout"
omarchy_security_enable_no_update_sudo
export PATH="$OMARCHY_PATH/bin:$PATH"
omarchy-state set reboot-required
fi

OMARCHY_UPDATE_USER_PATH="$user_path" omarchy-refresh-pacman "$pacman_channel"
# Each transaction can have replaced this tree; check before the next sudo.
wrapper_present || stop_for_older_destination
# --ask 4 accepts omarchy <-> omarchy-dev replacement prompts without file overwrites.
omarchy-update-pacman -S --needed --noconfirm --ask 4 "${packages[@]}"
wrapper_present || stop_for_older_destination
omarchy-refresh-pacman "$pacman_channel"
# The refresh can have installed an older release without this tree's helpers,
# so the swap calls pacman itself. --ask 4 accepts omarchy <-> omarchy-dev
# replacement prompts without file overwrites.
sudo env OMARCHY_UPDATE_PACMAN=1 pacman -S --needed --noconfirm --ask 4 "${packages[@]}"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Shutdown can interrupt the swap

The direct pacman call loses the protection from desktop shutdown that omarchy-update-pacman provided. If the desktop session ends during the swap, it can kill pacman and leave packages partly installed.

Calling pacman directly avoids relying on a helper that an older release may remove. Keep that approach, but copy the helper's use of systemd-run --scope when systemd is running.

Suggested change
sudo env OMARCHY_UPDATE_PACMAN=1 pacman -S --needed --noconfirm --ask 4 "${packages[@]}"
scope=()
if [[ -d /run/systemd/system && ! -L /run/systemd/system ]]; then
scope=(systemd-run --scope --quiet --collect)
fi
sudo env OMARCHY_UPDATE_PACMAN=1 "${scope[@]}" pacman -S --needed --noconfirm --ask 4 "${packages[@]}"

Knowledge Base Used: Update orchestration and system maintenance


if [[ -z $dev_checkout ]]; then
omarchy-dev-unlink --no-reboot
export OMARCHY_PATH=/usr/share/omarchy

if (( leaving_dev )); then
# The packaged commands must win over the unlinked checkout's from here on.
IFS=: read -r -a entries <<<"$PATH"
path=""
for entry in "${entries[@]}"; do
[[ ${entry%/} == "$OMARCHY_PATH/bin" ]] || path+="${path:+:}$entry"
done
export PATH=$path
omarchy-state set reboot-required
fi
omarchy_security_enable_no_update_sudo 2>/dev/null || stop_for_older_destination
export OMARCHY_PATH=/usr/share/omarchy
fi

OMARCHY_UPDATE_USER_PATH="$user_path" "$OMARCHY_PATH/bin/omarchy-update" -y
"$OMARCHY_PATH/bin/omarchy-update" -y
3 changes: 3 additions & 0 deletions bin/omarchy-install-ai-t3-code
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ T3CODE_APPIMAGE="$HOME/.local/share/t3code/T3-Code.AppImage"
t3_cli() {
local mount="" status=0
t3_cli_work=$(mktemp -d)
# The background job creates its output file only once it runs; made here,
# the loop below reads it empty instead of failing on a file not there yet.
: >"$t3_cli_work/mount"
"$T3CODE_APPIMAGE" --appimage-mount >"$t3_cli_work/mount" 2>/dev/null &
t3_cli_mounter=$!
# The runtime stays mounted until killed, and a background job ignores
Expand Down
45 changes: 7 additions & 38 deletions bin/omarchy-refresh-pacman
Original file line number Diff line number Diff line change
@@ -1,28 +1,9 @@
#!/bin/bash -p
#!/bin/bash

# omarchy:summary=Overwrite the package configuration for /etc/pacman with the Omarchy default of using its dedicated mirrors and repositories, then update all packages.
# omarchy:requires-sudo=true

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"
# Channel switching calls this behind its own sanitized PATH and hands the
# caller's original path over the same way the updater receives it.
user_path=${OMARCHY_UPDATE_USER_PATH:-$PATH}
unset OMARCHY_UPDATE_USER_PATH
# Traps first, so a signal or failure during the entry revocation still
# exits through the cleanup path.
omarchy_security_install_sudo_cleanup_traps
omarchy_security_revoke_sudo_timestamp || exit 1
omarchy_security_enable_no_update_sudo

channel="${1:-}"
if [[ -n $channel && $channel != "stable" && $channel != "rc" && $channel != "edge" ]]; then
Expand Down Expand Up @@ -56,15 +37,9 @@ fi

# Render the channel templates plus this machine's regional additions as the
# caller, so root only copies finished files. The scratch directory goes on
# every exit, including a failed render, a refused sudo prompt, or a signal;
# revoking the sudo timestamp stays the last thing the exit path does.
# every exit, including a failed render, a refused sudo prompt, or a signal.
rendered=$(mktemp -d)
cleanup_refresh() {
local status=$?
rm -rf "$rendered"
omarchy_security_exit_with_revoked_sudo "$status"
}
trap cleanup_refresh EXIT
trap 'rm -rf "$rendered"' EXIT
"$OMARCHY_PATH/bin/omarchy-apply-pacman" --render "$channel" "$rendered"

sudo cp -f /etc/pacman.conf /etc/pacman.conf.bak
Expand All @@ -76,20 +51,14 @@ rm -rf "$rendered"

# Allow user customization of /etc/pacman.conf before the upgrade runs, so
# custom repositories and IgnorePkg entries shape the downgrade-capable
# transaction below. The hook is user code: it runs cold behind the no-update
# wrapper, and the timestamp is revoked again afterwards so any authorization
# the hook obtained for itself cannot carry into the transaction.
omarchy_security_revoke_sudo_timestamp
PATH="$OMARCHY_PATH/default/omarchy/sudo-no-update:$user_path" \
"$OMARCHY_PATH/bin/omarchy-hook" pre-refresh-pacman
omarchy_security_revoke_sudo_timestamp
# transaction below.
omarchy-hook pre-refresh-pacman

# Stable and rc publish omarchy and omarchy-settings; the -dev pair is edge's.
# A stable or rc repository can still list an old -dev build (stable's listed
# 4.0.0.r1832 from August to October 2026), and -uu would move an edge machine
# onto it here, before omarchy-channel-set swaps the pair. That build predates
# command-scoped sudo, so the switch would stop short of its swap and leave the
# machine there. The -dev pair is left to the swap.
# onto it here, before omarchy-channel-set swaps the pair, and leave the
# machine on that old build. The -dev pair is left to the swap.
ignore=()
if [[ $channel == "stable" || $channel == "rc" ]]; then
ignore=(--ignore omarchy-dev,omarchy-settings-dev)
Expand Down
33 changes: 1 addition & 32 deletions bin/omarchy-remove-dev-env
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,6 @@ if [[ -z $1 ]]; then
exit 1
fi

cleanup_ocaml_sudo_credentials() {
local status=$?
trap - EXIT HUP INT TERM

if ! /usr/bin/sudo -k >/dev/null 2>&1; then
echo "Failed to invalidate sudo credentials after OCaml removal." >&2
(( status != 0 )) || status=1
fi

exit "$status"
}

begin_ocaml_sudo_boundary() {
trap cleanup_ocaml_sudo_credentials EXIT
trap 'exit 129' HUP
trap 'exit 130' INT
trap 'exit 143' TERM

/usr/bin/sudo -k >/dev/null || {
echo "Unable to start OCaml removal with a cold sudo credential state." >&2
exit 1
}

if ! /usr/bin/sudo -N -V >/dev/null 2>&1; then
echo "This sudo does not support --no-update; refusing to remove OCaml." >&2
exit 1
fi
}

remove_php() {
mise uninstall php --all
mise rm -g php
Expand Down Expand Up @@ -130,12 +101,10 @@ dotnet)
mise rm -g dotnet
;;
ocaml)
begin_ocaml_sudo_boundary

echo -e "Removing OCaml...\n"
opam switch remove default -y 2>/dev/null || true
rm -rf ~/.opam 2>/dev/null || true
if ! /usr/bin/sudo -N -- /usr/bin/rm -f /usr/local/bin/opam; then
if ! sudo rm -f /usr/local/bin/opam; then
echo "Failed to remove the system opam launcher." >&2
exit 1
fi
Expand Down
52 changes: 1 addition & 51 deletions bin/omarchy-security-functions
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

# omarchy:hidden=true
# omarchy:summary=Provide internal helpers for command-scoped sudo authentication
# omarchy:summary=Provide internal helpers for privileged Omarchy entrypoints

if [[ ${BASH_SOURCE[0]} == "$0" ]]; then
echo "omarchy-security-functions is an internal function library." >&2
Expand Down Expand Up @@ -63,62 +63,12 @@ omarchy_security_require_source_root() {
fi
}

omarchy_security_sudo_supports_no_update() {
local help
help=$(LC_ALL=C /usr/bin/sudo -h 2>&1) || return 1
/usr/bin/grep -Eq '^usage: sudo .*\[[^]]*N[^]]*\]' <<< "$help"
}

omarchy_security_revoke_sudo_timestamp() {
/usr/bin/sudo -k
}

omarchy_security_exit_with_revoked_sudo() {
local status=$1
local message=${2:-Could not invalidate cached sudo authorization.}

trap - EXIT HUP INT TERM
if ! omarchy_security_revoke_sudo_timestamp; then
echo "$message" >&2
(( status != 0 )) || status=1
fi
exit "$status"
}

omarchy_security_install_signal_exit_traps() {
trap 'exit 129' HUP
trap 'exit 130' INT
trap 'exit 143' TERM
}

omarchy_security_install_sudo_cleanup_traps() {
OMARCHY_SECURITY_SUDO_CLEANUP_MESSAGE=${1:-Could not invalidate cached sudo authorization.}
trap omarchy_security_run_sudo_cleanup_trap EXIT
omarchy_security_install_signal_exit_traps
}

omarchy_security_enable_no_update_sudo() {
local wrapper_dir="$OMARCHY_PATH/default/omarchy/sudo-no-update"
if ! omarchy_security_sudo_supports_no_update; then
echo "This sudo does not support --no-update; refusing mixed-trust work." >&2
return 1
fi
if [[ ! -f $wrapper_dir/sudo || ! -x $wrapper_dir/sudo ]]; then
echo "The command-scoped sudo wrapper is missing." >&2
return 1
fi
PATH="$wrapper_dir:$OMARCHY_PATH/bin:/usr/bin:/usr/sbin:/bin:/sbin"
OMARCHY_SUDO_NO_UPDATE=1
export PATH OMARCHY_SUDO_NO_UPDATE
}

omarchy_security_run_sudo_cleanup_trap() {
local status=$?

omarchy_security_exit_with_revoked_sudo "$status" \
"${OMARCHY_SECURITY_SUDO_CLEANUP_MESSAGE:-Could not invalidate cached sudo authorization.}"
}

omarchy_security_assert_root_directory() {
local path=$1 expected_mode=$2 canonical owner actual_mode

Expand Down
Loading
Loading