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
7 cp user_prefs user_prefs.edit.$$ # don't care if we clobber old files
10 if ! ln user_prefs.edit.$$ user_prefs.edit
13 echo >&2 "we are already editing user_prefs.edit"
19 ${VISUAL-vi} user_prefs.edit
21 if diff -u user_prefs user_prefs.edit
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"
33 ${VISUAL-vi} user_prefs.edit
36 # atomically replace user_prefs
37 mv user_prefs.edit user_prefs
38 echo '~/.spamassassin/user_prefs updated'