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
13 changes: 13 additions & 0 deletions bin/omarchy-channel-set
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,19 @@ templates=$(omarchy_pacman_templates "$platform") || exit 1
[[ -f $templates/pacman-$pacman_channel.conf && -f $templates/mirrorlist-$pacman_channel ]] ||
fail "Omarchy has no $pacman_channel channel for $platform; nothing changed."

# sudo remembers a password per terminal and script(1) opens a new one, so start
# the update's log here: the update this hands off to then asks no second time.
if [[ -z ${OMARCHY_UPDATE_LOGGED:-} ]]; then
# Run under script as omarchy-update runs itself, restoring the caller's SHELL.
if [[ ${SHELL@a} == *x* ]]; then
printf -v script_command 'export SHELL=%q; ' "$SHELL"
else
script_command='unset SHELL; '
fi
script_command+="$(printf '%q ' "$0" "$@"); exit \$?"
exec env OMARCHY_UPDATE_LOGGED=1 SHELL=/usr/bin/bash script -qefc "$script_command" "/tmp/omarchy-update.log"
fi

if [[ $channel == "dev" ]]; then
confirm_dev || { echo "Cancelled."; exit 0; }
dev_checkout="$HOME/omarchy"
Expand Down
5 changes: 4 additions & 1 deletion bin/omarchy-update
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ trap 'exit 129' HUP
trap 'exit 130' INT
trap 'exit 143' TERM

# Where this update's own output starts, past anything a channel switch logged first.
update_log_start=$(stat -c %s /tmp/omarchy-update.log 2>/dev/null || echo 0)

omarchy-update-requires-free-space

# -y skips the start confirmation and, unless the caller set
Expand Down Expand Up @@ -116,7 +119,7 @@ if [[ ${1:-} == "-y" ]] || omarchy-update-confirm; then
omarchy-migrate
omarchy-update-orphan-pkgs -y

omarchy-update-analyze-logs
omarchy-update-analyze-logs "$update_log_start"

# The dev checkout was fast-forwarded and the full upgrade went through, so
# there is no Omarchy update left to show. Rechecking would download every
Expand Down
15 changes: 13 additions & 2 deletions bin/omarchy-update-analyze-logs
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
#!/bin/bash

# omarchy:summary=Check the update log for known failure conditions
# omarchy:args=[start byte]

update_log="/tmp/omarchy-update.log"

# Read only what the update logged, from the offset it passes: a channel switch
# logs its own package transactions ahead of the update's.
log_start=${1:-0}
[[ $log_start =~ ^[0-9]+$ ]] || log_start=0
# A log replaced mid-update is shorter than the offset: read all of it.
(( log_start <= $(stat -c %s "$update_log" 2>/dev/null || echo 0) )) || log_start=0
update_output() {
tail -c "+$((log_start + 1))" "$update_log"
}

# limine-mkinitcpio-hook's Apple Silicon hook announces itself on every ARM
# machine, since pacman prints the description before the hook checks for a Mac,
# but it only builds an initramfs on one.
Expand All @@ -14,8 +25,8 @@ else
fi

# Check for initramfs generation failure
if grep -q "$initcpio_hook" "$update_log"; then
if ! grep -q "Initcpio image generation successful" "$update_log"; then
if update_output | grep -q "$initcpio_hook"; then
if ! update_output | grep -q "Initcpio image generation successful"; then
echo -e '\e[31mError: Initramfs generation may have failed. Review logs before restart.\e[0m'
echo
fi
Expand Down
21 changes: 21 additions & 0 deletions test/shell.d/channel-switch-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,27 @@ for channel in stable rc edge dev; do
pass "$channel runs the refresh hook before the transaction and hands off to one update authorization"
done

# sudo remembers a password per terminal, and script(1) opens a new one: the
# switch starts the update's log before its first sudo, and the update stays in it.
cat >"$SUDO_TEST_ROOT/bin/script" <<'STUB'
#!/bin/bash
printf 'step:script %s\n' "${@: -1}" >>"$SUDO_TEST_LOG"
exec /usr/bin/bash -c "$2"
STUB
chmod +x "$SUDO_TEST_ROOT/bin/script"
reset_boundary
OMARCHY_UPDATE_LOGGED='' run_channel rc || fail "an unlogged rc switch failed" "$(<"$boundary_tmp/output")"
assert_channel_order
python3 - "$SUDO_TEST_LOG" <<'PY' || fail "the switch and its update share one log" "$(<"$SUDO_TEST_LOG")"
import sys
events = open(sys.argv[1]).read().splitlines()
scripts = [i for i, event in enumerate(events) if event.startswith('step:script ')]
assert len(scripts) == 1 and events[scripts[0]] == 'step:script /tmp/omarchy-update.log', events
assert scripts[0] < next(i for i, event in enumerate(events) if event.startswith('sudo ')), events
PY
rm "$SUDO_TEST_ROOT/bin/script"
pass "an unlogged switch logs before its first sudo, so its update asks for the password no second time"

