Try to rewrite old-style config files to new-style config files

on upgrade to 6.0. (Not extensively tested yet)

We do this for two reasons:

1) the config file layout is completely different, it's error-prone
and tedious to force the user to manually transfer their customizations
on upgrade;

2) if there are user modifications to the config file, an upgrade triggered
remotely via piaware will prefer to keep the original config file intact
rather than installing the new version, and the old version just won't
work correctly with the new infrastructure.
This commit is contained in:
Oliver Jowett 2021-07-19 15:45:50 +08:00
parent ec69b94544
commit d4b3b03fe0
3 changed files with 178 additions and 0 deletions

View File

@ -4,4 +4,6 @@ debian/lighttpd/* etc/lighttpd/conf-available
bladerf/* usr/share/dump1090-fa/bladerf
debian/start-dump1090-fa usr/share/dump1090-fa/
debian/generate-wisdom usr/share/dump1090-fa/
debian/upgrade-config usr/share/dump1090-fa/
debian/dump1090-fa.default usr/share/dump1090-fa/
starch-benchmark /usr/lib/dump1090-fa/

View File

@ -63,6 +63,17 @@ case "$1" in
fi
fi
# on upgrade from pre-6.0, update the defaults file to the new syntax
if dpkg --compare-versions "$2" lt-nl "6.0"
then
if [ -f /etc/default/dump1090-fa ]
then
echo "Trying to upgrade existing config to new syntax.." >&2
/usr/share/dump1090-fa/upgrade-config /etc/default/dump1090-fa /usr/share/dump1090-fa/dump1090-fa.default \
|| echo "Something went wrong upgrading the config; your config may be broken. Sorry!" >&1
fi
fi
if dpkg --compare-versions "$2" le "5.0"
then
echo "Enabling lighttpd skyaware module.." >&2

165
debian/upgrade-config vendored Executable file
View File

@ -0,0 +1,165 @@
#!/bin/sh
# This script runs during upgrade from pre-6.0 to try to
# update /etc/default/dump1090-fa to the new-style
# config.
if [ $# -lt 2 ]
then
echo "syntax: $0 path-to-config path-to-package-defaults" >&2
exit 2
fi
OLDCONFIG="$1"
NEWCONFIG="${OLDCONFIG}.v6-upgrade"
BACKUPCONFIG="${OLDCONFIG}.pre-v6-upgrade"
PACKAGECONFIG="$2"
if [ ! -f $OLDCONFIG ]
then
echo "$OLDCONFIG does not exist, nothing to upgrade" >&2
exit 0
fi
# Use EXTRA_OPTIONS as a marker for a new-style config file
if grep -q EXTRA_OPTIONS ${OLDCONFIG}
then
echo "$OLDCONFIG seems to already be a new-style config, nothing to upgrade" >&2
exit 0
fi
if [ ! -f $PACKAGECONFIG ]
then
echo "$PACKAGECONFIG does not exist, cannot continue" >&2
exit 1
fi
if [ -f $BACKUPCONFIG ]
then
echo "$BACKUPCONFIG already exists, I'm not going to clobber it" >&2
exit 1
fi
# set some assumed defaults (5.0 dump1090 binary defaults if no command-line options are given)
ENABLED="no"
RECEIVER="rtlsdr"
RECEIVER_SERIAL=""
RECEIVER_GAIN="50"
WISDOM=""
ERROR_CORRECTION="no"
MAX_RANGE=""
NET_RAW_INPUT_PORTS="30001"
NET_RAW_OUTPUT_PORTS="30002"
NET_SBS_OUTPUT_PORTS="30003"
NET_BEAST_INPUT_PORTS="30004,30104"
NET_BEAST_OUTPUT_PORTS="30005"
EXTRAS_NET_RO_SIZE="0"
EXTRAS_NET_RO_INTERVAL="0"
EXTRAS_NET_HEARTBEAT="60"
# read the old config
. "$OLDCONFIG"
# process all the options from the old config file and accumulate settings in env vars
process_options() {
while [ $# -gt 0 ]
do
opt="$1"
shift
case "$opt" in
--device-type) RECEIVER="$1"; shift ;;
--device-index) RECEIVER_SERIAL="$1"; shift ;;
--gain) RECEIVER_GAIN="$1"; shift ;;
--max-range) MAX_RANGE="$1"; shift ;;
--fix) ERROR_CORRECTION="yes" ;;
--net) ;;
--net-ri-port) NET_RAW_INPUT_PORTS="$1"; shift ;;
--net-ro-port) NET_RAW_OUTPUT_PORTS="$1"; shift ;;
--net-sbs-port) NET_SBS_OUTPUT_PORTS="$1"; shift ;;
--net-bi-port) NET_BEAST_INPUT_PORTS="$1"; shift ;;
--net-bo-port) NET_BEAST_OUTPUT_PORTS="$1"; shift ;;
--json-location-accuracy) JSON_LOCATION_ACCURACY="$1"; shift ;;
--wisdom) WISDOM="$1"; shift ;;
--ppm) EXTRAS_PPM="$1"; shift ;;
--net-heartbeat) EXTRAS_NET_HEARTBEAT="$1"; shift ;;
--net-ro-size) EXTRAS_NET_RO_SIZE="$1"; shift ;;
--net-ro-interval) EXTRAS_NET_RO_INTERVAL="$1"; shift ;;
*) EXTRA_OPTIONS="$EXTRA_OPTIONS ${opt}" ;;
esac
done
}
process_options $RECEIVER_OPTIONS $DECODER_OPTIONS $NET_OPTIONS $JSON_OPTIONS
# update EXTRA_OPTIONS for any non-default special settings
if [ "${EXTRAS_PPM:-0}" != "0" ]; then EXTRA_OPTIONS="$EXTRA_OPTIONS --ppm $EXTRAS_PPM"; fi
if [ "${EXTRAS_NET_HEARTBEAT:-60}" != "60" ]; then EXTRA_OPTIONS="$EXTRA_OPTIONS --net-heartbeat $EXTRAS_NET_HEARTBEAT"; fi
if [ "${EXTRAS_NET_RO_SIZE:-1300}" != "1300" ]; then EXTRA_OPTIONS="$EXTRA_OPTIONS --net-ro-size $EXTRAS_NET_RO_SIZE"; fi
if [ "${EXTRAS_NET_RO_INTERVAL:-1300}" != "0.2" ]; then EXTRA_OPTIONS="$EXTRA_OPTIONS --net-ro-interval $EXTRAS_NET_RO_INTERVAL"; fi
# special case for device index 0 (the default)
if [ "${RECEIVER_SERIAL}" = "0" ]; then RECEIVER_SERIAL=""; fi
# special case for ports set to zero (new config uses a blank entry for that)
if [ "${NET_RAW_INPUT_PORTS}" = "0" ]; then NET_RAW_INPUT_PORTS=""; fi
if [ "${NET_RAW_OUTPUT_PORTS}" = "0" ]; then NET_RAW_OUTPUT_PORTS=""; fi
if [ "${NET_SBS_INPUT_PORTS}" = "0" ]; then NET_SBS_OUTPUT_PORTS=""; fi
if [ "${NET_BEAST_INPUT_PORTS}" = "0" ]; then NET_BEAST_INPUT_PORTS=""; fi
if [ "${NET_BEAST_OUTPUT_PORTS}" = "0" ]; then NET_BEAST_OUTPUT_PORTS=""; fi
SEDSCRIPT=$(mktemp -t dump1090XXX.sed)
# set up the sedscript
# nb: all values either derived from env vars or the package defaults,
# except for adaptive gain settings which we default to off on upgraded
# installs. New installs using the package defaults will default to on.
cat >>$SEDSCRIPT <<EOF
s@^ENABLED=.*@ENABLED=${ENABLED}@
s@^RECEIVER=.*@RECEIVER=${RECEIVER}@
s@^RECEIVER_SERIAL=.*@RECEIVER_SERIAL="${RECEIVER_SERIAL}"@
s@^RECEIVER_GAIN=.*@RECEIVER_GAIN=${RECEIVER_GAIN}@
s@^WISDOM=.*@WISDOM=${WISDOM}@
s@^ERROR_CORRECTION=.*@ERROR_CORRECTION=${ERROR_CORRECTION}@
s@^MAX_RANGE=.*@MAX_RANGE=${MAX_RANGE}@
s@^NET_RAW_INPUT_PORTS=.*@NET_RAW_INPUT_PORTS=${NET_RAW_INPUT_PORTS}@
s@^NET_RAW_OUTPUT_PORTS=.*@NET_RAW_OUTPUT_PORTS=${NET_RAW_OUTPUT_PORTS}@
s@^NET_SBS_OUTPUT_PORTS=.*@NET_SBS_OUTPUT_PORTS=${NET_SBS_OUTPUT_PORTS}@
s@^NET_BEAST_INPUT_PORTS=.*@NET_BEAST_INPUT_PORTS=${NET_BEAST_INPUT_PORTS}@
s@^NET_BEAST_OUTPUT_PORTS=.*@NET_BEAST_OUTPUT_PORTS=${NET_BEAST_OUTPUT_PORTS}@
s@^JSON_LOCATION_ACCURACY=.*@JSON_LOCATION_ACCURACY=${JSON_LOCATION_ACCURACY}@
s@^EXTRA_OPTIONS=.*@EXTRA_OPTIONS="$EXTRA_OPTIONS"@
s@^ADAPTIVE_DYNAMIC_RANGE=.*@ADAPTIVE_DYNAMIC_RANGE=no@
s@^ADAPTIVE_BURST=.*@ADAPTIVE_BURST=no@
EOF
# substitute into the standard config file to generate our customized config
if ! sed -f $SEDSCRIPT <$PACKAGECONFIG >$NEWCONFIG
then
echo "Something went wrong trying to upgrade $OLDCONFIG, giving up.." >&2
exit 1
fi
rm $SEDSCRIPT
# back up the old config and install the new config
if ! cp -p $OLDCONFIG $BACKUPCONFIG
then
echo "Something went wrong trying to back up $OLDCONFIG, giving up.." >&2
exit 1
fi
if ! mv $NEWCONFIG $OLDCONFIG
then
echo "Something went wrong trying to install the new version of $NEWCONFIG, giving up.." >&2
exit 1
fi
# all good
cat >&2 <<EOF
Upgraded existing config $OLDCONFIG to the new config syntax.
Please doublecheck that it looks ok!
The old config file has been preserved at $BACKUPCONFIG
EOF
exit 0