From 14e6d5c3fa18e56d5516f0fca313d60d38e84c32 Mon Sep 17 00:00:00 2001 From: Oliver Jowett Date: Mon, 23 Aug 2021 13:07:05 +0800 Subject: [PATCH] Rearrange config upgrade so upgrading a v6 config file disables adaptive gain. This is needed for the case where a v5 package with an unmodified config file is upgraded. dpkg will install the v6 default config file automatically so it will already be a v6 config by the time that upgrade-config runs, but we do still need to go in and disable adaptive gain. --- debian/upgrade-config | 79 ++++++++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 35 deletions(-) diff --git a/debian/upgrade-config b/debian/upgrade-config index 18973e3..d2ff054 100755 --- a/debian/upgrade-config +++ b/debian/upgrade-config @@ -64,14 +64,8 @@ then fi fi -if [ "$CONFIG_STYLE" = "6" ] -then - echo "$OLDCONFIG seems to already be a new-style config, nothing to upgrade" >&2 - exit 0 -fi - # process all the options from the old config file and accumulate settings in env vars -process_options() { +process_v5_options() { while [ $# -gt 0 ] do opt="$1" @@ -99,36 +93,37 @@ process_options() { *) EXTRA_OPTIONS="$EXTRA_OPTIONS ${opt}" ;; esac done + + # 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 gain -10 -> gain 60 + if [ "${RECEIVER_GAIN}" = "-10" ]; then RECEIVER_GAIN="60"; 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 } -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 gain -10 -> gain 60 -if [ "${RECEIVER_GAIN}" = "-10" ]; then RECEIVER_GAIN="60"; 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 <&2 + + # nb: all values either derived from env vars or the package defaults + process_v5_options $RECEIVER_OPTIONS $DECODER_OPTIONS $NET_OPTIONS $JSON_OPTIONS + FROMCONFIG=$PACKAGECONFIG + cat >>$SEDSCRIPT <&2 +cat >>$SEDSCRIPT <$NEWCONFIG +# substitute into the config file template to generate our customized config +if ! sed -f $SEDSCRIPT <$FROMCONFIG >$NEWCONFIG then echo "Something went wrong trying to upgrade $OLDCONFIG, giving up.." >&2 exit 1