summaryrefslogtreecommitdiff
path: root/.local/bin/emacs-update-packages
blob: 28d231dc679e8c7a2195095c4e95408bf42687c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash

set -euo pipefail
set -x

backup-elpa ()
{
    (
        cd ~/.emacs.d

        # Make a timestamped snapshot for archival.
        tar czf elpa.$(date +%F).tgz elpa

        # Move directory out of Emacs's sight.  We could remove it
        # altogether since we have the archived snapshot; keep it
        # around for the very minor convenience gain.
        rm -rf elpa.bkp
        mv -T elpa elpa.bkp
    )
}

gen-dotemacs ()
{
    # --batch will not read my configuration.  Fall back to print-like
    # functions, redirecting to 'external-debugging-output,
    # redirecting stderr to stdout, and kill-emacs.
    emacs 2>&1 \
          --eval '(pp `(use-package package
                        :custom
                        (package-archives '\''(,@package-archives))
                        (package-selected-packages '\''(,@package-selected-packages)))
                      '\''external-debugging-output)' \
          --funcall kill-emacs
}


cd ~

gen-dotemacs > .emacs.upgrade

backup-elpa
mv .emacs .emacs.bkp

cp .emacs.upgrade .emacs
emacs --funcall package-install-selected-packages

mv .emacs.bkp .emacs