Avoid creating a config file with all blank values if postinst configure fails.

This commit is contained in:
Oliver Jowett 2016-01-25 15:16:41 +00:00
parent 4711eaf741
commit f9aa0398e5

View file

@ -19,19 +19,23 @@ set -e
NAME=dump1090-mutability NAME=dump1090-mutability
CONFIGFILE=/etc/default/$NAME CONFIGFILE=/etc/default/$NAME
SRCCONFIGFILE=$CONFIGFILE
TEMPLATECONFIG=/usr/share/$NAME/config-template TEMPLATECONFIG=/usr/share/$NAME/config-template
CRONFILE=/etc/cron.d/$NAME CRONFILE=/etc/cron.d/$NAME
TEMPLATECRON=/usr/share/$NAME/cron-template TEMPLATECRON=/usr/share/$NAME/cron-template
SEDSCRIPT=$CONFIGFILE.sed.tmp SEDSCRIPT=$CONFIGFILE.sed.tmp
subvar_raw() { subvar_raw() {
# $1 = db var value # $1 = config value
# $2 = config var name # $2 = config var name
# if not present in the config file, add it if ! grep -Eq "^ *$2=" $SRCCONFIGFILE; then
test -z "$1" || grep -Eq "^ *$2=" $CONFIGFILE || echo "$2=" >> $CONFIGFILE # if not present in the config file, add it at the end
# add to the sedscript echo "$a $2=$1" >> $SEDSCRIPT
echo "s@^ *$2=.*@$2=\"$1\"@" >>$SEDSCRIPT else
# otherwise, replace the current value
echo "s@^ *$2=.*@$2=\"$1\"@" >>$SEDSCRIPT
fi
} }
subvar() { subvar() {
@ -52,9 +56,15 @@ case "$1" in
configure) configure)
. /usr/share/debconf/confmodule . /usr/share/debconf/confmodule
# Generate config file, if it doesn't exist. # If we have no config file, start from the template.
if [ ! -e $CONFIGFILE ]; then # Avoid copying the template to the config file
tail -n +4 $TEMPLATECONFIG >$CONFIGFILE # before substitution; this leaves an all-blank config
# in place if something fails, which causes problems
# on subsequent reconfiguration.
SKIPLINES=0
if [ ! -e $SRCCONFIGFILE ]; then
SRCCONFIGFILE=$TEMPLATECONFIG
SKIPLINES=4
fi fi
rm -f $SEDSCRIPT rm -f $SEDSCRIPT
@ -90,8 +100,11 @@ case "$1" in
subvar_yn log-decoded-messages LOG_DECODED_MESSAGES subvar_yn log-decoded-messages LOG_DECODED_MESSAGES
subvar extra-args EXTRA_ARGS subvar extra-args EXTRA_ARGS
cp -a -f $CONFIGFILE $CONFIGFILE.tmp tail -n +$SKIPLINES < $SRCCONFIGFILE | sed -f $SEDSCRIPT > $CONFIGFILE.tmp
sed -f $SEDSCRIPT < $CONFIGFILE > $CONFIGFILE.tmp if [ -e $CONFIGFILE ]; then
chown --reference=$CONFIGFILE $CONFIGFILE.tmp
chmod --reference=$CONFIGFILE $CONFIGFILE.tmp
fi
mv -f $CONFIGFILE.tmp $CONFIGFILE mv -f $CONFIGFILE.tmp $CONFIGFILE
rm $SEDSCRIPT rm $SEDSCRIPT