# Every aarch64 platform switches to all four channels, copying its own
# templates.
for platform in aarch64 aarch64-apple; do
Expand Down
2 changes: 2 additions & 0 deletions test/shell.d/channel-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ source "$SHELL_TEST_DIR/fixtures/sudo-boundary-test.sh"
test_tmp="$boundary_tmp"
package_root="$SUDO_TEST_ROOT"
copy_boundary_file bin/omarchy-channel-set
# Stands in for the script(1) log the switch starts, which would carry stderr to stdout.
export OMARCHY_UPDATE_LOGGED=1
python3 - "$SUDO_TEST_ROOT/bin/omarchy-channel-set" "$package_root" <<'PYTHON'
import sys
from pathlib import Path
Expand Down
34 changes: 34 additions & 0 deletions test/shell.d/update-sequence-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"
source "$SHELL_TEST_DIR/fixtures/sudo-boundary-test.sh"
copy_boundary_file bin/omarchy-update
test_tmp="$boundary_tmp"
sed -i "s#/tmp/omarchy-update\.log#$test_tmp/update.log#" "$SUDO_TEST_ROOT/bin/omarchy-update"
stub_bin="$SUDO_TEST_ROOT/bin"

# Every step omarchy-update runs, recorded in order with the unattended flag it
Expand Down Expand Up @@ -52,6 +53,9 @@ fi
if [[ ${0##*/} == "omarchy-shell" ]]; then
printf '%s\n' "$*" >"$STEP_LOG.shell-args"
fi
if [[ ${0##*/} == "omarchy-update-analyze-logs" ]]; then
printf '%s\n' "$*" >"$STEP_LOG.analyze-args"
fi
[[ ${FAILING_STEP:-} != "${0##*/}" ]] || exit 1
STUB
chmod +x "$stub_bin/$step"
Expand Down Expand Up @@ -112,6 +116,36 @@ pass "an unattended update approves orphan removal"
fail "a finished update clears the shell update indicator" "$(cat "$test_tmp/steps.shell-args")"
pass "a finished update clears the shell update indicator without rechecking"

# A channel switch logs its own package transactions first; the log check reads
# only what came after them.
printf 'channel switch output\n' >"$test_tmp/update.log"
run_update -y || fail "an update after a channel switch reports a failure"
[[ $(cat "$test_tmp/steps.analyze-args") == "$(stat -c %s "$test_tmp/update.log")" ]] ||
fail "the log check starts where the update's own output does" "$(cat "$test_tmp/steps.analyze-args")"
rm "$test_tmp/update.log"
run_update -y || fail "an update without a log reports a failure"
[[ $(cat "$test_tmp/steps.analyze-args") == "0" ]] || fail "without a log the check reads from the start"
pass "the update hands the log check the offset its own output starts at"

analyzer_bin="$test_tmp/analyzer-bin"
mkdir -p "$analyzer_bin"
sed "s#/tmp/omarchy-update\.log#$test_tmp/analyze.log#" "$ROOT/bin/omarchy-update-analyze-logs" >"$analyzer_bin/omarchy-update-analyze-logs"
grep -qF "$test_tmp/analyze.log" "$analyzer_bin/omarchy-update-analyze-logs" && ! grep -qF /tmp/omarchy-update.log "$analyzer_bin/omarchy-update-analyze-logs" ||
fail "the log check under test reads the test's log"
printf '#!/bin/bash\nexit 1\n' >"$analyzer_bin/omarchy-hw-aarch64-apple"
chmod +x "$analyzer_bin/"*
analyze() { PATH="$analyzer_bin:$PATH" omarchy-update-analyze-logs "$@"; }
build="(4/9) Updating linux initcpios..."
printf '%s\n' "$build" "==> Initcpio image generation successful" >"$test_tmp/analyze.log"
switch_end=$(stat -c %s "$test_tmp/analyze.log")
printf '%s\n' "$build" "==> ERROR: module not found" >>"$test_tmp/analyze.log"
[[ $(analyze "$switch_end") == *"may have failed"* ]] || fail "a channel switch's successful build hides the update's failed one"
printf '%s\n' "$build" "==> ERROR: module not found" >"$test_tmp/analyze.log"
for start in "" 999999 "a[0]"; do
[[ $(analyze "$start") == *"may have failed"* ]] || fail "an unusable offset (${start:-none}) does not read the whole log"
done
pass "the log check reads only the update's own output, or all of it without a usable offset"

grep -q '^omarchy-update-system-pkgs unattended=1$' "$test_tmp/steps" ||
fail "-y does not mark the update unattended"
run_update </dev/null || fail "a confirmed update reports a failure"
Expand Down