-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathqnadmin
executable file
·882 lines (860 loc) · 26.7 KB
/
qnadmin
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
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
#!/bin/bash
#
# Copyright (c) 2019 by Thomas A. Early N7TAE
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
trap ControlC INT
ControlC () {
echo "caught SIGINT"
}
# arguments "un" exe count module0 module1 module2
# 1 2 3 4 5 6
InstallComponent () {
if [ $3 -eq 1 ]; then
sudo make ${1}install$2
else
sudo make MODULE=$4 ${1}install$2
sudo make MODULE=$5 ${1}install$2
if [ $3 -eq 3 ]; then
sudo make MODULE=$6 ${1}install$2
fi
fi
}
InstallMMDVMHosts () {
if [ $nmmdvm -gt 0 ]; then
local n
if [ -z ${1} ]; then
if [ ! -d ../MMDVMHost ]; then
echo "This installation probabaly will not work because MMDVMHost can't be found!"
read -p "<Enter to continue"
fi
n=$(getconf _NPROCESSORS_ONLN)
echo "Detected $n processors for make"
for dir in $MMPATH $DMRPATH $YSFPATH $APRSPATH; do
if [ -d $dir ]; then
pushd $dir
make -j$n
popd
fi
done
fi
if [ -e ${MMPATH}/MMDVMHost ]; then
InstallComponent "$1" mmdvm $nmmdvm ${ammdvm[*]}
fi
if [ -e ${DMRPATH}/DMRGateway ]; then
InstallComponent "$1" dmr $nmmdvm ${ammdvm[*]}
fi
if [ -e ${YSFPATH}/YSFGateway ]; then
InstallComponent "$1" ysf $nmmdvm ${ammdvm[*]}
fi
if [ -e ${APRSPATH}/APRSGateway ]; then
sudo make ${1}installaprs
fi
fi
}
InstallSystem () {
local n
if [ -z ${1} ]; then
n=$( grep '^processor' /proc/cpuinfo | wc -l )
echo "Detected $n processors for make"
make base -j$n
fi
sudo make ${1}installbase
if [ $ndvap -gt 0 ]; then
if [ -z ${1} ]; then
make qndvap -j$n
fi
InstallComponent "$1" dvap $ndvap ${advap[*]}
fi
if [ $ndvrptr -gt 0 ]; then
if [ -z ${1} ]; then
make qndvrptr -j$n
fi
InstallComponent "$1" dvrptr $ndvrptr ${advrptr[*]}
fi
if [ $nitap -gt 0 ]; then
if [ -z ${1} ]; then
make qnitap -j$n
fi
InstallComponent "$1" itap $nitap ${aitap[*]}
fi
if [ $nmmdvm -gt 0 ]; then
if [ -z ${1} ]; then
make qnrelay -j$n
fi
InstallComponent "$1" relay $nmmdvm ${ammdvm[*]}
fi
if [ $nmodem -gt 0 ]; then
if [ -z ${1} ]; then
make qnmodem -j$n
fi
InstallComponent "$1" modem $nmodem ${amodem[*]}
fi
}
GetState() {
local state=$( systemctl show -p ${1}State $2 )
echo ${state#*=}
}
BaseStatus () {
local LoadGate SubGate LoadLink SubLink LoadDTMF SubDTMF LoadAPRS SubAPRS
LoadGate=$( GetState Load qngateway )
SubGate=$( GetState Sub qngateway )
LoadLink=$( GetState Load qnlink )
SubLink=$( GetState Sub qnlink )
LoadDTMF=$( GetState Load qndtmf )
SubDTMF=$( GetState Sub qndtmf )
LoadAPRS=$( GetState Load aprsgateway )
SubAPRS=$( GetState Sub aprsgateway )
if [[ $LoadGate == 'loaded' ]]; then
if [[ $SubGate == 'running' ]]; then
GateState='running'
else
GateState='stopped'
fi
else
GateState='not installed'
fi
echo "QnetGateway is $GateState"
if [[ $LoadLink == 'loaded' ]]; then
if [[ $SubLink == 'running' ]]; then
LinkState='running'
else
LinkState='stopped'
fi
else
LinkState='not installed'
fi
echo "QnetLink is $LinkState"
if [[ $LoadDTMF == 'loaded' ]]; then
if [[ $SubDTMF == 'running' ]]; then
DTMFState='running'
else
DTMFState='stopped'
fi
else
DTMFState='not installed'
fi
echo "DTMF is $DTMFState"
if [ -d $APRSPATH ]; then
if [[ $LoadAPRS == 'loaded' ]]; then
if [[ $SubAPRS == 'running' ]]; then
APRSState='running'
else
APRSState='stopped'
fi
else
APRSState='not installed'
fi
echo "APRSGateway is $APRSState"
fi
}
ModuleStatus () {
local LoadState SubState mcvar
if [ -z ${3} ]; then
ModuleState[$1]='EMPTY'
MMDVMState[$1]='EMPTY'
DMRState[$1]='EMPTY'
YSFState[$1]='EMPTY'
else
mcvar="n${3}"
ModuleProcess[$1]="qn$3"
MMDVMProcess[$1]=''
MMDVMState[$1]='EMPTY'
DMRProcess[$1]=''
DMRState[$1]='EMPTY'
YSFProcess[$1]=''
YSFState[$1]='EMPTY'
if [[ "${ModuleProcess[$1]}" == 'qnmmdvmhost' ]]; then
ModuleProcess[$1]='qnrelay'
MMDVMProcess[$1]='mmdvm'
MMDVMState[$1]='not installed'
DMRProcess[$1]='dmrgateway'
DMRState[$1]='not installed'
YSFProcess[$1]='ysfgateway'
YSFState[$1]='not installed'
elif [[ "${ModuleProcess[$1]}" == 'qnmmdvmmodem' ]]; then
ModuleProcess[$1]='qnmodem'
fi
if [[ ${!mcvar} > 1 ]]; then
ModuleProcess[$1]="${ModuleProcess[$1]}${2}"
if [[ "${MMDVMProcess[$1]}" == 'mmdvm' ]]; then
MMDVMProcess[$1]="${MMDVMProcess[$1]}${2}"
DMRProcess[$1]="${DMRProcess[$1]}${2}"
YSFProcess[$1]="${YSFProcess[$1]}${2}"
fi
fi
LoadState=$( GetState Load ${ModuleProcess[$1]} )
SubState=$( GetState Sub ${ModuleProcess[$1]} )
if [[ "$LoadState" == "loaded" ]]; then
if [[ $SubState == "running" ]]; then
ModuleState[$1]='running'
else
ModuleState[$1]='stopped'
fi
else
ModuleState[$1]='not installed'
fi
if [[ "${MMDVMState[$1]}" != 'EMPTY' ]]; then
LoadState=$( GetState Load ${MMDVMProcess[$1]} )
SubState=$( GetState Sub ${MMDVMProcess[$1]} )
if [[ "$LoadState" == "loaded" ]]; then
if [[ $SubState == "running" ]]; then
MMDVMState[$1]='running'
else
MMDVMState[$1]='stopped'
fi
else
MMDVMState[$1]='not installed'
fi
LoadState=$( GetState Load ${DMRProcess[$1]} )
SubState=$( GetState Sub ${DMRProcess[$1]} )
if [[ "$LoadState" == "loaded" ]]; then
if [[ $SubState == "running" ]]; then
DMRState[$1]='running'
else
DMRState[$1]='stopped'
fi
else
DMRState[$1]='not installed'
fi
LoadState=$( GetState Load ${YSFProcess[$1]} )
SubState=$( GetState Sub ${YSFProcess[$1]} )
if [[ "$LoadState" == "loaded" ]]; then
if [[ $SubState == "running" ]]; then
YSFState[$1]='running'
else
YSFState[$1]='stopped'
fi
else
YSFState[$1]='not installed'
fi
fi
if [[ "$3" == 'mmdvmhost' ]]; then
echo "Module ${2^^} - ${ModuleProcess[$1]} is ${ModuleState[$1]} - ${MMDVMProcess[$1]} is ${MMDVMState[$1]} - ${DMRProcess[$1]} is ${DMRState[$1]} - ${YSFProcess[$1]} is ${YSFState[$1]}"
else
echo "Module ${2^^} - ${ModuleProcess[$1]} is ${ModuleState[$1]}"
fi
fi
}
Header () {
local count
count=$( ps -aux | grep -e qn -e MMDVMHost | wc -l )
if [ ${count} -gt 3 ]; then
echo
echo "USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND"
ps -aux | grep -e qngateway -e qnlink -e qndtmf -e qndvap -e qnitap -e qnrelay -e qndvrptr -e qnmodem -e MMDVMHost -e YSFGateway -e DMRGateway -e APRSGateway | grep -v grep
fi
echo
}
LogMenu () {
ans=''
while [[ "$ans" != q* ]]; do
clear
echo " Log Menu"
Header
echo "After starting a log, use <Ctrl>+C to stop the log and return to this menu."
echo
if [[ $GateState == 'running' ]]; then
echo " g : qngateway Log"
else
echo " qngateway is not running"
fi
if [[ $LinkState == 'running' ]]; then
echo " l : qnlink Log"
else
echo " qnlink is not running"
fi
if [[ $DTMFState == 'running' ]]; then
echo " dt : qndtmf Log"
else
echo " qndtmf is not running"
fi
if [[ ${ModuleState[0]} != 'EMPTY' ]]; then
if [[ ${ModuleState[0]} == 'running' ]]; then
echo " a : ${ModuleProcess[0]} Log"
else
echo " ${ModuleProcess[0]} is not running"
fi
fi
if [[ ${ModuleState[1]} != 'EMPTY' ]]; then
if [[ ${ModuleState[1]} == 'running' ]]; then
echo " b : ${ModuleProcess[1]} Log"
else
echo " ${ModuleProcess[1]} is not running"
fi
fi
if [[ ${ModuleState[2]} != 'EMPTY' ]]; then
if [[ ${ModuleState[2]} == 'running' ]]; then
echo " c : ${ModuleProcess[2]} Log"
else
echo " ${ModuleProcess[2]} is not running"
fi
fi
if [[ ${MMDVMState[0]} != 'EMPTY' ]]; then
if [[ ${MMDVMState[0]} == 'running' ]]; then
echo " ma : ${MMDVMProcess[0]} Log"
else
echo " ${MMDVMProcess[0]} is not running"
fi
fi
if [[ ${MMDVMState[1]} != 'EMPTY' ]]; then
if [[ ${MMDVMState[1]} == 'running' ]]; then
echo " mb : ${MMDVMProcess[1]} Log"
else
echo " ${MMDVMProcess[1]} is not running"
fi
fi
if [[ ${MMDVMState[2]} != 'EMPTY' ]]; then
if [[ ${MMDVMState[2]} == 'running' ]]; then
echo " mc : ${MDVMProcess[2]} Log"
else
echo " ${MMDVMProcess[2]} is not running"
fi
fi
if [[ ${DMRState[0]} != 'EMPTY' ]]; then
if [[ ${DMRState[0]} == 'running' ]]; then
echo " da : ${DMRProcess[0]} Log"
else
echo " ${DMRProcess[0]} is not running"
fi
fi
if [[ ${DMRState[1]} != 'EMPTY' ]]; then
if [[ ${DMRState[1]} == 'running' ]]; then
echo " db : ${DMRProcess[1]} Log"
else
echo " ${DMRProcess[1]} is not running"
fi
fi
if [[ ${DMRState[2]} != 'EMPTY' ]]; then
if [[ ${DMRState[2]} == 'running' ]]; then
echo " dc : ${DMRProcess[2]} Log"
else
echo " ${DMRProcess[2]} is not running"
fi
fi
if [[ ${YSFState[0]} != 'EMPTY' ]]; then
if [[ ${YSFState[0]} == 'running' ]]; then
echo " ya : ${YSFProcess[0]} Log"
else
echo " ${YSFProcess[0]} is not running"
fi
fi
if [[ ${YSFState[1]} != 'EMPTY' ]]; then
if [[ ${YSFState[1]} == 'running' ]]; then
echo " yb : ${YSFProcess[1]} Log"
else
echo " ${YSFProcess[1]} is not running"
fi
fi
if [[ ${YSFState[2]} != 'EMPTY' ]]; then
if [[ ${YSFState[2]} == 'running' ]]; then
echo " yc : ${YSFProcess[2]} Log"
else
echo " ${YSFProcess[2]} is not running"
fi
fi
if [ -d $APRSPATH ]; then
if [[ ${APRSState} != 'not installed' ]]; then
if [[ ${APRSState} == 'running' ]]; then
echo " p : APRSGateway Log"
else
echo " APRSGateway is not running"
fi
fi
fi
echo
echo " q : quit and return to main menu"
echo
read -p "Command: " ans
if [[ "$ans" == g* ]] && [[ "$GateState" == 'running' ]]; then
sudo journalctl -u qngateway -f
elif [[ "$ans" == l* ]] && [[ "$LinkState" == 'running' ]]; then
sudo journalctl -u qnlink -f
elif [[ "$ans" == dt* ]] && [[ "$DTMFState" == 'running' ]]; then
sudo journalctl -u qndtmf -f
elif [[ "$ans" == a* ]] && [[ "${ModuleState[0]}" == 'running' ]]; then
sudo journalctl -u ${ModuleProcess[0]} -f
elif [[ "$ans" == b* ]] && [[ "${ModuleState[1]}" == 'running' ]]; then
sudo journalctl -u ${ModuleProcess[1]} -f
elif [[ "$ans" == c* ]] && [[ "${ModuleState[2]}" == 'running' ]]; then
sudo journalctl -u ${ModuleProcess[2]} -f
elif [[ "$ans" == ma* ]] && [[ "${MMDVMState[0]}" == 'running' ]]; then
sudo journalctl -u ${MMDVMProcess[0]} -f
elif [[ "$ans" == mb* ]] && [[ "${MMDVMState[1]}" == 'running' ]]; then
sudo journalctl -u ${MMDVMProcess[1]} -f
elif [[ "$ans" == mc* ]] && [[ "${MMDVMState[2]}" == 'running' ]]; then
sudo journalctl -u ${MMDVMProcess[2]} -f
elif [[ "$ans" == da* ]] && [[ "${DMRState[0]}" == 'running' ]]; then
sudo journalctl -u ${DMRProcess[0]} -f
elif [[ "$ans" == db* ]] && [[ "${DMRState[1]}" == 'running' ]]; then
sudo journalctl -u ${DMRProcess[1]} -f
elif [[ "$ans" == dc* ]] && [[ "${DMRState[2]}" == 'running' ]]; then
sudo journalctl -u ${DMRProcess[2]} -f
elif [[ "$ans" == ya* ]] && [[ "${YSFState[0]}" == 'running' ]]; then
sudo journalctl -u ${YSFProcess[0]} -f
elif [[ "$ans" == yb* ]] && [[ "${YSFState[1]}" == 'running' ]]; then
sudo journalctl -u ${YSFProcess[1]} -f
elif [[ "$ans" == yc* ]] && [[ "${YSFState[2]}" == 'running' ]]; then
sudo journalctl -u ${YSFProcess[2]} -f
elif [[ "$ans" == p* ]] && [[ "${APRSState}" == 'running' ]]; then
sudo journalctl -u aprsgateway -f
fi
done
ans=''
}
MaintenanceMenu () {
local m n
ans=''
while [[ "$ans" != q* ]]; do
clear
echo " MaintenanceMenu"
Header
if [[ "$GateState" == 'running' ]]; then
echo " g : Stop QnetGateway"
elif [[ "$GateState" == 'stopped' ]]; then
echo " g : Start QnetGateway"
fi
if [[ "$LinkState" == 'running' ]]; then
echo " l : Stop QnetLink"
elif [[ "$LinkState" == 'stopped' ]]; then
echo " l : Start QnetLink"
fi
if [[ "$DTMFState" == 'running' ]]; then
echo " dt : Stop DTMF"
elif [[ "$DTMFState" == 'stopped' ]]; then
echo " dt : Start DTMF"
fi
if [[ "${ModuleState[0]}" == 'running' ]]; then
echo " a : Stop Module A"
elif [[ "${ModuleState[0]}" == 'stopped' ]]; then
echo " a : Start Module A"
fi
if [[ "${ModuleState[1]}" == 'running' ]]; then
echo " b : Stop Module B"
elif [[ "${ModuleState[1]}" == 'stopped' ]]; then
echo " b : Start Module B"
fi
if [[ "${ModuleState[2]}" == 'running' ]]; then
echo " c : Stop Module C"
elif [[ "${ModuleState[2]}" == 'stopped' ]]; then
echo " c : Start Module C"
fi
if [[ "${MMDVMState[0]}" == 'running' ]]; then
echo " ma : Stop MMDVMHost A"
elif [[ "${MMDVMState[0]}" == 'stopped' ]]; then
echo " ma : Start MMDVMHost A"
fi
if [[ "${MMDVMState[1]}" == 'running' ]]; then
echo " mb : Stop MMDVMHost B"
elif [[ "${MMDVMState[1]}" == 'stopped' ]]; then
echo " mb : Start MMDVMHost B"
fi
if [[ "${MMDVMState[2]}" == 'running' ]]; then
echo " mc : Stop MMDVMHost C"
elif [[ "${MMDVMState[2]}" == 'stopped' ]]; then
echo " mc : Start MMDVMHost C"
fi
if [[ "${DMRState[0]}" == 'running' ]]; then
echo " da : Stop DMRGateway A"
elif [[ "${DMRState[0]}" == 'stopped' ]]; then
echo " da : Start DMRGateway A"
fi
if [[ "${DMRState[1]}" == 'running' ]]; then
echo " db : Stop DMRGateway B"
elif [[ "${DMRState[1]}" == 'stopped' ]]; then
echo " db : Start DMRGateway B"
fi
if [[ "${DMRState[2]}" == 'running' ]]; then
echo " dc : Stop DMRGateway C"
elif [[ "${DMRState[2]}" == 'stopped' ]]; then
echo " dc : Start DMRGateway C"
fi
if [[ "${YSFState[0]}" == 'running' ]]; then
echo " ya : Stop YSFGateway A"
elif [[ "${YSFState[0]}" == 'stopped' ]]; then
echo " ys : Start YSFGateway A"
fi
if [[ "${YSFState[1]}" == 'running' ]]; then
echo " yb : Stop YSFGateway B"
elif [[ "${YSFState[1]}" == 'stopped' ]]; then
echo " yb : Start YSFGateway B"
fi
if [[ "${YSFState[2]}" == 'running' ]]; then
echo " yc : Stop YSFGateway C"
elif [[ "${YSFState[2]}" == 'stopped' ]]; then
echo " yc : Start YSFGateway C"
fi
if [[ "${APRSState}" == 'running' ]]; then
echo " p : Stop APRSGateway"
elif [[ "${APRSState}" == 'stopped' ]]; then
echo " p : Start APRSGateway"
fi
echo
echo " q : Return to main Menu"
echo
read -p "Command: " ans
if [[ "$ans" == g* ]]; then
if [[ "$GateState" == 'running' ]]; then
sudo systemctl stop qngateway
elif [[ "$GateState" == 'stopped' ]]; then
sudo systemctl start qngateway
fi
BaseStatus
elif [[ "$ans" == l* ]]; then
if [[ "$LinkState" == 'running' ]]; then
sudo systemctl stop qnlink
elif [[ "$LinkState" == 'stopped' ]]; then
sudo systemctl start qnlink
fi
BaseStatus
elif [[ "$ans" == dt* ]]; then
if [[ "$DTMFState" == 'running' ]]; then
sudo systemctl stop qndtmf
elif [[ "$DTMFState" == 'stopped' ]]; then
sudo systemctl start qndtmf
fi
BaseStatus
elif [[ "$ans" == a* ]] && [ -n $module_a ]; then
if [[ "${ModuleState[0]}" == 'running' ]]; then
sudo systemctl stop ${ModuleProcess[0]}
elif [[ "${ModuleState[0]}" == 'stopped' ]]; then
sudo systemctl start ${ModuleProcess[0]}
fi
ModuleStatus 0 a $module_a
elif [[ "$ans" == b* ]] && [ -n $module_b ]; then
if [[ "${ModuleState[1]}" == 'running' ]]; then
sudo systemctl stop ${ModuleProcess[1]}
elif [[ "${ModuleState[1]}" == 'stopped' ]]; then
sudo systemctl start ${ModuleProcess[1]}
fi
ModuleStatus 1 b $module_b
elif [[ "$ans" == c* ]] && [ -n $module_c ]; then
if [[ "${ModuleState[2]}" == 'running' ]]; then
sudo systemctl stop ${ModuleProcess[2]}
elif [[ "${ModuleState[2]}" == 'stopped' ]]; then
sudo systemctl start ${ModuleProcess[2]}
fi
ModuleStatus 2 c $module_c
elif [[ "$ans" == ma* ]] && [ -n $module_a ]; then
if [[ "${MMDVMState[0]}" == 'running' ]]; then
sudo systemctl stop ${MMDVMProcess[0]}
elif [[ "${MMDVMState[0]}" == 'stopped' ]]; then
sudo systemctl start ${MMDVMProcess[0]}
fi
ModuleStatus 0 a $module_a
elif [[ "$ans" == mb* ]] && [ -n $module_b ]; then
if [[ "${MMDVMState[1]}" == 'running' ]]; then
sudo systemctl stop ${MMDVMProcess[1]}
elif [[ "${MMDVMState[1]}" == 'stopped' ]]; then
sudo systemctl start ${MMDVMProcess[1]}
fi
ModuleStatus 1 b $module_b
elif [[ "$ans" == mc* ]] && [ -n $module_c ]; then
if [[ "${MMDVMState[2]}" == 'running' ]]; then
sudo systemctl stop ${MMDVMProcess[2]}
elif [[ "${MMDVMState[2]}" == 'stopped' ]]; then
sudo systemctl start ${MMDVMProcess[2]}
fi
ModuleStatus 2 c $module_c
elif [[ "$ans" == da* ]] && [ -n $module_a ]; then
if [[ "${DMRState[0]}" == 'running' ]]; then
sudo systemctl stop ${DMRProcess[0]}
elif [[ "${DMRState[0]}" == 'stopped' ]]; then
sudo systemctl start ${DMRrocess[0]}
fi
ModuleStatus 0 a $module_a
elif [[ "$ans" == db* ]] && [ -n $module_b ]; then
if [[ "${DMRState[1]}" == 'running' ]]; then
sudo systemctl stop ${DMRProcess[1]}
elif [[ "${DMRState[1]}" == 'stopped' ]]; then
sudo systemctl start ${DMRProcess[1]}
fi
ModuleStatus 1 b $module_b
elif [[ "$ans" == dc* ]] && [ -n $module_c ]; then
if [[ "${DMRState[2]}" == 'running' ]]; then
sudo systemctl stop ${DMRProcess[2]}
elif [[ "${DMRState[2]}" == 'stopped' ]]; then
sudo systemctl start ${DMRProcess[2]}
fi
ModuleStatus 2 c $module_c
elif [[ "$ans" == ya* ]] && [ -n $module_a ]; then
if [[ "${YSFState[0]}" == 'running' ]]; then
sudo systemctl stop ${YSFProcess[0]}
elif [[ "${YSFState[0]}" == 'stopped' ]]; then
sudo systemctl start ${YSFProcess[0]}
fi
ModuleStatus 0 a $module_a
elif [[ "$ans" == yb* ]] && [ -n $module_b ]; then
if [[ "${YSFState[1]}" == 'running' ]]; then
sudo systemctl stop ${YSFProcess[1]}
elif [[ "${YSFState[1]}" == 'stopped' ]]; then
sudo systemctl start ${YSFProcess[1]}
fi
ModuleStatus 1 b $module_b
elif [[ "$ans" == yc* ]] && [ -n $module_c ]; then
if [[ "${YSFState[2]}" == 'running' ]]; then
sudo systemctl stop ${YSFProcess[2]}
elif [[ "${YSFState[2]}" == 'stopped' ]]; then
sudo systemctl start ${YSFProcess[2]}
fi
ModuleStatus 2 c $module_c
elif [[ "$ans" == p* ]]; then
if [[ "${APRSState}" == 'running' ]]; then
sudo systemctl stop ${APRSProcess}
elif [[ "${APRSState}" == 'stopped' ]]; then
sudo systemctl start ${APRSProcess}
fi
BaseStatus
fi
done
ans=''
}
GatewayMenu () {
which wget > /dev/null
if test $? -ne 0; then
echo 'wget not found, installing...'
sudo apt install wget
fi
ans=''
while [[ "$ans" != q* ]]; do
local refcount=$( grep -s "^REF" gwys.txt | wc -l )
local dcscount=$( grep -s "^DCS" gwys.txt | wc -l )
local xrfcount=$( grep -s "^XRF" gwys.txt | wc -l )
local xlxcount=$( grep -s "^XLX" gwys.txt | wc -l )
local repcount=$( grep -s -v "^#" gwys.txt | grep -s -v -e "^REF" -e "^DCS" -e "^XRF" -e "^XLX" | wc -l )
clear
echo
echo " Gateway File"
echo
echo " $refcount REF, $dcscount DCS, $xrfcount XRF, $xlxcount XLX and $repcount Repeaters"
echo
echo " All initialization will overwrite any existing file!"
echo "i6 : Initialize gwys.txt using www.PiStar.uk, xlxapi.rlx.lu and IPv6 from QuadNet"
echo "ip : Initialize gwys.txt using www.PiStar.uk/downloads and xlxapi.rlx.lu"
echo "iv : Initialize gwys.txt using VA3UV.com (includes a large # of repeaters)"
echo "ir : Initialize gwys.txt using VA3UV.com (but just the reflectors)"
echo "n : Edit gwys.txt file with nano"
echo "v : Edit gwys.txt file with vi"
echo
echo "q : Quit and return to Main Menu"
echo
read -p "Command: " ans
if [[ "$ans" == i6* ]]; then
wget -O XLX_Hosts.txt http://xlxapi.rlx.lu/api.php?do=GetXLXDMRMaster
wget http://www.pistar.uk/downloads/DExtra_Hosts.txt
wget http://www.pistar.uk/downloads/DPlus_Hosts.txt
wget http://www.pistar.uk/downloads/DCS_Hosts.txt
wget https://hosts.openquad.net/ipv6-hosts.txt
/bin/rm -f gwys.txt
echo "# Downloaded from www.pistar.uk and xlxapi.rlx.lu `date`" > gwys.txt
awk '$1 ~ /^XLX/ { gsub("\r", ""); printf "%s %s 30001\n", $1, $2 }' XLX_Hosts.txt >> gwys.txt
awk '$1 ~ /^XRF/ { printf "%s %s 30001\n", $1, $2 }' DExtra_Hosts.txt >> gwys.txt
awk '$1 ~ /^DCS/ { printf "%s %s 30051\n", $1, $2 }' DCS_Hosts.txt >> gwys.txt
awk '$1 ~ /^REF/ { printf "%s %s 20001\n", $1, $2 }' DPlus_Hosts.txt >> gwys.txt
cat ipv6-hosts.txt >> gwys.txt
if [ -e My_Hosts.txt ]; then
cat My_Hosts.txt >> gwys.txt
fi
/bin/rm -f {XLX,DExtra,DPlus,DCS}_Hosts.txt ipv6-hosts.txt
elif [[ "$ans" == ip* ]]; then
wget -O XLX_Hosts.txt http://xlxapi.rlx.lu/api.php?do=GetXLXDMRMaster
wget http://www.pistar.uk/downloads/DExtra_Hosts.txt
wget http://www.pistar.uk/downloads/DPlus_Hosts.txt
wget http://www.pistar.uk/downloads/DCS_Hosts.txt
/bin/rm -f gwys.txt
echo "# Downloaded from www.pistar.uk and xlxapi.rlx.lu `date`" > gwys.txt
awk '$1 ~ /^XLX/ { gsub("\r", ""); printf "%s %s 30001\n", $1, $2 }' XLX_Hosts.txt >> gwys.txt
awk '$1 ~ /^XRF/ { printf "%s %s 30001\n", $1, $2 }' DExtra_Hosts.txt >> gwys.txt
awk '$1 ~ /^DCS/ { printf "%s %s 30051\n", $1, $2 }' DCS_Hosts.txt >> gwys.txt
awk '$1 ~ /^REF/ { printf "%s %s 20001\n", $1, $2 }' DPlus_Hosts.txt >> gwys.txt
if [ -e My_Hosts.txt ]; then
cat My_Hosts.txt >> gwys.txt
fi
/bin/rm -f {XLX,DExtra,DPlus,DCS}_Hosts.txt
elif [[ "$ans" == iv* ]]; then
/bin/rm -f gwys.txt
wget http://www.va3uv.com/gwys.txt
if [ -e My_Hosts.txt ]; then
cat My_Hosts.txt >> gwys.txt
fi
elif [[ "$ans" == ir* ]]; then
/bin/rm -f gwys.txt
wget -nv -O gwys.va3uv.txt http://www.va3uv.com/gwys.txt
if [ -e gwys.va3uv.txt ]; then
echo "# Downloaded from www.va3uv.com `date`" > gwys.txt
awk '$1~/^REF/{print $1, $2, $3}' gwys.va3uv.txt >> gwys.txt
awk '$1~/^XRF/{print $1, $2, $3}' gwys.va3uv.txt >> gwys.txt
awk '$1~/^DCS/{print $1, $2, $3}' gwys.va3uv.txt >> gwys.txt
if [ -e My_Hosts.txt ]; then
cat My_Hosts.txt >> gwys.txt
fi
rm -f gwys.va3uv.txt
fi
elif [[ "$ans" == n* ]]; then
nano gwys.txt
elif [[ "$ans" == v* ]]; then
vi gwys.txt
fi
done
ans=''
}
# get defined modules from the config file
if [ -e qn.cfg ]; then
source <( grep "^module_[abc]=" qn.cfg )
if [ -z "$module_a" ] && [ -z "$module_b" ] && [ -z "$module_c" ]; then
echo "No moudules defined in the qn.cfg file!, please re-edit you configuration."
exit 1
fi
else
echo "ERROR: can't find the qn.cfg configuration file!"
echo "You can use ./qnconfig to create your config file."
exit 1
fi
# get the installation directory from the make file
if [ -e makefile ]; then
MAKEFILE=makefile
elif [ -e Makefile ]; then
MAKEFILE=Makefile
else
echo "ERROR: There is no Makefile or makefile"
exit 1
fi
source <( grep -e '^BINDIR=' -e '^MMPATH=' -e '^DMRPATH=' -e '^YSFPATH=' -e '^APRSPATH' $MAKEFILE )
if [ -z $BINDIR ]; then
echo "ERROR: The BINDIR definition in $MAKEFILE is empty!"
exit 1
fi
if [ ! -d "$BINDIR" ]; then
echo "ERROR: The BINDIR directory $BINDIR is not a directory!"
exit 1
fi
ndvap=0
ndvrptr=0
nitap=0
nmmdvm=0
nmodem=0
for m in a b c ; do
mod=module_${m}
if [ -z ${!mod} ]; then continue; fi
type=${!mod}
if [[ "$type" == 'dvap' ]]; then
advap[${ndvap}]=${m}
ndvap=$((ndvap + 1))
elif [[ "$type" == 'dvrptr' ]]; then
advrptr[$ndvap]=${m}
ndvrptr=$((ndvrptr + 1))
elif [[ "$type" == 'itap' ]]; then
aitap[${nitap}]=${m}
nitap=$((nitap + 1))
elif [[ "$type" == 'mmdvmhost' ]]; then
ammdvm[${nmmdvm}]=${m}
nmmdvm=$((nmmdvm + 1))
elif [[ "$type" == 'mmdvmmodem' ]]; then
amodem[${nmodem}]=${m}
nmodem=$((nmodem + 1))
fi
done
MODULE_COUNT=$((ndvap + ndvrptr + nitap + nmmdvm + nmodem))
while [[ "$ans" != q* ]]; do
clear
echo
echo " Qnet Administration Menu V#211013"
Header
BaseStatus
ModuleStatus 0 a "$module_a"
ModuleStatus 1 b "$module_b"
ModuleStatus 2 c "$module_c"
echo
if [[ "$GateState" == 'not installed' ]] || [[ "$LinkState" == 'not installed' ]]; then
if [ -e gwys.txt ]; then
echo "is : Install configured system"
echo "gp : Do a 'git pull' to refresh sources"
else
echo " You must set-up your gwys.txt file before installation."
fi
else
echo "us : Uninstall configured System"
fi
echo "gw : Gateway File Menu"
echo
if [[ "$DTMFState" == 'not installed' ]]; then
echo "nd : Edit DTMF file with nano"
echo "vd : Edit DTMF file with vi"
if [ -e qndtmf ] && [ -n "`diff -q qndtmf qndtmf.sh`" ]; then
echo "rd : Restore DTMF file to default (this will overwrite existing DTMF file)"
fi
echo "id : Install DTMF"
else
echo "ud : Uninstall DTMF"
fi
echo
echo "c : Clean (remove temporary files and locally built executables)"
echo
if [[ "$GateState" != 'not installed' ]] && [[ "$LinkState" != 'not installed' ]]; then
echo "m : Maintenance Menu"
echo "l : Log Menu"
fi
echo
read -p "q to quit. Command: " ans
# EXECUTE COMMANDS
if [[ "$GateState" == 'not installed' ]] && [[ "$ans" == is* ]]; then
InstallSystem
InstallMMDVMHosts
echo 'Wait for a few seconds for everything to start...'
sleep 5
elif [[ "$GateState" != 'not installed' ]] && [[ "$ans" == us* ]]; then
InstallSystem un
InstallMMDVMHosts un
elif [[ "$GateState" == 'not installed' ]] && [[ "$ans" == gp* ]]; then
git pull
for dir in $MMPATH $DMRPATH $YSFPATH $APRSPATH; do
if [ -d $dir ]; then
pushd $dir
git pull
popd
fi
done
read -p 'Press <Enter> to continue: ' ans
ans=''
elif [[ "$ans" == gw* ]]; then
GatewayMenu
elif [[ "$DTMFState" == 'not installed' ]] && [[ "$ans" == nd* ]]; then
if [ ! -e qndtmf ]; then cp qndtmf.sh qndtmf; fi
nano qndtmf
elif [[ "$DTMFState" == 'not installed' ]] && [[ "$ans" == vd* ]]; then
if [ ! -e qndtmf ]; then cp qndtmf.sh qndtmf; fi
vi qndtmf
elif [[ "$DTMFState" == 'not installed' ]] && [ -e qndtmf ] && [ -n "`diff -q qndtmf qndtmf.sh`" ] && [[ "$ans" == rd* ]]; then
rm -f qndtmf
elif [[ "$DTMFState" == 'not installed' ]] && [[ "$ans" == id* ]]; then
if [ ! -e qndtmf ]; then cp qndtmf.sh qndtmf; fi
sudo make installdtmf
elif [[ "$DTMFState" != 'not installed' ]] && [[ "$ans" == ud* ]]; then
sudo make uninstalldtmf
elif [[ "$ans" == c* ]]; then
make clean
for dir in $MMPATH $DMRPATH $YSFPATH $APRSPATH; do
if [ -d $dir ]; then
pushd $dir
make clean
popd
fi
done
elif [[ "$ans" == m* ]]; then
MaintenanceMenu
elif [[ "$ans" == l* ]]; then
LogMenu
fi
done
exit 0