-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathFA-functions
709 lines (603 loc) · 22.3 KB
/
FA-functions
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
#functions file for find ardop
#20200425 km4ack
MYPATH=$HOME/patmenu2
MAIN=$MYPATH/./find2
CONFIG=$XDG_CONFIG_HOME/pat/config.json
TEMP=$HOME/patmenu2/tempconfig.txt
TODAY=$(date +%Y%m%d-%R)
WHO=$(whoami)
LASTDL=$(cat $MYPATH/ardop-list/ardoplist.txt | head -1)
LOGO=$MYPATH/pmlogo.png
source $MYPATH/config
#--------------------------------
# MANUAL Download List
#--------------------------------
DOWNLIST(){
$MYPATH/getardoplist
$MAIN &
exit
}
#--------------------------------
# AUTO Download List
#--------------------------------
AUTODOWN(){
FILE=/run/user/$UID/cronbkup.txt
crontab -l > $FILE
HOURS=Disable,At-Boot,00,01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,22,23
MINS=00,15,30,45
TEST=$(yad --center --wrap --width=350 --title="Auto Download" --text-align=center \
--text="Please choose the time you would like to download the gateway list everyday" \
--image $LOGO --window-icon=$LOGO --image-on-top \
--button="Update:2" \
--button="Cancel:1" \
--form --separator="," --item-separator="," \
--field="Choose the hour":CB $HOURS \
--field="Choose the minutes":CB $MINS \
)
rc=$?
if [[ $rc -eq 2 ]]; then
echo "Updating Cron"
HOUR=$(echo $TEST | awk -F ',' '{print $1}')
MIN=$(echo $TEST | awk -F ',' '{print $2}')
sed -i '/getardoplist/d' $FILE
if [ $HOUR = 'At-Boot' ]; then
echo "@reboot sleep 10 && $MYPATH/.getardoplist-cron" >> $FILE
crontab $FILE
echo "Your crontab has been updated. The gateway list"
echo "will be downloaded daily at "$HOUR":"$MIN" hours"
yad --center --timeout=3 --timeout-indicator=top --no-buttons --text="Auto Download set for $HOUR:$MIN daily" \
--image $LOGO --window-icon=$LOGO --image-on-top
$MAIN &
rm $FILE
exit
elif [ $HOUR = 'Disable' ]; then
sed -i s'/getardoplist-cron/d' $FILE
crontab $FILE
yad --center --timeout=3 --timeout-indicator=top --no-buttons --text="Auto Download Disabled" \
--image $LOGO --window-icon=$LOGO --image-on-top
$MAIN & exit
else
echo "$MIN $HOUR * * * $MYPATH/.getardoplist-cron" >> $FILE
#echo $MIN" "$HOUR" * * * $MYPATH/.getardoplist-cron" >> $FILE
crontab $FILE
echo
echo "Your crontab has been updated. The gateway list"
echo "will be downloaded daily at "$HOUR":"$MIN" hours"
yad --center --timeout=3 --timeout-indicator=top --no-buttons --text="Auto Download set for $HOUR:$MIN daily" \
--image $LOGO --window-icon=$LOGO --image-on-top
$MAIN &
rm $FILE
exit
fi
elif [[ $rc -eq 1 ]]; then
echo "BYE"
$MAIN &
exit
fi
}
#--------------------------------
# GRID SEARCH
#--------------------------------
GRIDSEARCH(){
OUTFILE=/run/user/$UID/tempardoplist.txt
CONFIG=$XDG_CONFIG_HOME/pat/config.json
TEMP=/run/user/$UID/tempconfig.txt
ARDOPLIST=$MYPATH/ardop-list
VARALIST=$MYPATH/vara-list
WHO=$(whoami)
source $MYPATH/config #patmenu config file
#check to make sure user has downloaded
if [ ! -d "$MYPATH/ardop-list/" ]; then
yad --title="No List" --width=400 --height=100 \
--image $LOGO --window-icon=$LOGO --image-on-top --text-align=center \
--center --form --text="\r\rGateway list has NOT been downloaded.\rPlease download now\rRecommend setting auto download time" \
--button="Download":2
BUT=$?
if [ $BUT = 2 ]; then
$MYPATH/getardoplist
$MAIN &
exit
elif [ $BUT = 252 ]; then
exit
fi
fi
SEARCHMENU(){
#MENU
BANDS="20|30|40|80|2M-70CM"
SEARCH=$(yad --form --width=400 --text="<b>Find Winlink Gateways</b>" --text-align=center --center --title="Find ARDOP" --text-align=center \
--separator="|" --item-separator="|" \
--image=$LOGO --window-icon=$LOGO --image-on-top \
--field="Choose Modem":CB "VARA|ARDOP" \
--field="Grid to Search" "EM" \
--field="Band to Search":CB "$BANDS" \
--button="Search":2 \
--button="Cancel":1)
QUIT=$?
MODEM=$(echo $SEARCH | awk -F "|" '{print $1}')
GRID=$(echo $SEARCH | awk -F "|" '{print $2}')
GRID=$(echo "${GRID^^}")
BAND=$(echo $SEARCH | awk -F "|" '{print $3}')
echo "Grid search is $GRID"
echo "Band is $BAND"
if [ $QUIT = 1 ]; then
$MAIN &
exit
elif [ $QUIT = 252 ]; then
exit
fi
##############PACKET SEARCH######################
if [ $QUIT = 2 ] && [ "$BAND" = '2M-70CM' ]; then
#########START PACKET SECTION######################
FILE=$MYPATH/ardop-list/packet.txt
TEMP=/run/user/$UID/temppacket.txt
TEMP1=/run/user/$UID/templist.txt
TEMP2=/run/user/$UID/tempalias.txt
echo "Grid search is $GRID"
cat $FILE | egrep -i $GRID[[:digit:]]{2} | tee "$TEMP" > /dev/null 2>&1
INFO=$(PARSER='OFS="\n" {print $1, $2, $3, $4, $5, $6, $7, $9, $11}'
MYTEMP=$TEMP2
tail -1000 $TEMP | awk "$PARSER" | \
yad --title="Search Results" --width=1100 --height=500 \
--image $LOGO --window-icon=$LOGO --image-on-top --multiple \
--center --list --text="Search Results" \
--column Call --column Grid --column Dist \
--column Azm --column Mode --column Speed \
--column Dial-Freq \
--column Center-Freq --column Shortcut \
--button=gtk-close \
--button="Add Alias":2 > $MYTEMP)
BUT=$?
if [ "$BUT" = 2 ];then
CALL=$(echo $INFO | awk -F "|" '{print $1}')
SC=$(echo $INFO | awk -F "|" '{print $9}')
FREQ=$(echo $SC | sed 's/.*=//')
if [ $RIGCONTROL = 'no' ]; then
SC=$(echo $SC | sed 's/[?].*$//')
fi
while read LINE; do
CALL=$(echo $LINE | awk -F "|" '{print $1}')
SC=$(echo $LINE | awk -F "|" '{print $9}')
FREQ=$(echo $SC | sed 's/.*=//')
if [ $RIGCONTROL = 'no' ]; then
SC=$(echo $SC | sed 's/[?].*$//')
fi
SC=$(echo $SC | sed 's/packet/ax25/')
jq '.connect_aliases += {'\""$CALL-$BAND"M"-$FREQ"\"' : '\"$SC\"'}' $CONFIG > $TEMP
cp $TEMP $CONFIG
rm $TEMP
done < $TEMP2
sudo killall pat
sudo systemctl start pat@$WHO
yad --title="ADDED" --width=300 --height=100 \
--image $LOGO --window-icon=$LOGO --image-on-top \
--center --form --text="$CALL-$FREQ added to Pat Winlink\rRefresh Pat Mailbox Window\rto view changes" \
--button=gtk-ok
SEARCHMENU
fi
SEARCHMENU
fi
##############END PACKET SECTION################
#determine which modem was chosen
if [ "$MODEM" = 'ARDOP' ]; then
#############ARDOP SEARCH####################
OUTFILE2=/run/user/$UID/tempardop2.txt
if [ $BAND = 20 ];then
FILE=$ARDOPLIST/20mardoplist.txt
cat $FILE | egrep -i $GRID[[:digit:]]{2} | tee "$OUTFILE" > /dev/null 2>&1
sed -i 's/&/&/g' $OUTFILE > /dev/null 2>&1
elif [ $BAND = 30 ];then
FILE=$ARDOPLIST/30mardoplist.txt
cat $FILE | egrep -i $GRID[[:digit:]]{2} | tee "$OUTFILE" > /dev/null 2>&1
sed -i 's/&/&/g' $OUTFILE > /dev/null 2>&1
elif [ $BAND = 40 ];then
FILE=$ARDOPLIST/40mardoplist.txt
cat $FILE | egrep -i $GRID[[:digit:]]{2} | tee "$OUTFILE" > /dev/null 2>&1
sed -i 's/&/&/g' $OUTFILE > /dev/null 2>&1
elif [ $BAND = 80 ];then
FILE=$ARDOPLIST/80mardoplist.txt
cat $FILE | egrep -i $GRID[[:digit:]]{2} | tee "$OUTFILE" > /dev/null 2>&1
sed -i 's/&/&/g' $OUTFILE > /dev/null 2>&1
echo "80 done"
fi
INFO=$(PARSER='OFS="\n" {print $1, $2, $3, $4, $5, $6, $7, $9, $11}'
MYTEMP=/run/user/$UID/mytemptestardoplist
tail -50 $OUTFILE | awk "$PARSER" | \
yad --title="Search Results" --width=1100 --height=500 \
--image $LOGO --window-icon=$LOGO --image-on-top --multiple \
--center --list --text="Search Results" \
--column Call --column Grid --column Dist \
--column Azm --column Mode --column Speed \
--column Dial-Freq \
--column Center-Freq --column Shortcut \
--button=gtk-close \
--button="Add Alias":2 > $MYTEMP)
BUT=$?
if [ "$BUT" = 2 ];then
CALL=$(echo $INFO | awk -F "|" '{print $1}')
SC=$(echo $INFO | awk -F "|" '{print $9}')
FREQ=$(echo $SC | sed 's/.*=//')
if [ $RIGCONTROL = 'no' ]; then
SC=$(echo $SC | sed 's/[?].*$//')
fi
while read LINE; do
CALL=$(echo $LINE | awk -F "|" '{print $1}')
SC=$(echo $LINE | awk -F "|" '{print $9}' | sed 's/\&/\&/')
FREQ=$(echo $SC | sed 's/.*=//')
if [ $RIGCONTROL = 'no' ]; then
SC=$(echo $SC | sed 's/[?].*$//')
fi
jq '.connect_aliases += {'\""$CALL-$BAND"M"-""ARDOP"\"' : '\"$SC\"'}' $CONFIG > $TEMP
cp $TEMP $CONFIG
rm $TEMP
done < /run/user/$UID/mytemptestardoplist
sudo killall pat
sudo systemctl start pat@$WHO
if [ -z "$CALL" ]; then
yad --title="No Selection" --width=300 --height=100 \
--image $LOGO --window-icon=$LOGO --image-on-top \
--center --form --text="No station was selected\r Please try again" \
--button=gtk-ok
$MAIN &
exit
fi
yad --title="ADDED" --width=300 --height=100 \
--image $LOGO --window-icon=$LOGO --image-on-top \
--center --form --text="Alias added to Pat Winlink\rRefresh Pat Mailbox Window\rto view changes" \
--button=gtk-ok
SEARCHMENU
fi
elif [ "$MODEM" = 'VARA' ]; then
#############VARA SEARCH####################
OUTFILE2=/run/user/$UID/tempardop2.txt
if [ $BAND = 20 ];then
FILE=$VARALIST/20mvaralist.txt
cat $FILE | egrep -i $GRID[[:digit:]]{2} | tee "$OUTFILE" > /dev/null 2>&1
sed -i 's/&/&/g' $OUTFILE > /dev/null 2>&1
elif [ $BAND = 30 ];then
FILE=$VARALIST/30mvaralist.txt
cat $FILE | egrep -i $GRID[[:digit:]]{2} | tee "$OUTFILE" > /dev/null 2>&1
sed -i 's/&/&/g' $OUTFILE > /dev/null 2>&1
elif [ $BAND = 40 ];then
FILE=$VARALIST/40mvaralist.txt
cat $FILE | egrep -i $GRID[[:digit:]]{2} | tee "$OUTFILE" > /dev/null 2>&1
sed -i 's/&/&/g' $OUTFILE > /dev/null 2>&1
elif [ $BAND = 80 ];then
FILE=$VARALIST/80mvaralist.txt
cat $FILE | egrep -i $GRID[[:digit:]]{2} | tee "$OUTFILE" > /dev/null 2>&1
sed -i 's/&/&/g' $OUTFILE > /dev/null 2>&1
echo "80 done"
fi
#remove outfile2 if it exist
if [ -f $OUTFILE2 ]; then
rm $OUTFILE2
fi
#add speed to line if not in list already
while read -r line
do
CHECK=$(echo $line | awk '{print $6}')
if [ "$CHECK" = 500 ] || [ "$CHECK" = 2750 ]; then
echo $line >> $OUTFILE2
else
echo $line | sed 's/VARA/VARA 500/' >> $OUTFILE2
fi
done < $OUTFILE
INFO=$(PARSER='OFS="\n" {print $1, $2, $3, $4, $5, $6, $7, $9, $11}'
MYTEMP=/run/user/$UID/mytemptestardoplist
tail -50 $OUTFILE2 | awk "$PARSER" | \
yad --title="Search Results" --width=1100 --height=500 \
--image $LOGO --window-icon=$LOGO --image-on-top --multiple \
--center --list --text="Search Results" \
--column Call --column Grid --column Dist \
--column Azm --column Mode --column Speed \
--column Dial-Freq \
--column Center-Freq --column Shortcut \
--button=gtk-close \
--button="Add Alias":2 > $MYTEMP)
BUT=$?
if [ "$BUT" = 2 ];then
CALL=$(echo $INFO | awk -F "|" '{print $1}')
SC=$(echo $INFO | awk -F "|" '{print $9}')
FREQ=$(echo $SC | sed 's/.*=//')
if [ $RIGCONTROL = 'no' ]; then
SC=$(echo $SC | sed 's/[?].*$//')
fi
while read LINE; do
CALL=$(echo $LINE | awk -F "|" '{print $1}')
SC=$(echo $LINE | awk -F "|" '{print $9}' | sed 's/\&/\&/')
FREQ=$(echo $SC | sed 's/.*=//')
if [ $RIGCONTROL = 'no' ]; then
SC=$(echo $SC | sed 's/[?].*$//')
fi
jq '.connect_aliases += {'\""$CALL-$BAND"M"-""VARA"\"' : '\"$SC\"'}' $CONFIG > $TEMP
cp $TEMP $CONFIG
rm $TEMP
done < /run/user/$UID/mytemptestardoplist
sudo killall pat
sudo systemctl start pat@$WHO
if [ -z "$CALL" ]; then
yad --title="No Selection" --width=300 --height=100 \
--image $LOGO --window-icon=$LOGO --image-on-top \
--center --form --text="No station was selected\r Please try again" \
--button=gtk-ok
$MAIN &
exit
fi
yad --title="ADDED" --width=300 --height=100 \
--image $LOGO --window-icon=$LOGO --image-on-top \
--center --form --text="Alias added to Pat Winlink\rRefresh Pat Mailbox Window\rto view changes" \
--button=gtk-ok
SEARCHMENU
fi
fi #close modem if/then statement
SEARCHMENU
}
SEARCHMENU
}
#--------------------------------
# Open Map
#--------------------------------
MAP(){
if [ "$MAP" = "usa" ]; then
MAP=$MYPATH/grid-map.pdf
elif [ "$MAP" = "world" ]; then
MAP=$MYPATH/worldgridmap.pdf
fi
xdg-open $MAP
}
#--------------------------------
# Alternate Grid Download
#--------------------------------
#THIS FUNCTION DEPRECATED BUT LEFT FOR REFERENCE 11MARCH2022
#make new dir in pat menu dir if needed
mkdir -p $HOME/patmenu2/alt-ardop-list
ALTGRID(){
#check internet connection
echo "Please wait while we check your internet connection"
echo "This may take up to a minute"
wget -q --tries=5 --timeout=10 --spider http://google.com #| yad --center --progress --pulsate --timeout-indicator=top --auto-close --no-buttons --text="Checking internet connection"
if [[ $? -eq 0 ]]; then
#yad --center --timeout=2 --timeout-indicator=top --no-buttons --text="Connection Detected" &
echo "Connection detected"
else
yad --center --timeout=3 --timeout-indicator=top --no-buttons --text="You are not connected to the internet"
exit
fi
#Create temp config file to use for downloads
MAINFILE=$XDG_CONFIG_HOME/pat/config.json
TEMPFILE=/run/user/$UID/config.json
cp $MAINFILE $TEMPFILE
GRID=$(yad --form --width=420 --text-align=center --center --title="Pat Log In/Out" --text-align=center \
--image $LOGO --window-icon=$LOGO --image-on-top --separator="|" --item-separator="|" \
--text="<b>Pat Log In/Out</b> by KM4ACK" \
--field="Alt Grid" "" \
--button="Download Gateway List":2 \
--button="Cancel":1)
BUT=$?
if [ $BUT = 252 ]; then
exit
elif [ $BUT = 1 ]; then
$MAIN &
exit
fi
GRID=$(echo $GRID | awk -F "|" '{print $1}')
sed -i "s/\"locator\":.*/\"locator\": \"$GRID\",/" $TEMPFILE
#Download the files
FOLDER=$HOME/patmenu2/alt-ardop-list/ardop-list-$GRID
mkdir -p $FOLDER
echo "downloading....please wait"
DL(){
pat --config /run/user/$UID/config.json rmslist -s --band 80m --mode ardop --force-download > $FOLDER/80mardoplist.txt
pat --config /run/user/$UID/config.json rmslist -s --band 40m --mode ardop --force-download > $FOLDER/40mardoplist.txt
pat --config /run/user/$UID/config.json rmslist -s --band 30m --mode ardop --force-download > $FOLDER/30mardoplist.txt
pat --config /run/user/$UID/config.json rmslist -s --band 20m --mode ardop --force-download > $FOLDER/20mardoplist.txt
pat --config /run/user/$UID/config.json rmslist -s --mode packet --force-download > $FOLDER/packet.txt
yad --center --timeout=2 --timeout-indicator=top --no-buttons --text="Downloads Done" &
}
DL | yad --center --progress --pulsate --auto-close --no-buttons --text-align=center \
--text="Downloading....This takes ~30 seconds\r<b>DO NOT CLOSE THIS WINDOW</b>\rDoing so will abort the download."
rm $TEMPFILE
$MAIN &
exit
}
#--------------------------------
# Load Alternate Grid List
#--------------------------------
#THIS FUNCTION DEPRECATED BUT LEFT FOR REFERENCE 11MARCH2022
LOADALTGRID(){
OUTFILE=/run/user/$UID/alt-grid.list
ls $HOME/patmenu2/alt-ardop-list > $OUTFILE
LIST=$(PARSER='OFS="\n" {print $1}'
tail -10 $OUTFILE | awk "$PARSER" | \
yad --title="Load Packet List" --width=300 --height=500 \
--image $LOGO --window-icon=$LOGO --image-on-top \
--center --list --text="Choose List to Load" \
--column List-to-Load \
--button="Cancel":1 \
--button="Load List":2 \
--button="Delete All Lists":3)
BUT=$?
LIST=$(echo $LIST | awk -F "|" '{print $1}')
echo $LIST
if [ $BUT = 252 ]; then
exit
elif [ $BUT = 1 ]; then
$MAIN &
exit
elif [ $BUT = 3 ]; then
yad --title="Delete List" --width=100 --height=100 \
--image $LOGO --window-icon=$LOGO --image-on-top \
--center --text="Are You Sure?" \
--button="YES":1 \
--button="NO":2
BUT=$?
if [ $BUT = 1 ]; then
rm -rf $HOME/patmenu2/alt-ardop-list
yad --center --timeout=2 --timeout-indicator=top --no-buttons --text="Alt Lists Deleted"
$MAIN &
exit
fi
$MAIN &
exit
fi
#backup home grid before loading alt grid
HOMEGRID=$(grep locator $XDG_CONFIG_HOME/pat/config.json | sed 's/"//g;s/locator://;s/,//;s/ //g')
if [ ! -d $HOME/patmenu2/alt-ardop-list/ardop-list-$HOMEGRID ]; then
echo "Backing up home grid"
mkdir -p $HOME/patmenu2/alt-ardop-list/ardop-list-$HOMEGRID
cp $HOME/patmenu2/ardop-list/* $HOME/patmenu2/alt-ardop-list/ardop-list-$HOMEGRID
fi
#load alt grid
cp -r $HOME/patmenu2/alt-ardop-list/$LIST/* $HOME/patmenu2/ardop-list/
LIST=$(echo $LIST | sed 's/ardop-list-//')
yad --center --timeout=2 --timeout-indicator=top --no-buttons --text="Grid $LIST Loaded"
echo "GRID=$LIST" > $HOME/patmenu2/.grid
$MAIN &
exit
}
#--------------------------------
# Recalculate Distance & Bearings
#--------------------------------
NEWCALC(){
#Function to update the distance and bearing between
#your current grid and the winlink gateways.
#this is necessary because the calculations are initially
#based on the grid in the pat config file at the time the
#list is downloaded.
#10MARCH2022 KM4ACK
DIR=/run/user/$UID
TMPFILE=$DIR/tempfile
TMPFILE2=$DIR/tempfile2
TMPFILE3=$DIR/tempfile3
MYGRID=$(cat /run/user/$UID/gridinfo.txt | cut -c1-6)
#backup current ARDOP lists
BKDIR=$MYPATH/ardop-list/bkup-`date +%F.%H%M`
mkdir -p $BKDIR
cp -r $HOME/patmenu2/ardop-list/*.txt $BKDIR/
#backup current VARA lists
BKDIRVARA=$MYPATH/vara-list/bkup-`date +%F.%H%M`
mkdir -p $BKDIRVARA
cp -r $HOME/patmenu2/vara-list/*.txt $BKDIRVARA/
MYGRID=$(yad --form --width=450 --text="<b>Recalculate Distance and Bearings to Gateways</b>\rThis takes 5-6 minutes to complete" \
--text-align=center --center --title="Recalculate" --text-align=center --separator="|" --item-separator="|" \
--image=$LOGO --window-icon=$LOGO --image-on-top \
--field="Current Grid Square" "$MYGRID" \
--button="Recalculate":2 \
--button="Cancel":1)
BUT=$?
MYGRID=`echo $MYGRID | awk -F "|" '{print $1}'`
if [ $BUT = 252 ]; then
exit
elif [ $BUT = 1 ]; then
$MAIN &
exit
fi
#create file that has grid variable used in calculations
touch $HOME/patmenu2/ardop-list/grid.txt
echo "GRID=$MYGRID" > $HOME/patmenu2/ardop-list/grid.txt
echo "LASTDL=Recalculated `date`" >> $HOME/patmenu2/ardop-list/grid.txt
MAIN(){
echo "Recalculating ARDOP 20M List"
RECALC 20mardoplist.txt | yad --center --progress --pulsate --auto-close --no-buttons --text-align=center --title="Recalculate" \
--text="Recalculating ARDOP 20M List\r<b>DO NOT CLOSE THIS WINDOW</b>\rDoing so will abort the process\rand leave you with a corrupt list."
echo "Recalculating ARDOP 30M List"
RECALC 30mardoplist.txt | yad --center --progress --pulsate --auto-close --no-buttons --text-align=center --title="Recalculate" \
--text="Recalculating ARDOP 30M List\r<b>DO NOT CLOSE THIS WINDOW</b>\rDoing so will abort the process\rand leave you with a corrupt list."
echo "Recalculating ARDOP 40M List"
RECALC 40mardoplist.txt | yad --center --progress --pulsate --auto-close --no-buttons --text-align=center --title="Recalculate" \
--text="Recalculating ARDOP 40M List\r<b>DO NOT CLOSE THIS WINDOW</b>\rDoing so will abort the process\rand leave you with a corrupt list."
echo "Recalculating ARDOP 80M List"
RECALC 80mardoplist.txt | yad --center --progress --pulsate --auto-close --no-buttons --text-align=center --title="Recalculate" \
--text="Recalculating ARDOP 80M List\r<b>DO NOT CLOSE THIS WINDOW</b>\rDoing so will abort the process\rand leave you with a corrupt list."
echo "Recalculating Packet list"
RECALC packet.txt | yad --center --progress --pulsate --auto-close --no-buttons --text-align=center --title="Recalculate" \
--text="Recalculating Packet List\r<b>DO NOT CLOSE THIS WINDOW</b>\rDoing so will abort the process\rand leave you with a corrupt list."
echo "Recalculating Vara 20M List"
RECALCVARA 20mvaralist.txt | yad --center --progress --pulsate --auto-close --no-buttons --text-align=center --title="Recalculate" \
--text="Recalculating VARA 20M List\r<b>DO NOT CLOSE THIS WINDOW</b>\rDoing so will abort the process\rand leave you with a corrupt list."
echo "Recalculating Vara 30M List"
RECALCVARA 30mvaralist.txt | yad --center --progress --pulsate --auto-close --no-buttons --text-align=center --title="Recalculate" \
--text="Recalculating VARA 30M List\r<b>DO NOT CLOSE THIS WINDOW</b>\rDoing so will abort the process\rand leave you with a corrupt list."
echo "Recalculating Vara 40M List"
RECALCVARA 40mvaralist.txt | yad --center --progress --pulsate --auto-close --no-buttons --text-align=center --title="Recalculate" \
--text="Recalculating VARA 40M List\r<b>DO NOT CLOSE THIS WINDOW</b>\rDoing so will abort the process\rand leave you with a corrupt list."
echo "Recalculating Vara 80M List"
RECALCVARA 80mvaralist.txt | yad --center --progress --pulsate --auto-close --no-buttons --text-align=center --title="Recalculate" \
--text="Recalculating VARA 80M List\r<b>DO NOT CLOSE THIS WINDOW</b>\rDoing so will abort the process\rand leave you with a corrupt list."
yad --center --timeout=2 --timeout-indicator=top --no-buttons --text="New Calculations Complete"
}
RECALC(){
#This section recalculates the ARDOP lists and 2M Packet list
FILE=$HOME/patmenu2/ardop-list/$1
#check for and remove existing temp file
if [ -f $TMPFILE3 ]; then
rm $TMPFILE3
fi
#create temp list to work with and remove headers/blank lines
cp $FILE $TMPFILE
sed -i 's/.*information...//;s/.*succeeded.//;s/.*url//' $TMPFILE
sed -i '/^$/d' $TMPFILE
#read file, calculate new distance, and update
while read LINE;
do
GRID=`echo $LINE | awk '{print $2}' | sed 's/\[//;s/\]//'`
DISTANCE=`echo $LINE | awk '{print $3 }'`
BEARING=`echo $LINE | awk '{print $4 }'`
CALC=`/usr/bin/wwl $MYGRID $GRID`
NEWDISTANCE=`echo $CALC | awk '{print $2}'`
NEWBEARING=`echo $CALC | awk '{print $5}'`
echo $LINE | sed "s/$DISTANCE/$NEWDISTANCE/;s/$BEARING/$NEWBEARING/" >> $TMPFILE2
done < $TMPFILE
rm $TMPFILE
#pad distance with zeros for sorting
while read LINE
do
DISTANCE=$(echo $LINE | awk '{ print $3 }')
NEWDISTANCE=$(echo $LINE | awk '{ print $3 }' | sed -e :a -e 's/^.\{1,4\}$/0&/;ta')
echo $LINE | sed "s/$DISTANCE/$NEWDISTANCE/" >> $TMPFILE3
done < $TMPFILE2
rm $TMPFILE2
#sort list by distance
sort -k3 -o $TMPFILE3 $TMPFILE3
cp $TMPFILE3 $HOME/patmenu2/ardop-list/$1
}
###########VARA Recalculate#######################
RECALCVARA(){
#This section recalculates the VARA lists.
FILE=$HOME/patmenu2/vara-list/$1
#check for and remove existing temp file
if [ -f $TMPFILE3 ]; then
rm $TMPFILE3
fi
#create temp list to work with and remove headers/blank lines
cp $FILE $TMPFILE
sed -i 's/.*information...//;s/.*succeeded.//;s/.*url//' $TMPFILE
sed -i '/^$/d' $TMPFILE
#read file, calculate new distance, and update
while read LINE;
do
GRID=`echo $LINE | awk '{print $2}' | sed 's/\[//;s/\]//'`
DISTANCE=`echo $LINE | awk '{print $3 }'`
BEARING=`echo $LINE | awk '{print $4 }'`
CALC=`/usr/bin/wwl $MYGRID $GRID`
NEWDISTANCE=`echo $CALC | awk '{print $2}'`
NEWBEARING=`echo $CALC | awk '{print $5}'`
echo $LINE | sed "s/$DISTANCE/$NEWDISTANCE/;s/$BEARING/$NEWBEARING/" >> $TMPFILE2
done < $TMPFILE
rm $TMPFILE
#pad distance with zeros for sorting
while read LINE
do
DISTANCE=$(echo $LINE | awk '{ print $3 }')
NEWDISTANCE=$(echo $LINE | awk '{ print $3 }' | sed -e :a -e 's/^.\{1,4\}$/0&/;ta')
echo $LINE | sed "s/$DISTANCE/$NEWDISTANCE/" >> $TMPFILE3
done < $TMPFILE2
rm $TMPFILE2
#sort list by distance
sort -k3 -o $TMPFILE3 $TMPFILE3
cp $TMPFILE3 $HOME/patmenu2/vara-list/$1
}
#call main function
MAIN
#return to pat menu
$MAIN
}