From c92e622f9d1e4368fbb1a46a931d2214a53cf1ec Mon Sep 17 00:00:00 2001 From: Steve Magnuson Date: Thu, 23 Jul 2020 13:41:07 -0700 Subject: [PATCH] Improved pat config file error checking --- ardop_pat_gui.sh | 30 ++++++++++++------------------ dw_pat_gui.sh | 29 ++++++++++++----------------- 2 files changed, 24 insertions(+), 35 deletions(-) diff --git a/ardop_pat_gui.sh b/ardop_pat_gui.sh index 51b3f0b..80f0834 100755 --- a/ardop_pat_gui.sh +++ b/ardop_pat_gui.sh @@ -16,7 +16,7 @@ #% #================================================================ #- IMPLEMENTATION -#- version ${SCRIPT_NAME} 1.0.4 +#- version ${SCRIPT_NAME} 1.0.6 #- author Steve Magnuson, AG7GN #- license CC-BY-SA Creative Commons License #- script_id 0 @@ -317,14 +317,22 @@ else # No configuration files exist FIRST_RUN=true fi -# Check for pat's config.json. Create it if necessary -if ! [[ -s $PAT_CONFIG ]] -then +# Check for pat's config file, config.json. Create it if missing or corrupted. +RESULT="$(jq . $PAT_CONFIG 2>/dev/null)" +if [[ $RESULT == "" ]] +then # config.json missing or corrupted. Make a new one. + [[ -f $PAT_CONFIG ]] && rm $PAT_CONFIG cd $HOME export EDITOR=ed echo -n "" | pat configure >/dev/null 2>&1 fi +# Set up pat for rigctl in config.json +cat $PAT_CONFIG | jq \ + '.hamlib_rigs += {"network": {"address": "localhost:4532", "network": "tcp"}}' | sponge $PAT_CONFIG +# Add the network Hamlib rig to the ardop section +cat $PAT_CONFIG | jq --arg R "network" '.ardop.rig = $R' | sponge $PAT_CONFIG + export -f setARDOPpatDefaults loadpatDefaults export load_pat_defaults_cmd='@bash -c "setARDOPpatDefaults; loadpatDefaults"' export PIPEDATA=$PIPE @@ -344,20 +352,6 @@ $SYNTAX && set -n # Run in debug mode, if set $DEBUG && set -x - -# Set up rig for rigctl in pat -#RIG="$(jq -r '.hamlib_rigs | keys[] as $k | "\($k)"' $PAT_CONFIG)" -RIG="$(jq -r .hamlib_rigs $PAT_CONFIG)" -if [[ $RIG == "{}" ]] -then # No rigs configured. Make a network Hamlib rig - cat $PAT_CONFIG | jq \ - '.hamlib_rigs += {"network": {"address": "localhost:4532", "network": "tcp"}}' | sponge $PAT_CONFIG - # Add the network Hamlib rig to the ax25, winmor, ardop, pactor sections - cat $PAT_CONFIG | jq \ - --arg R "network" \ - '.ax25.rig = $R | .winmor.rig = $R | .ardop.rig = $R | .pactor.rig = $R' | sponge $PAT_CONFIG -fi - timeStamp & timeStamp_PID=$! diff --git a/dw_pat_gui.sh b/dw_pat_gui.sh index 4b91581..8a77003 100755 --- a/dw_pat_gui.sh +++ b/dw_pat_gui.sh @@ -15,7 +15,7 @@ #% #================================================================ #- IMPLEMENTATION -#- version ${SCRIPT_NAME} 1.6.2 +#- version ${SCRIPT_NAME} 1.6.4 #- author Steve Magnuson, AG7GN #- license CC-BY-SA Creative Commons License #- script_id 0 @@ -355,14 +355,22 @@ else # No configuration files exist FIRST_RUN=true fi -# Check for pat's config.json. Create it if necessary -if ! [[ -s $PAT_CONFIG ]] -then +# Check for pat's config file, config.json. Create it if missing or corrupted. +RESULT="$(jq . $PAT_CONFIG 2>/dev/null)" +if [[ $RESULT == "" ]] +then # config.json missing or corrupted. Make a new one. + [[ -f $PAT_CONFIG ]] && rm $PAT_CONFIG cd $HOME export EDITOR=ed echo -n "" | pat configure >/dev/null 2>&1 fi +# Set up pat for rigctl in config.json +cat $PAT_CONFIG | jq \ + '.hamlib_rigs += {"network": {"address": "localhost:4532", "network": "tcp"}}' | sponge $PAT_CONFIG +# Add the network Hamlib rig to the ax25 section +cat $PAT_CONFIG | jq --arg R "network" '.ax25.rig = $R' | sponge $PAT_CONFIG + export -f setTNCpatDefaults loadpatDefaults export load_pat_defaults_cmd='@bash -c "setTNCpatDefaults; loadpatDefaults"' export PIPEDATA=$PIPE @@ -382,19 +390,6 @@ $SYNTAX && set -n # Run in debug mode, if set $DEBUG && set -x -# Set up rig for rigctl in pat -#RIG="$(jq -r '.hamlib_rigs | keys[] as $k | "\($k)"' $PAT_CONFIG)" -RIG="$(jq -r .hamlib_rigs $PAT_CONFIG)" -if [[ $RIG == "{}" ]] -then # No rigs configured. Make a network Hamlib rig - cat $PAT_CONFIG | jq \ - '.hamlib_rigs += {"network": {"address": "localhost:4532", "network": "tcp"}}' | sponge $PAT_CONFIG - # Add the network Hamlib rig to the ax25, winmor, ardop, pactor sections - cat $PAT_CONFIG | jq \ - --arg R "network" \ - '.ax25.rig = $R | .winmor.rig = $R | .ardop.rig = $R | .pactor.rig = $R' | sponge $PAT_CONFIG -fi - timeStamp & timeStamp_PID=$!