Skip to content

Timestamp the limine and pacman refresh backups - #7998

Open
Adolanium wants to merge 4 commits into
omacom:quattrofrom
Adolanium:refresh-backup-timestamps
Open

Adolanium wants to merge 4 commits into
omacom:quattrofrom
Adolanium:refresh-backup-timestamps

Conversation

@Adolanium

@Adolanium Adolanium commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

omarchy-refresh-limine and omarchy-refresh-pacman both keep a backup of what they replace, at a name that does not change between runs:

# omarchy-refresh-limine
sudo mv /boot/limine.conf /boot/limine.conf.bak

# omarchy-refresh-pacman
sudo cp -f /etc/pacman.conf /etc/pacman.conf.bak
sudo cp -f /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.bak

Run either one twice and the second run overwrites the first run's backup. What is lost is the state the machine was in before any refresh, which is the state someone reaching for a backup usually wants. omarchy-refresh-limine is the worse of the two, because it moves the config rather than copying it, so once the backup is overwritten the original is gone outright.

The sibling scripts already timestamp. omarchy-refresh-config writes <file>.bak.$(date +%s) and omarchy-restart-audio does the same, so recoverable history is the house pattern and these two are the ones that drifted from it.

omarchy-refresh-pacman has a second problem in the same lines. The backups are taken at the top of the file, before the channel argument is checked:

sudo cp -f /etc/pacman.conf /etc/pacman.conf.bak
sudo cp -f /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.bak

channel="${1:-stable}"

if [[ $channel != "stable" && $channel != "rc" && $channel != "edge" ]]; then
  echo "Error: Invalid channel '$channel'. Must be one of: stable, rc, edge"
  exit 1
fi

So omarchy refresh pacman stabel overwrites both backups and then exits without changing anything else. A typo costs you the backups from the previous real run.

What changed: both scripts name their backups <file>.bak.<epoch>, the same form omarchy-refresh-config uses, and omarchy-refresh-pacman checks the channel before it writes anything. The two pacman backups share one timestamp so a pair from the same run stays recognisable as a pair.

Tests: new test/shell.d/refresh-backup-test.sh stubs sudo so the /etc and /boot paths are rerooted into a directory the test owns, which keeps the real ones out of reach. omarchy-hook is stubbed too and HOME points inside the temp tree, because refresh-pacman calls omarchy-hook pre-refresh-pacman and that runs a script from ~/.config/omarchy/hooks through bash. Four cases: two pacman refreshes leave two pacman.conf and two mirrorlist backups with the first run's content still readable and each pair sharing one timestamp, an unknown channel is refused without writing a backup, the hook call is answered by the stub rather than a real hook, and two limine refreshes leave two backups. All 4 pass. Against the original scripts the first case fails reporting no timestamped backup where two were expected, which is the overwrite.

Copilot AI balanced review requested due to automatic review settings August 24, 2026 04:42

Copilot AI left a comment

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.

Pull request overview

Adds timestamped backups for Pacman and Limine refreshes to preserve configuration history.

Changes:

  • Validates Pacman channels before backup creation.
  • Timestamps Pacman and Limine backups.
  • Adds backup retention and invalid-channel tests.

Tip

If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.

Reviewed changes

Copilot reviewed 1 out of 3 changed files in this pull request and generated 2 comments.

File Description
bin/omarchy-refresh-pacman Validates channels and creates paired timestamped backups.
bin/omarchy-refresh-limine Adds timestamped Limine backups.
test/shell.d/refresh-backup-test.sh Tests backup retention and channel rejection.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread test/shell.d/refresh-backup-test.sh Outdated
SH
chmod +x "$stub_bin/sudo"

for tool in limine-update limine-snapper-sync omarchy-update omarchy-pkg-add; do

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Both right, and the first one is the more serious of the two. Fixed in d47a4d3.

omarchy-refresh-pacman:28 calls omarchy-hook pre-refresh-pacman, and omarchy-hook runs $HOME/.config/omarchy/hooks/<name> through bash. The test stubbed neither that nor HOME. It happened not to bite here only because omarchy-hook is not on PATH in my environment and the script has no set -e, so the missing command was shrugged off. On a machine with Omarchy installed it would have run the real hook with no isolation at all.

omarchy-hook is now stubbed alongside the other external commands, and HOME points at an empty directory inside the temp tree for every run, so a hook is unreachable by either route. The stubs also log what they were called with, and there is an assertion that the omarchy-hook pre-refresh-pacman call was answered by the stub. That way the isolation is proven rather than assumed, and if the script later calls something else instead, this test fails and gets looked at again.

