diff options
| author | Kévin Le Gouguec <kevin.legouguec@gmail.com> | 2025-11-03 07:48:38 +0100 |
|---|---|---|
| committer | Kévin Le Gouguec <kevin.legouguec@gmail.com> | 2025-11-03 07:48:38 +0100 |
| commit | 0489ee1e567a8a7674fab9b27014b2c3f7383004 (patch) | |
| tree | c9f04497cc680012cfc998950a520704e1af474f /.local/bin/emacs-update-packages | |
| parent | a797c4ad2da63a3f3eebca309a17ec986cc17357 (diff) | |
| download | dotfiles-0489ee1e567a8a7674fab9b27014b2c3f7383004.tar.xz | |
Hide current elpa directory behind a symlink
Simplifies rollbacks: revert symlink to previous directory.
Also,
* make directory names more intuitive: use $(date) for the _new_
directory, instead of the old one;
* write update patches to the new directory, instead of the old one;
* tee update summary to the new directory, so that it survives the
transient shell the update was run from.
Also, ask the augurs why 'test' has both -h and -L for symbolic links,
https://pubs.opengroup.org/onlinepubs/9799919799/utilities/test.html
and get no answer 🤷
Diffstat (limited to '.local/bin/emacs-update-packages')
| -rwxr-xr-x | .local/bin/emacs-update-packages | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/.local/bin/emacs-update-packages b/.local/bin/emacs-update-packages index 2f162a5..ecf5267 100755 --- a/.local/bin/emacs-update-packages +++ b/.local/bin/emacs-update-packages @@ -8,7 +8,15 @@ set -euo pipefail test "${DEBUG:-}" && set -x -BKPDIR=.elpa.$(date +%F-%T) +cd ~/.config/emacs + +test -L elpa || { + echo >&2 "'elpa' directory must be a symlink." + exit 1 +} + +OLDELPADIR=$(readlink elpa) +NEWELPADIR=.elpa.$(date +%F-%T) read-packages () { @@ -57,8 +65,8 @@ compare-packages () # Make a patch for later review. ( set +e - diff > ${BKPDIR}/update-${pkg}.patch \ - -ru ${BKPDIR}/${pkg}-${oldv} elpa/${pkg}-${newv} + diff > ${NEWELPADIR}/update-${pkg}.patch \ + -ru ${OLDELPADIR}/${pkg}-${oldv} ${NEWELPADIR}/${pkg}-${newv} diffstatus=$? @@ -73,15 +81,15 @@ compare-packages () done } -( - cd ~/.config/emacs - cp -a elpa ${BKPDIR} +cp -a ${OLDELPADIR} ${NEWELPADIR} + +declare -A OLDPACKAGES NEWPACKAGES - declare -A OLDPACKAGES NEWPACKAGES +read-packages OLDPACKAGES +ln -fsT ${NEWELPADIR} elpa - read-packages OLDPACKAGES - emacs -f package-upgrade-all -f package-autoremove - read-packages NEWPACKAGES +emacs -f package-upgrade-all -f package-autoremove +read-packages NEWPACKAGES - enum-packages | compare-packages | column -ts$'\t' -) +enum-packages | compare-packages | column -ts$'\t' | + tee ${NEWELPADIR}/update.sum |
