1
0
mirror of https://github.com/AG7GN/nexus-utilities.git synced 2025-05-18 15:30:12 -07:00

Improved pat config file error checking

This commit is contained in:
Steve Magnuson 2020-07-23 13:41:07 -07:00
parent 19033c1f1b
commit c92e622f9d
2 changed files with 24 additions and 35 deletions

View File

@ -16,7 +16,7 @@
#% #%
#================================================================ #================================================================
#- IMPLEMENTATION #- IMPLEMENTATION
#- version ${SCRIPT_NAME} 1.0.4 #- version ${SCRIPT_NAME} 1.0.6
#- author Steve Magnuson, AG7GN #- author Steve Magnuson, AG7GN
#- license CC-BY-SA Creative Commons License #- license CC-BY-SA Creative Commons License
#- script_id 0 #- script_id 0
@ -317,14 +317,22 @@ else # No configuration files exist
FIRST_RUN=true FIRST_RUN=true
fi fi
# Check for pat's config.json. Create it if necessary # Check for pat's config file, config.json. Create it if missing or corrupted.
if ! [[ -s $PAT_CONFIG ]] RESULT="$(jq . $PAT_CONFIG 2>/dev/null)"
then if [[ $RESULT == "" ]]
then # config.json missing or corrupted. Make a new one.
[[ -f $PAT_CONFIG ]] && rm $PAT_CONFIG
cd $HOME cd $HOME
export EDITOR=ed export EDITOR=ed
echo -n "" | pat configure >/dev/null 2>&1 echo -n "" | pat configure >/dev/null 2>&1
fi 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 -f setARDOPpatDefaults loadpatDefaults
export load_pat_defaults_cmd='@bash -c "setARDOPpatDefaults; loadpatDefaults"' export load_pat_defaults_cmd='@bash -c "setARDOPpatDefaults; loadpatDefaults"'
export PIPEDATA=$PIPE export PIPEDATA=$PIPE
@ -344,20 +352,6 @@ $SYNTAX && set -n
# Run in debug mode, if set # Run in debug mode, if set
$DEBUG && set -x $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 &
timeStamp_PID=$! timeStamp_PID=$!

View File

@ -15,7 +15,7 @@
#% #%
#================================================================ #================================================================
#- IMPLEMENTATION #- IMPLEMENTATION
#- version ${SCRIPT_NAME} 1.6.2 #- version ${SCRIPT_NAME} 1.6.4
#- author Steve Magnuson, AG7GN #- author Steve Magnuson, AG7GN
#- license CC-BY-SA Creative Commons License #- license CC-BY-SA Creative Commons License
#- script_id 0 #- script_id 0
@ -355,14 +355,22 @@ else # No configuration files exist
FIRST_RUN=true FIRST_RUN=true
fi fi
# Check for pat's config.json. Create it if necessary # Check for pat's config file, config.json. Create it if missing or corrupted.
if ! [[ -s $PAT_CONFIG ]] RESULT="$(jq . $PAT_CONFIG 2>/dev/null)"
then if [[ $RESULT == "" ]]
then # config.json missing or corrupted. Make a new one.
[[ -f $PAT_CONFIG ]] && rm $PAT_CONFIG
cd $HOME cd $HOME
export EDITOR=ed export EDITOR=ed
echo -n "" | pat configure >/dev/null 2>&1 echo -n "" | pat configure >/dev/null 2>&1
fi 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 -f setTNCpatDefaults loadpatDefaults
export load_pat_defaults_cmd='@bash -c "setTNCpatDefaults; loadpatDefaults"' export load_pat_defaults_cmd='@bash -c "setTNCpatDefaults; loadpatDefaults"'
export PIPEDATA=$PIPE export PIPEDATA=$PIPE
@ -382,19 +390,6 @@ $SYNTAX && set -n
# Run in debug mode, if set # Run in debug mode, if set
$DEBUG && set -x $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 &
timeStamp_PID=$! timeStamp_PID=$!