]> Sergey Matveev's repositories - public-inbox.git/blob - scripts/edit-sa-prefs
examples: systemd socket and service definitions for daemons
[public-inbox.git] / scripts / edit-sa-prefs
1 #!/bin/sh
2 # Copyright (C) 2014, Eric Wong <e@80x24.org>
3 # License: GPLv3 or later <http://www.gnu.org/licenses/gpl-3.0.txt>
4 # edit and atomically update ~/.spamasassin/user_prefs safely
5 set -e
6 cd ~/.spamassassin
7 cp user_prefs user_prefs.edit.$$ # don't care if we clobber old files
8
9 # non-blocking lock
10 if ! ln user_prefs.edit.$$ user_prefs.edit
11 then
12         rm user_prefs.edit.$$
13         echo >&2 "we are already editing user_prefs.edit"
14         exit 1
15 fi
16
17 rm user_prefs.edit.$$
18
19 ${VISUAL-vi} user_prefs.edit
20
21 if diff -u user_prefs user_prefs.edit
22 then
23         rm -f user_prefs.edit
24         echo 'no changes'
25         exit 0
26 fi
27
28 # check until we're good or $EDITOR fails
29 while ! spamassassin -p user_prefs.edit --lint
30 do
31         echo >&2 "respawning editor, press Enter to continue"
32         read ignored_var
33         ${VISUAL-vi} user_prefs.edit
34 done
35
36 # atomically replace user_prefs
37 mv user_prefs.edit user_prefs
38 echo '~/.spamassassin/user_prefs updated'