viewvcs: handle exceptions in on_destroy cb
[public-inbox.git] / scripts / edit-sa-prefs
blobacaed61029dffe37be7712592771d5bac17d3438
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
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
17 rm user_prefs.edit.$$
19 ${VISUAL-vi} user_prefs.edit
21 if diff -u user_prefs user_prefs.edit
22 then
23 rm -f user_prefs.edit
24 echo 'no changes'
25 exit 0
28 # check until we're good or $EDITOR fails
29 while ! spamassassin -p user_prefs.edit --lint
31 echo >&2 "respawning editor, press Enter to continue"
32 read ignored_var
33 ${VISUAL-vi} user_prefs.edit
34 done
36 # atomically replace user_prefs
37 mv user_prefs.edit user_prefs
38 echo '~/.spamassassin/user_prefs updated'