Comment thread test/shell.d/refresh-backup-test.sh Outdated
Comment on lines +64 to +69
count=$(backups_in "$root_fs/etc" 'pacman.conf*bak')
(( count == 2 )) ||
fail "two pacman refreshes keep both backups" "got: $count"

grep -rqx 'first pacman conf' "$root_fs/etc"/pacman.conf*bak ||
fail "the first pacman refresh's backup survives the second"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Correct, and it undercut the paired-backup claim in the description. Fixed in d47a4d3.

The mirrorlist now gets the same two checks as pacman.conf: two backups after two runs, and the first run's content still readable in one of them. On top of that, the pairing is checked directly. The stamp is read off each pacman.conf.<stamp>.bak and a mirrorlist.<stamp>.bak is required to exist for it, so either file drifting to its own clock or to a fixed name fails.

Verified it catches what you described: reverting only the mirrorlist line to /etc/pacman.d/mirrorlist.bak and leaving pacman.conf timestamped now fails with "two pacman refreshes keep both mirrorlist backups, got: 1". Against the original scripts the first case still fails at "got: 1".

One aside while I was in here. My earlier check of this test against the old scripts was worthless, because I used git stash on files that were already committed on the branch, so nothing was actually reverted. Redone with git checkout upstream/quattro -- on the two scripts, which is where the failures quoted above come from.

Both scripts wrote a fixed .bak name, so a second run overwrote the backup
from the first and the pre-refresh configuration could not be recovered.
refresh-limine moves rather than copies, so there was nothing else left.

refresh-pacman also took its backups before checking the channel argument,
so an unknown channel spent them on its way to exiting.

Name both <file>.bak.<epoch>, the same form omarchy-refresh-config uses,
and check the channel first. The test reroots /etc and /boot through a
sudo stub, stubs omarchy-hook so a developer's own pre-refresh-pacman hook
never runs, and checks both pacman backups carry the same stamp.
@Adolanium
Adolanium force-pushed the refresh-backup-timestamps branch from d47a4d3 to 441f391 Compare September 1, 2026 20:41
@Adolanium

Copy link
Copy Markdown
Contributor Author

Switched the backup name to <file>.bak.<epoch>, the form omarchy-refresh-config and omarchy-restart-audio already use, instead of adding a third style. The test globs follow. Squashed the test fixup into the main commit.

@omarchybot omarchybot added the bug Something isn't working label Sep 27, 2026
quattro rewrote omarchy-refresh-pacman behind its sudo boundary and already checks the channel before the backups, so the conflict resolves to quattro's script with only the backup names timestamped.

The same rewrite rebuilds PATH around the no-update sudo wrapper, so the test's sudo stub no longer answered the pacman refresh: on a machine with passwordless sudo it would have reached the real /etc and a real pacman -Syyuu. The pacman half now runs on test/shell.d/fixtures/sudo-boundary-test.sh, whose stand-ins replace the fixed privileged paths, with cp rerooted into the test's tree and omarchy-update-pacman a logged no-op.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@omarchybot omarchybot added verified Omarchy Triage has verified that this issue is ready for final review ready Good to merge labels Sep 28, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed and verified on a disposable Omarchy worker. The fix holds on quattro, and I pushed one merge commit (4b8b775) to bring the branch up to date.

The bug is real. On the worker, two refreshes on quattro left a single pacman.conf.bak, mirrorlist.bak and limine.conf.bak, each holding the second run's config, so the first run's backup was gone. On this branch both runs' backups survive, and each pacman pair shares one stamp.

What I pushed, and why. The branch conflicted with quattro, which has since rewritten omarchy-refresh-pacman behind its sudo boundary (bash -p, omarchy-security-functions, the no-update sudo wrapper). quattro also already checks the channel before taking the backups. So the merge keeps quattro's script and changes only the two backup lines to .bak.$stamp. The limine change is yours, unchanged.

The same rewrite rebuilds PATH around the sudo wrapper, so the test's sudo stub no longer answers the pacman refresh. On a machine with passwordless sudo, the test would have written the real /etc and run a real pacman -Syyuu. The pacman half of test/shell.d/refresh-backup-test.sh now uses test/shell.d/fixtures/sudo-boundary-test.sh, which replaces those fixed paths with stand-ins. cp is rerooted into the test's own tree, omarchy-update-pacman becomes a logged no-op, and the hook is answered by the fixture. The limine half keeps your PATH stub, since that script is not hardened.

Tests, on the worker:

  • The new test passes on this head.
  • The same test fails on quattro with only the test file added, which is also this head with the two scripts reverted.
  • channel-test, channel-sudo-boundary-test, update-hook-security-test, update-pacman-test, security-source-root-test, security-entrypoint-symlink-test and privileged-heredoc-test all pass.
  • ./test/cli fails the same three vscode theme checks on quattro as on this head, and nothing else. Those failures are unrelated to this change.

