diff --git a/bin/omarchy-plugin-hold b/bin/omarchy-plugin-hold new file mode 100755 index 000000000000..9c6a9f64ebb1 --- /dev/null +++ b/bin/omarchy-plugin-hold @@ -0,0 +1,26 @@ +#!/bin/bash + +# omarchy:summary=Keep a plugin out of updates that do not name it +# omarchy:group=plugin +# omarchy:args= + +set -euo pipefail + +fail() { + echo "omarchy-plugin-hold: $*" >&2 + exit 1 +} + +if [[ ${1:-} == "-h" || ${1:-} == "--help" ]]; then + echo "Usage: omarchy plugin hold " + exit 0 +fi + +id="${1:-}" +[[ -n $id ]] || fail "plugin id is required" +[[ $id =~ ^[A-Za-z0-9][A-Za-z0-9._-]*$ && $id != *..* ]] || fail "invalid plugin id '$id'" + +held_dir="$HOME/.local/state/omarchy/plugins/held" +mkdir -p "$held_dir" && : >"$held_dir/$id" + +echo "Held $id: plugin updates skip it until: omarchy plugin unhold $id" diff --git a/bin/omarchy-plugin-unhold b/bin/omarchy-plugin-unhold new file mode 100755 index 000000000000..57af72d322b9 --- /dev/null +++ b/bin/omarchy-plugin-unhold @@ -0,0 +1,26 @@ +#!/bin/bash + +# omarchy:summary=Let a held plugin update again +# omarchy:group=plugin +# omarchy:args= + +set -euo pipefail + +fail() { + echo "omarchy-plugin-unhold: $*" >&2 + exit 1 +} + +if [[ ${1:-} == "-h" || ${1:-} == "--help" ]]; then + echo "Usage: omarchy plugin unhold " + exit 0 +fi + +id="${1:-}" +[[ -n $id ]] || fail "plugin id is required" +[[ $id =~ ^[A-Za-z0-9][A-Za-z0-9._-]*$ && $id != *..* ]] || fail "invalid plugin id '$id'" + +held_dir="$HOME/.local/state/omarchy/plugins/held" +rm -f "$held_dir/$id" + +echo "Unheld $id" diff --git a/bin/omarchy-plugin-update b/bin/omarchy-plugin-update index 8dd65ea1cb09..72267c47f6b4 100755 --- a/bin/omarchy-plugin-update +++ b/bin/omarchy-plugin-update @@ -10,6 +10,8 @@ export GIT_TERMINAL_PROMPT=0 export GIT_SSH_COMMAND="${GIT_SSH_COMMAND:-ssh -oBatchMode=yes}" PLUGINS_DIR="$HOME/.config/omarchy/plugins" +# Plugins held with omarchy plugin hold, skipped unless named. +HELD_DIR="$HOME/.local/state/omarchy/plugins/held" ASSUME_YES=0 UPDATED_ANY=0 @@ -114,7 +116,12 @@ if [[ -n $id ]]; then else for dir in "$PLUGINS_DIR"/*/; do [[ -d $dir/.git ]] || continue - targets+=("$(basename "$dir")") + plugin=$(basename "$dir") + if [[ -f $HELD_DIR/$plugin ]]; then + echo "$plugin is held back; run: omarchy plugin unhold $plugin" + continue + fi + targets+=("$plugin") done if (( ${#targets[@]} == 0 )); then echo "No git-managed plugins installed." diff --git a/bin/omarchy-update b/bin/omarchy-update index f8dcdda87600..a798dcf59887 100755 --- a/bin/omarchy-update +++ b/bin/omarchy-update @@ -127,6 +127,19 @@ if [[ ${1:-} == "-y" ]] || omarchy-update-confirm; then omarchy-done mark first-update omarchy-shell -q omarchy.system-update clear + # Plugins are third-party code, so updating them here is opt-in + # (omarchy-toggle update-plugins). The shell restart below loads what changed. + if omarchy-toggle-enabled update-plugins; then + if [[ ${OMARCHY_UPDATE_UNATTENDED:-} == "1" ]]; then + plugin_update_args=(--yes) + else + plugin_update_args=() + fi + if ! omarchy-plugin-update "${plugin_update_args[@]}"; then + echo -e "\e[33m\nSome plugins could not be updated. Review the errors above and run 'omarchy plugin update' to retry.\e[0m" >&2 + fi + fi + # Service restart helpers can need sudo. The reboot-only phase below # performs no privileged work. omarchy-update-restart --services-only diff --git a/docs/update-process.md b/docs/update-process.md index fa0a5eff6eae..63427b395e12 100644 --- a/docs/update-process.md +++ b/docs/update-process.md @@ -133,6 +133,8 @@ omarchy-update ├─ run migrations ├─ automatically remove orphan packages and run log analysis ├─ clear the shell update indicator: the update just installed what it showed + ├─ update git-managed plugins, only when the update-plugins toggle is on (held plugins are skipped) + │ (-y approves each change, a failed plugin warns and the update continues) ├─ restart marked services and the shell ├─ run the post-update hook, then update mise tools (a failed tool update │ warns and the update continues) diff --git a/manual/30-updates.md b/manual/30-updates.md index 01fb326caffe..03074e06d8f0 100644 --- a/manual/30-updates.md +++ b/manual/30-updates.md @@ -20,6 +20,16 @@ Finally, there's the dev channel, which links Omarchy directly to a git checkout You can switch between channels using _Update > Channel_ from the Omarchy menu (or `omarchy channel set ` in the terminal, with `omarchy channel current` to see where you are). +### Updating plugins with Omarchy + +Shell plugins you added with `omarchy plugin add` are not part of an update by default. They are third-party code that runs inside your shell, so Omarchy leaves them to you and `omarchy plugin update`. If you'd rather keep them current with everything else, turn it on once: + +``` +omarchy-toggle update-plugins on +``` + +From then on, `omarchy update` also runs `omarchy plugin update` near the end, before it restarts the shell, so the new plugin code is what comes back up. You still see each plugin's diff and confirm it, unless you run `omarchy update -y`, which approves them. A plugin that fails to update prints a warning, and the rest of the update finishes. Turn it off again with `omarchy-toggle update-plugins off`. To keep a single plugin out of it, use `omarchy plugin hold ` (see the shell plugins chapter). + ### Switching kernels Omarchy boots its own `linux-omarchy` kernel, but you can keep others installed next to it, like the stock Arch `linux` kernel or an experimental build you're testing. When there's more than one, _Update > Kernel_ in the Omarchy menu lists them with a check next to the one that boots by default. Pick another, enter your password once, and it'll boot after the next restart. The other kernels stay in the boot menu, so you can still pick one by hand if the new default gives you trouble. In the terminal, it's `omarchy kernel` to see the current default, `omarchy kernel list` for what's installed, and `omarchy kernel set ` to switch. diff --git a/manual/32-shell-plugins.md b/manual/32-shell-plugins.md index 108c764bb391..2690468723f4 100644 --- a/manual/32-shell-plugins.md +++ b/manual/32-shell-plugins.md @@ -50,7 +50,16 @@ omarchy plugin update acme.weather omarchy plugin update ``` -With no id it updates every git-managed plugin you have. It shows you the diff before applying it, refuses to update if you've got local changes it can't fast-forward past, and rolls back if the new revision fails validation. +With no id it updates every git-managed plugin you have. It shows you the diff before applying it, refuses to update if you've got local changes it can't fast-forward past, and rolls back if the new revision fails validation. To have `omarchy update` do this for you, see _Updating plugins with Omarchy_ in the updates chapter. + +If you need one plugin to stay where it is, because you patched it locally or its latest version broke something, hold it: + +``` +omarchy plugin hold acme.weather +omarchy plugin unhold acme.weather +``` + +A held plugin is skipped by `omarchy plugin update` with no id, and so by `omarchy update` too. Naming it, as in `omarchy plugin update acme.weather`, still updates it, because you asked for that one. ``` omarchy plugin remove acme.weather diff --git a/test/shell.d/plugin-hold-test.sh b/test/shell.d/plugin-hold-test.sh new file mode 100755 index 000000000000..8435c29624c2 --- /dev/null +++ b/test/shell.d/plugin-hold-test.sh @@ -0,0 +1,55 @@ +#!/bin/bash + +set -euo pipefail + +source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh" + +TMPDIR=$(mktemp -d) +trap 'rm -rf "$TMPDIR"' EXIT +mkdir -p "$TMPDIR/bin" +home="$TMPDIR/home" +calls="$TMPDIR/calls" +for id in alpha.one beta.two; do + mkdir -p "$home/.config/omarchy/plugins/$id/.git" +done + +# git reports every plugin up to date and records which one it was asked about. +cat >"$TMPDIR/bin/git" <<'SH' +#!/bin/bash +[[ $1 == "-C" ]] && printf '%s %s\n' "${2##*/}" "$3" >>"$OMARCHY_TEST_CALLS" +[[ $3 == "rev-parse" ]] && echo same +exit 0 +SH +chmod +x "$TMPDIR/bin/git" + +run() { + HOME="$home" OMARCHY_PATH="$ROOT" OMARCHY_TEST_CALLS="$calls" \ + PATH="$TMPDIR/bin:$ROOT/bin:$PATH" "$@" +} + +run omarchy-plugin-hold beta.two >/dev/null +[[ -f $home/.local/state/omarchy/plugins/held/beta.two ]] || fail "hold did not record the plugin" +pass "plugin hold records the plugin" + +: >"$calls" +out=$(run omarchy-plugin-update --yes) +grep -q '^alpha.one fetch' "$calls" || fail "update skipped a plugin that is not held" +! grep -q '^beta.two' "$calls" || fail "update touched a held plugin" +grep -Fq 'beta.two is held back' <<<"$out" || fail "update did not say the plugin is held" +pass "plugin update skips a held plugin and says so" + +: >"$calls" +run omarchy-plugin-update beta.two --yes >/dev/null +grep -q '^beta.two fetch' "$calls" || fail "update by name did not update a held plugin" +pass "plugin update by name still updates a held plugin" + +run omarchy-plugin-unhold beta.two >/dev/null +: >"$calls" +run omarchy-plugin-update --yes >/dev/null +grep -q '^beta.two fetch' "$calls" || fail "unhold did not let the plugin update again" +pass "plugin unhold lets it update again" + +if run omarchy-plugin-hold '../evil' >/dev/null 2>&1; then + fail "hold accepted a path as a plugin id" +fi +pass "plugin hold rejects ids that are not plugin ids" diff --git a/test/shell.d/update-sequence-test.sh b/test/shell.d/update-sequence-test.sh index d17bec2cd351..7855d3c0069c 100755 --- a/test/shell.d/update-sequence-test.sh +++ b/test/shell.d/update-sequence-test.sh @@ -34,6 +34,8 @@ steps=( omarchy-shell omarchy-update-available omarchy-update-restart + omarchy-toggle-enabled + omarchy-plugin-update ) for step in "${steps[@]}"; do @@ -56,6 +58,13 @@ fi if [[ ${0##*/} == "omarchy-update-analyze-logs" ]]; then printf '%s\n' "$*" >"$STEP_LOG.analyze-args" fi +if [[ ${0##*/} == "omarchy-toggle-enabled" ]]; then + printf '%s\n' "$*" >"$STEP_LOG.toggle-args" + [[ ${PLUGIN_UPDATES:-} == 1 ]] || exit 1 +fi +if [[ ${0##*/} == "omarchy-plugin-update" ]]; then + printf '%s\n' "$*" >"$STEP_LOG.plugin-args" +fi [[ ${FAILING_STEP:-} != "${0##*/}" ]] || exit 1 STUB chmod +x "$stub_bin/$step" @@ -77,7 +86,8 @@ steps_run() { } # Every step of a whole update, in order. $1 asks for the one a person confirms; -# an empty $2 leaves out the shell restart, for an update with nothing to migrate. +# an empty $2 leaves out the shell restart, for an update with nothing to migrate; +# $3 asks for the plugin update a person opted into. # Stay Awake bookends the work, so it is here twice. expected_steps() { printf '%s\n' \ @@ -97,6 +107,8 @@ expected_steps() { omarchy-update-analyze-logs \ omarchy-done \ omarchy-shell \ + omarchy-toggle-enabled \ + ${3:+omarchy-plugin-update} \ omarchy-update-restart \ omarchy-hook \ omarchy-update-mise \ @@ -229,3 +241,35 @@ HOME="$restart_home" \ grep -q "update.hyprlandReboot" "$test_tmp/restart-prompts" || fail "omarchy-update-restart offers a reboot when a later Hyprland PID runs a deleted binary" "$(cat "$test_tmp/restart-prompts")" pass "omarchy-update-restart checks every Hyprland PID for a deleted executable" + +# Plugins are third-party code, so the update leaves them alone unless the +# person opted in. When they did, plugins update before the shell restart so the +# restart loads the new code, and a plugin failure never fails the system update. +run_update -y || fail "an update without plugin updates reports a failure" +[[ $(cat "$test_tmp/steps.toggle-args") == "update-plugins" ]] || + fail "the update checks the wrong toggle for plugin updates" "$(cat "$test_tmp/steps.toggle-args")" +if grep -q '^omarchy-plugin-update ' "$test_tmp/steps"; then + fail "an update updates plugins nobody opted into" +fi +pass "an update leaves plugins alone unless the person opted in" + +PLUGIN_UPDATES=1 run_update -y || fail "an opted-in unattended update reports a failure" +diff <(expected_steps "" omarchy-restart-shell plugins) <(steps_run) >"$test_tmp/order" || + fail "an opted-in update does not update plugins before the shell restart" "$(cat "$test_tmp/order")" +[[ $(cat "$test_tmp/steps.plugin-args") == "--yes" ]] || + fail "an unattended update still asks to review plugin changes" "$(cat "$test_tmp/steps.plugin-args")" +pass "an opted-in unattended update approves plugin updates before the shell restart" + +PLUGIN_UPDATES=1 run_update "$test_tmp/order" || + fail "an opted-in confirmed update runs a different set of steps" "$(cat "$test_tmp/order")" +[[ -z $(cat "$test_tmp/steps.plugin-args") ]] || + fail "a confirmed update skips the plugin change review" "$(cat "$test_tmp/steps.plugin-args")" +pass "an opted-in confirmed update lets the person review each plugin change" + +PLUGIN_UPDATES=1 FAILING_STEP=omarchy-plugin-update run_update -y || + fail "a failed plugin update fails the system update" +diff <(expected_steps "" omarchy-restart-shell plugins) <(steps_run) >"$test_tmp/order" || + fail "a failed plugin update skips later update steps" "$(cat "$test_tmp/order")" +grep -q "omarchy plugin update" "$test_tmp/err" || fail "the plugin update failure has no retry guidance" +pass "a plugin failure still finishes the update and explains how to retry"