-
Notifications
You must be signed in to change notification settings - Fork 9
/
autopat-vara
executable file
·245 lines (208 loc) · 5.92 KB
/
autopat-vara
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
#!/bin/bash
#script to perform auto connects to gateways
#using pat winlink and the vara modem
#20220831 KM4ACK
#Most of this code was copied from the autopat script which does
#the same thing using the ARDOP modem.
MYPATH=$HOME/patmenu2
LOGO=$MYPATH/pmlogo.png
MAIN=$MYPATH/patmenu
source $MYPATH/config
#verify we have rig control
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
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
#clear any temp files from previous runs that might exist
rm -rf $HOME/tempardop > /dev/null
VARALIST=$MYPATH/vara-list/
touch $LOG
DATE=$(date)
STARTRIG () {
#start rigctld & restart pat
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 Mode for rigcontrol
$RIG M $MODEHF
}
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=$VARALIST"20mvaralist.txt"
elif [ $2 = "30" ]
then
FILE=$VARALIST"30mvaralist.txt"
elif [ $2 = "40" ]
then
FILE=$VARALIST"40mvaralist.txt"
elif [ $2 = "80" ]
then
FILE=$VARALIST"80mvaralist.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 varaHF modem
echo "Starting VARA-HF modem"
/usr/local/bin/wine $HOME/.wine/drive_c/VARA/VARA.exe > /dev/null 2>&1 &
echo "standby while the modem starts....."
sleep 10 #give vara time to start
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
CALL=$(echo "$CALL" | sed 's/&/ /')
yad --title="SUCCESS" --width=300 --height=100 \
--image $LOGO --window-icon=$LOGO --image-on-top \
--center --form --text="<b>Successfully connected!</b>\r$CALL\r\rSee mylog in documents\rdirectory for more details." \
--button=gtk-ok
if [ $AMRRON = "no" ]
then
sudo killall direwolf piardopc kissattach piARDOP_GUI rigctld > /dev/null 2>&1
VARA=$(ps aux | grep wine | grep VARA | head -1 | awk '{print $2}')
kill -9 $VARA > /dev/null 2>&1
VARA=$(ps aux | grep wine | grep VARA | head -1 | awk '{print $2}')
kill -9 $VARA > /dev/null 2>&1
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
#add speed to line if not in list already
#otherwise the URL is wrong
while read -r line
do
CHECK=$(echo $line | awk '{print $6}')
if [ "$CHECK" = 500 ] || [ "$CHECK" = 2750 ]; then
echo $line >> $HOME/tempardop/temp.txt
else
echo $line | sed 's/VARA/VARA 500/' >> $HOME/tempardop/temp.txt
fi
done < $HOME/tempardop/tempardop.txt
cp $HOME/tempardop/temp.txt $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
sudo killall direwolf piardopc kissattach piARDOP_GUI rigctld > /dev/null 2>&1
sudo rfcomm release /dev/rfcomm0 > /dev/null 2>&1
VARA=$(ps aux | grep wine | grep VARA | head -1 | awk '{print $2}')
kill -9 $VARA > /dev/null 2>&1
VARA=$(ps aux | grep wine | grep VARA | head -1 | awk '{print $2}')
kill -9 $VARA > /dev/null 2>&1
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