Second opinion: Codex Medium reviewed the merged head read-only and found nothing to change. It agreed that the change is proportionate, the merge resolution is sound under the hardened startup, and the test cannot reach the host or pass on the unfixed scripts. It also noted that epoch-second stamps can still collide if two refreshes land in the same second, the same limit omarchy-refresh-config has. Its independence from my review is not guaranteed.

Nothing is left for you to do. This waits on the maintainer. One overlap to note: #13362 also edits these backup lines in omarchy-refresh-pacman, so whichever lands second will need a small conflict resolved.

@omarchybot omarchybot added ready Good to merge and removed ready Good to merge labels Sep 28, 2026
@omarchybot omarchybot removed ready Good to merge verified Omarchy Triage has verified that this issue is ready for final review labels Oct 10, 2026
omarchybot and others added 2 commits October 11, 2026 01:53
…refresh

quattro taught omarchy-refresh-pacman to pick its templates by platform and to refuse a channel the platform has no templates for, both before the backups are taken. The conflict resolves to quattro's script with only the two backup names timestamped, so a refused channel still writes no backup.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
quattro's pacman-templates-test pins the exact backup commands, so it still expected the fixed .bak names this branch replaces. It now takes the stamp from the run's own log and requires the mirrorlist backup to carry the same one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@omarchybot omarchybot removed the bug Something isn't working label Oct 10, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

This branch conflicted with quattro again, so I pushed a merge (8b2298e) and one test update (cd1efdb). The fix still holds there, verified on a disposable Omarchy worker.

What moved on quattro. omarchy-refresh-pacman now chooses its templates by platform and refuses a channel the platform has no templates for. Both checks run before the backups. The merge keeps that script as it is and changes only the two backup lines to .bak.$stamp, so a refused channel or an unknown platform still writes no backup. The limine change is untouched.

Test update. quattro added test/shell.d/pacman-templates-test.sh, which pins the exact backup commands and so expected the old fixed .bak names. It now reads the stamp from the run's log and requires the pacman.conf and mirrorlist backups to share it.

Tests, on the worker:

  • refresh-backup-test and pacman-templates-test pass on this head. Both fail on quattro with only the tests added, which is this head with the scripts reverted.
  • channel-test, channel-sudo-boundary-test, update-hook-security-test, update-pacman-test, security-source-root-test, security-entrypoint-symlink-test, privileged-heredoc-test, platform-packages-test and limine-defaults-test all pass.
  • ./test/cli passes on this head and on quattro.

Second opinion: Codex Medium reviewed this head read-only. It found no problem with the merge or the test update, and agreed that the change is proportionate and that neither test can pass vacuously. Its independence from my review is not guaranteed. Its one finding is that two refreshes started in the same second would still get the same name. That is the same limit omarchy-refresh-config has, and before this change every second run overwrote the backup, so I left the naming as you chose it.

Classification is unsettled. I classified this as a bug fix. Codex Medium, asked separately, classified it as an enhancement. Reasonable readings differ on whether an overwritten backup is a defect or the old design. The two models disagree, so I removed the bug label and added no class label. This waits on the maintainer to decide what it is. Nothing is left for you to do.

@greptile-apps

greptile-apps Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[Medium impact] Adds timestamped backups to system refresh scripts.

Make backup names collision-safe before merging so quick retries cannot erase the original configuration.

Findings

  1. P1 Quick retries erase backups ▶

Summary

The PR gives Limine and pacman backups timestamped names and adds tests for retained backup history.

  • Limine and pacman refreshes keep timestamped backups.

Channel validation already precedes backups in the supplied base; this PR does not move it.

Reviews (1) · Last reviewed commit: "Expect timestamped backups in the pacman..." · Reviewed by Greptile

# Timestamped, the way omarchy-refresh-config names its backups. A fixed .bak
# name means a second run overwrites the backup from the first, so the config
# the machine booted with before any refresh cannot be recovered.
sudo mv /boot/limine.conf "/boot/limine.conf.bak.$(date +%s)"

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.

P1 Quick retries erase backups

Both refresh scripts still overwrite an earlier backup if two runs reach the backup step within the same second, such as a quick retry after a failed refresh. date +%s gives both runs the same filename, and mv or cp -f replaces the first backup. For omarchy-refresh-limine, this can erase the original configuration entirely.

Use names that cannot collide, while keeping one shared suffix for the pacman pair. Add a repeated-run test with a fixed clock; the current tests use sleep 1 and miss this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants