mirror of
https://github.com/km4ack/patmenu2.git
synced 2025-05-16 06:40:10 -07:00
263 lines
5.1 KiB
Bash
Executable File
263 lines
5.1 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
#script to perform auto connects to gateways
|
|
#using pat winlink
|
|
#20191015 KM4ACK
|
|
|
|
MYPATH=$HOME/patmenu2
|
|
LOGO=$MYPATH/pmlogo.png
|
|
MAIN=$MYPATH/patmenu
|
|
|
|
source $MYPATH/config
|
|
|
|
if [ $RIGCONTROL == 'no' ]
|
|
then
|
|
|
|
yad --title="NO RIG CONTROL" --width=400 --height=100 \
|
|
--image $LOGO --window-icon=$LOGO --image-on-top --text-align=center \
|
|
--center --form --text="\r\r\r\rRig Control is needed for auto pat.\rPlease configure rig control and try again." \
|
|
--button=gtk-ok
|
|
|
|
exit
|
|
fi
|
|
|
|
#Check if FLRIG is running if user has it set in config file
|
|
if [ "$RIGCONTROL" = 'yes' ]; then
|
|
echo "rig control is on"
|
|
FLRIG=$(echo $RIG | grep "\-m 4")
|
|
if [ -z "$FLRIG" ]; then
|
|
echo
|
|
else
|
|
FLRIG=$(pidof flrig)
|
|
if [ -z "$FLRIG" ]; then
|
|
yad --title="FAILED" --width=400 --height=100 \
|
|
--image $LOGO --window-icon=$LOGO --image-on-top --text-align=center \
|
|
--center --form --text="Please start FLRIG and try again" \
|
|
--button=gtk-ok
|
|
exit
|
|
fi
|
|
fi
|
|
fi
|
|
|
|
|
|
|
|
if [ $AMRRON = "no" ]
|
|
then
|
|
|
|
DIRE=$(pidof direwolf)
|
|
if [ -z "$DIRE" ]
|
|
then
|
|
echo
|
|
else
|
|
sudo killall direwolf kissattach
|
|
fi
|
|
|
|
PIARDOPC=$(pidof piardopc)
|
|
if [ -z "$PIARDOPC" ]
|
|
then
|
|
echo
|
|
else
|
|
sudo killall piardopc ardop-GUI
|
|
fi
|
|
|
|
fi
|
|
|
|
#clear any temp files from previous runs that might exist
|
|
rm -rf $HOME/tempardop > /dev/null
|
|
|
|
ARDOPLIST=$MYPATH/ardop-list/
|
|
|
|
touch $LOG
|
|
|
|
DATE=$(date)
|
|
|
|
STARTRIG () {
|
|
#start rigctld if not already
|
|
PIDCTL=$(pidof rigctld)
|
|
WHO=$(whoami)
|
|
if [ -z "$PIDCTL" ]
|
|
then
|
|
CONTROL=$(echo $RIG | sed 's/rigctl/rigctld/')
|
|
$CONTROL &
|
|
sudo systemctl restart pat@$WHO
|
|
fi
|
|
}
|
|
|
|
STARTRIG
|
|
|
|
if [ -z "$PIDCTL" ]
|
|
then
|
|
STARTRIG
|
|
fi
|
|
|
|
SETRIG () {
|
|
|
|
#Set USB Mode
|
|
RIGUSB=$RIG" M $MODEHF 0"
|
|
|
|
#check rig is in USB
|
|
MODE=$($RIG m | grep $MODEHF)
|
|
|
|
sleep 1
|
|
|
|
MODECHECK() {
|
|
#check rig is in correct mode
|
|
MODE=$($RIG m | grep $MODEHF)
|
|
}
|
|
|
|
sleep 1
|
|
|
|
if [ -z $MODE ]
|
|
then
|
|
$RIGUSB
|
|
MODECHECK
|
|
fi
|
|
|
|
}
|
|
|
|
SETRIG
|
|
|
|
#Directions Function
|
|
directions () {
|
|
echo "The script needs two arguments to run."
|
|
echo "It needs the distance that you want to try to connect"
|
|
echo "and it needs the band you wish to use"
|
|
echo "Bands available are 20, 30, 40, & 80"
|
|
echo "The first argument is the distance"
|
|
echo "and the second is the band. So to try all 40M"
|
|
echo "stations in a 300km radius, you would enter"
|
|
echo "autopat 300 40"
|
|
exit 0
|
|
}
|
|
|
|
#check if distance is empty and give direction
|
|
if [ -z "$1" ]
|
|
then
|
|
directions
|
|
fi
|
|
|
|
#check if band is empty and give direction
|
|
if [ -z "$2" ]
|
|
then
|
|
directions
|
|
fi
|
|
|
|
#Check for min distance
|
|
if [ -z "$3" ]
|
|
then
|
|
MIN=0
|
|
else
|
|
MIN=$3
|
|
fi
|
|
|
|
#take $2 as band to use
|
|
if [ $2 = "20" ]
|
|
then
|
|
FILE=$ARDOPLIST"20mardoplist.txt"
|
|
elif [ $2 = "30" ]
|
|
then
|
|
FILE=$ARDOPLIST"30mardoplist.txt"
|
|
elif [ $2 = "40" ]
|
|
then
|
|
FILE=$ARDOPLIST"40mardoplist.txt"
|
|
elif [ $2 = "80" ]
|
|
then
|
|
FILE=$ARDOPLIST"80mardoplist.txt"
|
|
fi
|
|
|
|
#Verify we have a list to work with
|
|
test -f $FILE
|
|
FILERESULT=$(echo $?)
|
|
if [ $FILERESULT = "1" ]
|
|
then
|
|
echo "FILE DOESN'T EXIST."
|
|
yad --title="NO LIST" --width=400 --height=100 \
|
|
--image $LOGO --window-icon=$LOGO --image-on-top --text-align=center \
|
|
--center --form --text="\r\r\rNo list has been downloaded. Auto Pat has no data to work with. Please download the gateway list \
|
|
and try again" \
|
|
--button="Download List":2 \
|
|
--button="Cancel":1
|
|
BUT=$?
|
|
if [ $BUT = 1 ]; then
|
|
exit
|
|
elif [ $BUT = 2 ]; then
|
|
$MYPATH/getardoplist
|
|
$MAIN &
|
|
exit
|
|
fi
|
|
fi
|
|
|
|
if [ $AMRRON = "no" ]
|
|
then
|
|
#start ardop-gui & piardopc
|
|
$ARDOPGUI &
|
|
$ARDOP &
|
|
sleep 10
|
|
fi
|
|
|
|
#Pat Connection Function
|
|
connect () {
|
|
pat connect $CALL
|
|
#Check if connection was successful
|
|
RESULTS=$(echo $?)
|
|
if [ $RESULTS = "0" ]
|
|
then
|
|
echo "A connection was made"
|
|
echo $DATE" "$CALL" Success with autopat" >> $LOG
|
|
|
|
yad --title="SUCCESS" --width=300 --height=100 \
|
|
--image $LOGO --window-icon=$LOGO --image-on-top \
|
|
--center --form --text="Successfully connected with $CALL" \
|
|
--button=gtk-ok
|
|
|
|
if [ $AMRRON = "no" ]
|
|
then
|
|
sudo killall piardopc piARDOP_GUI
|
|
fi
|
|
exit 0
|
|
fi
|
|
}
|
|
|
|
#create temp dir & manipulate file
|
|
mkdir -p $HOME/tempardop/
|
|
#cat file, remove first few lines, remove blanks > NEWFILE NAME
|
|
cat $FILE | tail -n +5 | grep '[^[:blank:]]' > $HOME/tempardop/tempardop.txt
|
|
|
|
#pad with zeros
|
|
while read LINE
|
|
do DISTANCE=$(echo $LINE | awk '{ print $3 }' | sed -e :a -e 's/^.\{1,4\}$/0&/;ta')
|
|
CALL=$(echo $LINE | awk '{ print $11 }')
|
|
echo $DISTANCE" "$CALL >> $HOME/tempardop/tempardop1.txt
|
|
done < $HOME/tempardop/tempardop.txt
|
|
|
|
cat $HOME/tempardop/tempardop1.txt | sort >> $HOME/tempardop/sorted.txt
|
|
|
|
echo "Will Attempt to Connect to This Station"
|
|
#loop through file and find needed station info
|
|
while read LINE
|
|
do DISTANCE=$(echo $LINE | awk '{ print $1 }')
|
|
CALL=$(echo $LINE | awk '{ print $2 }')
|
|
if [ $DISTANCE -lt "$1" ] && [ $DISTANCE -gt "$MIN" ]
|
|
then
|
|
echo "Distance="$DISTANCE " Call="$CALL
|
|
#call the connect funtion
|
|
connect
|
|
fi
|
|
done < $HOME/tempardop/sorted.txt
|
|
|
|
|
|
#remove temp directory & files
|
|
rm -rf $HOME/tempardop
|
|
|
|
if [ $AMRRON = "no" ]
|
|
then
|
|
#Stop ARDOP modem and gui
|
|
sudo killall piardopc piARDOP_GUI
|
|
fi
|
|
|
|
yad --title="NO Connection" --width=400 --height=100 \
|
|
--image $LOGO --window-icon=$LOGO --image-on-top --text-align=center \
|
|
--center --form --text="\r\r\r\rNo Winlink connection was made using the criteria you entered." \
|
|
--button=gtk-ok
|
|
|