forked from davecrump/atv-rptr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu.sh
executable file
·1544 lines (1312 loc) · 46.3 KB
/
menu.sh
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
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# Repeater Menu Application
############ Function to Write to Repeater Config File ###############
set_config_var() {
lua - "$1" "$2" "$3" <<EOF > "$3.bak"
local key=assert(arg[1])
local value=assert(arg[2])
local fn=assert(arg[3])
local file=assert(io.open(fn))
local made_change=false
for line in file:lines() do
if line:match("^#?%s*"..key.."=.*$") then
line=key.."="..value
made_change=true
end
print(line)
end
if not made_change then
print(key.."="..value)
end
EOF
mv "$3.bak" "$3"
}
############ Function to Read from Repeater Config File ###############
get_config_var() {
lua - "$1" "$2" <<EOF
local key=assert(arg[1])
local fn=assert(arg[2])
local file=assert(io.open(fn))
for line in file:lines() do
local val = line:match("^#?%s*"..key.."=(.*)$")
if (val ~= nil) then
print(val)
break
end
end
EOF
}
############ Function to Read value with - from Config File ###############
get-config_var() {
lua - "$1" "$2" <<EOF
local key=assert(arg[1])
local fn=assert(arg[2])
local file=assert(io.open(fn))
for line in file:lines() do
local val = line:match("^#?%s*"..key.."=[+-]?(.*)$")
if (val ~= nil) then
print(val)
break
end
end
EOF
}
#########################################################
CONFIGFILE="/home/pi/atv-rptr/config/repeater_config.txt"
do_Reboot()
{
sudo reboot now
}
do_Nothing()
{
:
}
do_Norm_HDMI()
{
# change #enable_tvout=1 or enable_tvout=1 to #enable_tvout=1
# first check if "#enable_tvout=1" is in /boot/config.txt
grep -q "#enable_tvout=1" /boot/config.txt
if [ $? -ne 0 ]; then # "#enable_tvout=1" is not there, so check if "enable_tvout=1" is there
grep -q "enable_tvout=1" /boot/config.txt
if [ $? -eq 0 ]; then # "enable_tvout=1" is there, so replace it with "#enable_tvout=1"
sudo sed -i '/enable_tvout=1/c\#enable_tvout=1' /boot/config.txt >/dev/null 2>/dev/null
else # not there, so append the commented statement
sudo bash -c 'echo " " >> /boot/config.txt '
sudo bash -c 'echo "# Uncomment to enable Comp Vid output" >> /boot/config.txt '
sudo bash -c 'echo "#enable_tvout=1" >> /boot/config.txt '
sudo bash -c 'echo " " >> /boot/config.txt '
fi
fi
# change #hdmi_safe=1 or hdmi_safe=1 to #hdmi_safe=1
# first check if "#hdmi_safe=1" is in /boot/config.txt
grep -q "#hdmi_safe=1" /boot/config.txt
if [ $? -ne 0 ]; then # "#hdmi_safe=1" is not there, so check if "hdmi_safe=1" is there
grep -q "hdmi_safe=1" /boot/config.txt
if [ $? -eq 0 ]; then # "hdmi_safe=1" is there, so replace it with "#hdmi_safe=1"
sudo sed -i '/hdmi_safe=1/c\#hdmi_safe=1' /boot/config.txt >/dev/null 2>/dev/null
else # not there, so append the commented statement
sudo bash -c 'echo " " >> /boot/config.txt '
sudo bash -c 'echo "# uncomment if you get no picture on HDMI for a default safe mode" >> /boot/config.txt '
sudo bash -c 'echo "#hdmi_safe=1" >> /boot/config.txt '
sudo bash -c 'echo " " >> /boot/config.txt '
fi
fi
}
do_Safe_HDMI()
{
# change #enable_tvout=1 or enable_tvout=1 to #enable_tvout=1
# first check if "#enable_tvout=1" is in /boot/config.txt
grep -q "#enable_tvout=1" /boot/config.txt
if [ $? -ne 0 ]; then # "#enable_tvout=1" is not there, so check if "enable_tvout=1" is there
grep -q "enable_tvout=1" /boot/config.txt
if [ $? -eq 0 ]; then # "enable_tvout=1" is there, so replace it with "#enable_tvout=1"
sudo sed -i '/enable_tvout=1/c\#enable_tvout=1' /boot/config.txt >/dev/null 2>/dev/null
else # not there, so append the commented statement
sudo bash -c 'echo " " >> /boot/config.txt '
sudo bash -c 'echo "# Uncomment to enable Comp Vid output" >> /boot/config.txt '
sudo bash -c 'echo "#enable_tvout=1" >> /boot/config.txt '
sudo bash -c 'echo " " >> /boot/config.txt '
fi
fi
# change #hdmi_safe=1 or hdmi_safe=1 to hdmi_safe=1
# first check if "#hdmi_safe=1" is in /boot/config.txt
grep -q "#hdmi_safe=1" /boot/config.txt
if [ $? -eq 0 ]; then # "#hdmi_safe=1" is there, so change it to "hdmi_safe=1"
sudo sed -i '/#hdmi_safe=1/c\hdmi_safe=1' /boot/config.txt >/dev/null 2>/dev/null
else # "#hdmi_safe=1" is not there so check "hdmi_safe=1" is there
grep -q "hdmi_safe=1" /boot/config.txt
if [ $? -ne 0 ]; then # "hdmi_safe=1" is not there, so add it (else do nothing)
sudo bash -c 'echo " " >> /boot/config.txt '
sudo bash -c 'echo "# uncomment if you get no picture on HDMI for a default safe mode" >> /boot/config.txt '
sudo bash -c 'echo "hdmi_safe=1" >> /boot/config.txt '
sudo bash -c 'echo " " >> /boot/config.txt '
fi
fi
}
do_Comp_Vid_Aspect_4_3()
{
grep -q "sdtv_aspect=1" /boot/config.txt
if [ $? -ne 0 ]; then # "sdtv_aspect=1" is not there so change it
sudo sed -i 's/sdtv_aspect=3/sdtv_aspect=1/' /boot/config.txt
fi
}
do_Comp_Vid_Aspect_16_9()
{
grep -q "sdtv_aspect=3" /boot/config.txt
if [ $? -ne 0 ]; then # "sdtv_aspect=3" is not there so change it
sudo sed -i 's/sdtv_aspect=1/sdtv_aspect=3/' /boot/config.txt
fi
}
do_Comp_Vid_Aspect()
{
Radio1=OFF
Radio2=OFF
Radio3=OFF
grep -q "sdtv_aspect=1" /boot/config.txt
if [ $? -eq 0 ]; then # "sdtv_aspect=1" 4:3
Radio1=ON
else
grep -q "sdtv_aspect=3" /boot/config.txt
if [ $? -eq 0 ]; then # "sdtv_aspect=3" 16:9
Radio2=ON
else
Radio3=ON
fi
fi
NEW_VA=$(whiptail --title "Choose the Composite Video Aspect Ratio" --radiolist \
"Highlight choice, select with space bar and then press enter" 20 78 5 \
"4:3" "4:3 for older displays" $Radio1 \
"16:9" "16:9 for widescreen displays" $Radio2 \
"Not Set" "Defaults to 4:3" $Radio3 \
3>&2 2>&1 1>&3)
if [ $? -eq 0 ]; then
case "$NEW_VA" in
"4:3")
do_Comp_Vid_Aspect_4_3
;;
"16:9")
do_Comp_Vid_Aspect_16_9
;;
esac
fi
}
do_Comp_Vid_PAL()
{
# change #hdmi_safe=1 or hdmi_safe=1 to #hdmi_safe=1
# first check if "#hdmi_safe=1" is in /boot/config.txt
grep -q "#hdmi_safe=1" /boot/config.txt
if [ $? -ne 0 ]; then # "#hdmi_safe=1" is not there, so check if "hdmi_safe=1" is there
grep -q "hdmi_safe=1" /boot/config.txt
if [ $? -eq 0 ]; then # "hdmi_safe=1" is there, so replace it with "#hdmi_safe=1"
sudo sed -i '/hdmi_safe=1/c\#hdmi_safe=1' /boot/config.txt >/dev/null 2>/dev/null
else # not there, so append the commented statement
sudo bash -c 'echo " " >> /boot/config.txt '
sudo bash -c 'echo "# uncomment if you get no picture on HDMI for a default safe mode" >> /boot/config.txt '
sudo bash -c 'echo "#hdmi_safe=1" >> /boot/config.txt '
sudo bash -c 'echo " " >> /boot/config.txt '
fi
fi
#change #sdtv_mode=1/2 or sdtv_mode=1/2 to sdtv_mode=2
# first check if "#sdtv_mode=2" is in /boot/config.txt
grep -q "#sdtv_mode=2" /boot/config.txt
if [ $? -eq 0 ]; then # "#sdtv_mode=2" is there, so change it to "sdtv_mode=2"
sudo sed -i '/#sdtv_mode=2/c\sdtv_mode=2' /boot/config.txt >/dev/null 2>/dev/null
else # "#sdtv_mode=2" is not there so check if "#sdtv_mode=1" is there
grep -q "#sdtv_mode=1" /boot/config.txt
if [ $? -eq 0 ]; then # "#sdtv_mode=1" is there, so change it to "sdtv_mode=2"
sudo sed -i '/#sdtv_mode=1/c\sdtv_mode=2' /boot/config.txt >/dev/null 2>/dev/null
else # neither "#sdtv_mode=2" nor "#sdtv_mode=1" are there
grep -q "sdtv_mode=1" /boot/config.txt # so check if "sdtv_mode=1" is there
if [ $? -eq 0 ]; then # "sdtv_mode=1" is there, so change it to "sdtv_mode=2"
sudo sed -i '/sdtv_mode=1/c\sdtv_mode=2' /boot/config.txt >/dev/null 2>/dev/null
else # check if "sdtv_mode=2" is there and add it if not
grep -q "sdtv_mode=2" /boot/config.txt
if [ $? -ne 0 ]; then # "sdtv_mode=2" is not there, so add it at the end (else do nothing)
sudo bash -c 'echo " " >> /boot/config.txt '
sudo bash -c 'echo "# uncomment for composite PAL" >> /boot/config.txt '
sudo bash -c 'echo "sdtv_mode=2" >> /boot/config.txt '
sudo bash -c 'echo " " >> /boot/config.txt '
fi
fi
fi
fi
# change #enable_tvout=1 or enable_tvout=1 to enable_tvout=1 (Add if not present)
# first check if "#enable_tvout=1" is in /boot/config.txt
grep -q "#enable_tvout=1" /boot/config.txt
if [ $? -eq 0 ]; then # "#enable_tvout=1" is there, so replace it with "enable_tvout=1"
sudo sed -i '/#enable_tvout=1/c\enable_tvout=1' /boot/config.txt >/dev/null 2>/dev/null
else # "#enable_tvout=1" is not there, so check for "enable_tvout=1"
grep -q "enable_tvout=1" /boot/config.txt
if [ $? -ne 0 ]; then # "enable_tvout=1" is not there, so add it at the end (else do nothing)
sudo bash -c 'echo " " >> /boot/config.txt '
sudo bash -c 'echo "# Uncomment to enable Comp Vid output" >> /boot/config.txt '
sudo bash -c 'echo "enable_tvout=1" >> /boot/config.txt '
sudo bash -c 'echo " " >> /boot/config.txt '
fi
fi
# Ask about aspect ratio
do_Comp_Vid_Aspect
}
do_Comp_Vid_NTSC()
{
# change #hdmi_safe=1 or hdmi_safe=1 to #hdmi_safe=1
# first check if "#hdmi_safe=1" is in /boot/config.txt
grep -q "#hdmi_safe=1" /boot/config.txt
if [ $? -ne 0 ]; then # "#hdmi_safe=1" is not there, so check if "hdmi_safe=1" is there
grep -q "hdmi_safe=1" /boot/config.txt
if [ $? -eq 0 ]; then # "hdmi_safe=1" is there, so replace it with "#hdmi_safe=1"
sudo sed -i '/hdmi_safe=1/c\#hdmi_safe=1' /boot/config.txt >/dev/null 2>/dev/null
else # not there, so append the commented statement
sudo bash -c 'echo " " >> /boot/config.txt '
sudo bash -c 'echo "# uncomment if you get no picture on HDMI for a default safe mode" >> /boot/config.txt '
sudo bash -c 'echo "#hdmi_safe=1" >> /boot/config.txt '
sudo bash -c 'echo " " >> /boot/config.txt '
fi
fi
#change #sdtv_mode=1/2 or sdtv_mode=1/2 to sdtv_mode=1
# first check if "#sdtv_mode=1" is in /boot/config.txt
grep -q "#sdtv_mode=1" /boot/config.txt
if [ $? -eq 0 ]; then # "#sdtv_mode=1" is there, so change it to "sdtv_mode=1"
sudo sed -i '/#sdtv_mode=1/c\sdtv_mode=1' /boot/config.txt >/dev/null 2>/dev/null
else # "#sdtv_mode=1" is not there so check if "#sdtv_mode=2" is there
grep -q "#sdtv_mode=2" /boot/config.txt
if [ $? -eq 0 ]; then # "#sdtv_mode=2" is there, so change it to "sdtv_mode=1"
sudo sed -i '/#sdtv_mode=2/c\sdtv_mode=1' /boot/config.txt >/dev/null 2>/dev/null
else # neither "#sdtv_mode=1" nor "#sdtv_mode=2" are there
grep -q "sdtv_mode=2" /boot/config.txt # so check if "sdtv_mode=2" is there
if [ $? -eq 0 ]; then # "sdtv_mode=2" is there, so change it to "sdtv_mode=1"
sudo sed -i '/sdtv_mode=2/c\sdtv_mode=1' /boot/config.txt >/dev/null 2>/dev/null
else # check if "sdtv_mode=1" is there and add it if not
grep -q "sdtv_mode=1" /boot/config.txt
if [ $? -ne 0 ]; then # "sdtv_mode=1" is not there, so add it at the end (else do nothing)
sudo bash -c 'echo " " >> /boot/config.txt '
sudo bash -c 'echo "# uncomment for composite PAL" >> /boot/config.txt '
sudo bash -c 'echo "sdtv_mode=1" >> /boot/config.txt '
sudo bash -c 'echo " " >> /boot/config.txt '
fi
fi
fi
fi
# change #enable_tvout=1 or enable_tvout=1 to enable_tvout=1 (Add if not present)
# first check if "#enable_tvout=1" is in /boot/config.txt
grep -q "#enable_tvout=1" /boot/config.txt
if [ $? -eq 0 ]; then # "#enable_tvout=1" is there, so replace it with "enable_tvout=1"
sudo sed -i '/#enable_tvout=1/c\enable_tvout=1' /boot/config.txt >/dev/null 2>/dev/null
else # "#enable_tvout=1" is not there, so check for "enable_tvout=1"
grep -q "enable_tvout=1" /boot/config.txt
if [ $? -ne 0 ]; then # "enable_tvout=1" is not there, so add it at the end (else do nothing)
sudo bash -c 'echo " " >> /boot/config.txt '
sudo bash -c 'echo "# Uncomment to enable Comp Vid output" >> /boot/config.txt '
sudo bash -c 'echo "enable_tvout=1" >> /boot/config.txt '
sudo bash -c 'echo " " >> /boot/config.txt '
fi
fi
# Ask about aspect ratio
do_Comp_Vid_Aspect
}
do_Audio_Jack()
{
Radio1=OFF
Radio2=OFF
Radio3=OFF
Radio4=OFF
grep -q "^# vlcArgs += '--gain 4 --alsa-audio-device hw:CARD=Headphones,DEV=0 '" \
/home/pi/ryde/rydeplayer/player.py
if [ $? -eq 0 ]; then # Line commented, so HDMI currently selected
Radio1=ON
else
grep -q "^ vlcArgs += '--gain 4 --alsa-audio-device hw:CARD=Headphones,DEV=0 '" \
/home/pi/ryde/rydeplayer/player.py
if [ $? -eq 0 ]; then # RPi Jack currently selected
Radio2=ON
else
grep -q "^ vlcArgs += '--gain 4 --alsa-audio-device hw:CARD=Device,DEV=0 '" \
/home/pi/ryde/rydeplayer/player.py
if [ $? -eq 0 ]; then # USB Dongle currently selected
Radio3=ON
else
Radio4=ON
fi
fi
fi
AUDIO_JACK=$(whiptail --title "Choose the Audio Output Port" --radiolist \
"Highlight choice, select with space bar and then press enter" 20 78 6 \
"HDMI" "Audio on HDMI" $Radio1 \
"RPi Jack" "Audio on the RPi 3.5 mm Jack" $Radio2 \
"USB" "Audio on a White USB Dongle" $Radio3 \
"Not Set" "Defaults to same as video" $Radio4 \
3>&2 2>&1 1>&3)
if [ $? -eq 0 ]; then
case "$AUDIO_JACK" in
"HDMI")
sed -i "/--alsa-audio-device/c\# vlcArgs += '--gain 4 --alsa-audio-device hw:CARD=Headphones,DEV=0 '" \
/home/pi/ryde/rydeplayer/player.py
;;
"RPi Jack")
sed -i "/--alsa-audio-device/c\ vlcArgs += '--gain 4 --alsa-audio-device hw:CARD=Headphones,DEV=0 '" \
/home/pi/ryde/rydeplayer/player.py
;;
"USB")
sed -i "/--alsa-audio-device/c\ vlcArgs += '--gain 4 --alsa-audio-device hw:CARD=Device,DEV=0 '" \
/home/pi/ryde/rydeplayer/player.py
;;
esac
fi
REBOOT_REQUIRED=no
}
do_video_change()
{
REBOOT_REQUIRED=yes
menuchoice=$(whiptail --title "Video Output Menu" --menu "Select Choice" 16 78 6 \
"1 Normal HDMI" "Recommended Mode" \
"2 HDMI Safe Mode" "Use for HDMI Troubleshooting" \
"3 PAL Composite Video" "Use the RPi Video Output Jack" \
"4 NTSC Composite Video" "Use the RPi Video Output Jack" \
"5 Audio Output" "Change Audio Output Destination" \
3>&2 2>&1 1>&3)
case "$menuchoice" in
1\ *) do_Norm_HDMI ;;
2\ *) do_Safe_HDMI ;;
3\ *) do_Comp_Vid_PAL ;;
4\ *) do_Comp_Vid_NTSC ;;
5\ *) do_Audio_Jack ;;
esac
if [ "$REBOOT_REQUIRED" == "yes" ]; then
menuchoice=$(whiptail --title "Reboot Now?" --menu "Reboot to Apply Changes?" 16 78 10 \
"1 Yes" "Immediate Reboot" \
"2 No" "Apply changes at next Reboot" \
3>&2 2>&1 1>&3)
case "$menuchoice" in
1\ *) do_Reboot ;;
2\ *) do_Nothing ;;
esac
fi
}
do_SD_Button()
{
Radio1=OFF
Radio2=OFF
# Check current status
# If /home/pi/.pi-sdn exists then it is loaded
if test -f "/home/pi/.pi-sdn"; then
Radio1=ON
else
Radio2=ON
fi
SD_BUTTON=$(whiptail --title "Select Hardware Shutdown Function" --radiolist \
"Highlight choice, select with space bar and then press enter" 20 78 5 \
"SHUTDOWN" "RPi Immediately Shuts Down" $Radio1 \
"DO NOTHING" "Nothing happens" $Radio2 \
3>&2 2>&1 1>&3)
if [ $? -eq 0 ]; then
if [ "$SD_BUTTON" == "SHUTDOWN" ]; then
cp /home/pi/ryde-build/text.pi-sdn /home/pi/.pi-sdn ## Load it at logon
/home/pi/.pi-sdn ## Load it now
else
rm /home/pi/.pi-sdn >/dev/null 2>/dev/null ## Stop it being loaded at log-on
sudo pkill -x pi-sdn ## kill the current process
fi
fi
}
#"5 Power Button" "Set behaviour on double press of power button" \
#"6 Daily Reboot" "Enable 12-hourly reboot for Repeater Operation" \
#"7 Stop Reboot" "Disable 12-hourly reboot for Repeater Operation" \
#"8 Hardware Shutdown" "Enable or disable hardware shutdown function" \
#5\ *) do_Power_Button ;;
#6\ *) sudo crontab /home/pi/ryde-build/configs/rptrcron ;;
#7\ *) sudo crontab /home/pi/ryde-build/configs/blankcron ;;
#8\ *) do_SD_Button ;;
do_show_update_log()
{
reset
more /var/log/rptr/update_log.txt
printf "\nPress any key to return to the menu\n"
read -n 1
}
do_show_build_log()
{
reset
more /var/log/rptr/initial_build_log.txt
printf "\nPress any key to return to the menu\n"
read -n 1
}
do_show_log()
{
reset
if test -f "/var/log/rptr/error_log.txt"; then
echo "===ERROR LOG==="
echo
more /var/log/rptr/error_log.txt
else
echo "GOOD NEWS. The Error Log is empty"
fi
printf "\nPress any key to return to the menu\n"
read -n 1
}
do_info()
{
more /home/pi/atv-rptr/config/repeater_config.txt
printf "\nPress any key to return to the menu\n"
read -n 1
}
do_cmd_line_repeater()
{
reset
cd /home/pi
/home/pi/atv-rptr/utils/update_rptr.sh
printf "\nPress any key to return to the menu\n"
read -n 1
}
do_dtmf_codes()
{
reset
echo "Stopping the Repeater for DTMF Code Display"
echo
pkill run-audio.sh >/dev/null 2>/dev/null
pkill dtmf_listener.sh >/dev/null 2>/dev/null
sudo killall arecord >/dev/null 2>/dev/null
sudo killall -9 fbi >/dev/null 2>/dev/null
sudo killall rptr >/dev/null 2>/dev/null
sleep 1
# Check for audio card number
CARD="$(arecord -l \
| grep -E "USB Audio Device|USB AUDIO|Head|Sound Device" \
| head -c 6 | tail -c 1)"
echo
echo "Starting the DTMF Code Display."
echo
echo "Press ctrl-c to stop the display, restart the repeater"
echo "and return to the console menu"
echo
arecord -f S16_LE -r 48000 -c 1 -B 4800 -t raw -D plughw:"$CARD",0 \
| sox -c 1 -t raw -r 48000 -b 16 -e signed-integer - --buffer 1024 -t raw -b 16 - rate 22050 \
| multimon-ng -a DTMF -
sudo killall arecord >/dev/null 2>/dev/null
echo
echo "Restarting the Repeater"
# Put up the Start-up Splash Screen, which will be killed by the repeater process
sudo fbi -T 1 -noverbose -a /home/pi/atv-rptr/media/starting_up.jpg >/dev/null 2>/dev/null
echo
echo "Building the Captions....."
# Source the script to build the default captions
source /home/pi/atv-rptr/scripts/build_captions.sh
AUDIO_KEEP_ALIVE=$(get_config_var audiokeepalive $CONFIGFILE)
if [[ "$AUDIO_KEEP_ALIVE" == "yes" ]];
then
/home/pi/atv-rptr/scripts/run-audio.sh &
fi
# Start the DTMF Listener if required
DTMF_CONTROL=$(get_config_var dtmfcontrol $CONFIGFILE)
if [[ "$DTMF_CONTROL" == "on" ]];
then
ps cax | grep 'multimon-ng' > /dev/null
if [ $? -ne 0 ]; then
echo "DTMF Process is not running. Starting the DTMF Listener"
(/home/pi/atv-rptr/scripts/dtmf_listener.sh >/dev/null 2>/dev/null) &
fi
fi
echo
echo "Restarting the repeater controller"
(/home/pi/atv-rptr/bin/rptr >/dev/null 2>/dev/null) &
}
do_dtmf_replay()
{
reset
echo "Stopping the Repeater for DTMF Pass-through"
pkill run-audio.sh >/dev/null 2>/dev/null
pkill dtmf_listener.sh >/dev/null 2>/dev/null
sudo killall arecord >/dev/null 2>/dev/null
sudo killall -9 fbi >/dev/null 2>/dev/null
sudo killall rptr >/dev/null 2>/dev/null
sleep 1
# Check for audio card number
CARD="$(arecord -l \
| grep -E "USB Audio Device|USB AUDIO|Head|Sound Device" \
| head -c 6 | tail -c 1)"
# Set audio gain (0 - 100, default 62)
AUDIO_GAIN=$(get_config_var dtmfaudiogain $CONFIGFILE)
AUDIO_GAIN+="%"
echo
echo "Setting the DTMF Mic Capture gain to "$AUDIO_GAIN
amixer -c $CARD -- sset Mic Capture $AUDIO_GAIN >/dev/null 2>/dev/null
echo
echo "Setting the HDMI Audio Gain to Max"
amixer -c 0 -- sset HDMI Playback Volume 100% >/dev/null 2>/dev/null
echo
echo "Starting the audio pass-through."
echo
echo "You should now hear undistorted DTMF Audio on the HDMI output"
echo
echo "Press any key to stop the pass-through, restart the repeater"
echo "and return to the console menu"
echo
(arecord -f S16_LE -r 48000 -c 1 -B 4800 -t raw -D plughw:"$CARD",0 2>/dev/null \
| aplay -f S16_LE -r 48000 -c 1 -D plughw:CARD=b1,DEV=0 >/dev/null 2>/dev/null) &
read -n 1
sudo killall arecord >/dev/null 2>/dev/null
echo
echo "Restarting the Repeater"
# Put up the Start-up Splash Screen, which will be killed by the repeater process
sudo fbi -T 1 -noverbose -a /home/pi/atv-rptr/media/starting_up.jpg >/dev/null 2>/dev/null
echo
echo "Building the Captions....."
# Source the script to build the default captions
source /home/pi/atv-rptr/scripts/build_captions.sh
AUDIO_KEEP_ALIVE=$(get_config_var audiokeepalive $CONFIGFILE)
if [[ "$AUDIO_KEEP_ALIVE" == "yes" ]];
then
/home/pi/atv-rptr/scripts/run-audio.sh &
fi
# Start the DTMF Listener if required
DTMF_CONTROL=$(get_config_var dtmfcontrol $CONFIGFILE)
if [[ "$DTMF_CONTROL" == "on" ]];
then
ps cax | grep 'multimon-ng' > /dev/null
if [ $? -ne 0 ]; then
echo "DTMF Process is not running. Starting the DTMF Listener"
(/home/pi/atv-rptr/scripts/dtmf_listener.sh >/dev/null 2>/dev/null) &
fi
fi
echo
echo "Restarting the repeater controller"
(/home/pi/atv-rptr/bin/rptr >/dev/null 2>/dev/null) &
}
do_diagnostics()
{
status=0
while [ "$status" -eq 0 ]
do
menuchoice=$(whiptail --title "Repeater Diagnostics Menu" --menu "Select Choice" 20 78 8 \
"1 Config" "Show Repeater Configuration File" \
"2 Log File" "Show Repeater Error Log File" \
"3 Build Log" "Show Initial Build Log File" \
"4 Update Log" "Show Latest Update Log File" \
"5 Rptr Test" "Run Repeater with the ability to read errors" \
"6 DTMF Replay" "Listen to the DTMF Input on the HDMI Audio" \
"7 DTMF Codes" "Display the decoded DTMF Codes" \
"8 Main Menu" "Go back to the Main Menu" \
3>&2 2>&1 1>&3)
case "$menuchoice" in
1\ *) do_info ;;
2\ *) do_show_log ;;
3\ *) do_show_build_log ;;
4\ *) do_show_update_log ;;
5\ *) do_cmd_line_repeater ;;
6\ *) do_dtmf_replay ;;
7\ *) do_dtmf_codes ;;
8\ *) status=1 ;;
esac
done
status=0
}
do_Audio_Port()
{
AUDIO_PORT=$(get_config_var audioout $CONFIGFILE)
Radio1=OFF
Radio2=OFF
Radio3=OFF
if [[ "$AUDIO_PORT" == "hdmi" ]];
then
Radio1=ON
fi
if [[ "$AUDIO_PORT" == "jack" ]];
then
Radio2=ON
fi
if [[ "$AUDIO_PORT" == "usb" ]];
then
Radio3=ON
fi
AUDIO_PORT=$(whiptail --title "Select Audio Output Port for Ident and K CW" --radiolist \
"Highlight choice, select with space bar and then press enter" 20 78 6 \
"hdmi" "Audio on HDMI Output" $Radio1 \
"jack" "Audio on RPi 3.5mm jack" $Radio2 \
"usb" "Audio on USB Audio Dongle" $Radio3 \
3>&2 2>&1 1>&3)
if [ $? -eq 0 ]; then
set_config_var audioout $AUDIO_PORT $CONFIGFILE
fi
}
do_Check_HDMI()
{
reset
tvservice -n
tvservice -s
cd /home/pi
read -p "Press enter to continue"
}
do_Restore_Factory()
{
cp /home/pi/home/pi/atv-rptr/config/repeater_config.txt.factory /home/pi/home/pi/atv-rptr/config/repeater_config
# Wait here until user presses a key
whiptail --title "Factory Setting Restored" --msgbox "Touch any key to continue." 8 78
}
do_Settings()
{
status=0
while [ "$status" -eq 0 ]
do
menuchoice=$(whiptail --title "Advanced Settings Menu" --menu "Select Choice and press enter" 16 78 9 \
"1 Restore Factory" "Reset all settings to default" \
"2 Check HDMI" "List HDMI settings for fault-finding" \
"3 Audio Port" "Choose output port for Ident and K CW" \
"4 Main Menu" "Go back to the Main Menu" \
3>&2 2>&1 1>&3)
case "$menuchoice" in
1\ *) do_Restore_Factory ;;
2\ *) do_Check_HDMI ;;
3\ *) do_Audio_Port ;;
4\ *) status=1 ;;
esac
done
status=0
}
do_update()
{
/home/pi/atv-rptr/scripts/check_for_update.sh
}
do_update_menu()
{
INSTALLEDVERSION=$(head -c 9 /home/pi/atv-rptr/config/installed_version.txt)
status=0
while [ "$status" -eq 0 ]
do
menuchoice=$(whiptail --title "Current Version is "$INSTALLEDVERSION"" --menu "Select Choice" 20 78 7 \
"1 Update" "Update Repeater Software" \
"2 Main Menu" "Go back to the Main Menu" \
3>&2 2>&1 1>&3)
case "$menuchoice" in
1\ *) do_update ;;
2\ *) status=1 ;;
esac
done
status=0
}
do_normal_repeat()
{
echo "00" > /dev/udp/127.0.0.1/8888 #>/dev/null 2>/dev/null
}
do_status()
{
echo "01" > /dev/udp/127.0.0.1/8888 #>/dev/null 2>/dev/null
}
do_quad()
{
echo "04" > /dev/udp/127.0.0.1/8888 #>/dev/null 2>/dev/null
}
do_0()
{
echo "10" > /dev/udp/127.0.0.1/8888 #>/dev/null 2>/dev/null
}
do_1()
{
echo "11" > /dev/udp/127.0.0.1/8888 #>/dev/null 2>/dev/null
}
do_2()
{
echo "12" > /dev/udp/127.0.0.1/8888 #>/dev/null 2>/dev/null
}
do_3()
{
echo "13" > /dev/udp/127.0.0.1/8888 #>/dev/null 2>/dev/null
}
do_4()
{
echo "14" > /dev/udp/127.0.0.1/8888 #>/dev/null 2>/dev/null
}
do_5()
{
echo "15" > /dev/udp/127.0.0.1/8888 #>/dev/null 2>/dev/null
}
do_6()
{
echo "16" > /dev/udp/127.0.0.1/8888 #>/dev/null 2>/dev/null
}
do_7()
{
echo "17" > /dev/udp/127.0.0.1/8888 #>/dev/null 2>/dev/null
}
do_input_control()
{
status="0"
while [ "$status" -eq 0 ]
do
INPUT1NAME=$(get_config_var input1name $CONFIGFILE)
INPUT2NAME=$(get_config_var input2name $CONFIGFILE)
INPUT3NAME=$(get_config_var input3name $CONFIGFILE)
INPUT4NAME=$(get_config_var input4name $CONFIGFILE)
INPUT5NAME=$(get_config_var input5name $CONFIGFILE)
INPUT6NAME=$(get_config_var input6name $CONFIGFILE)
INPUT7NAME=$(get_config_var input7name $CONFIGFILE)
menuchoice=$(whiptail --title "Direct Input Control Menu" --menu "Select Choice and press enter" 20 78 12 \
"1 Input 1" "$INPUT1NAME" \
"2 Input 2" "$INPUT2NAME" \
"3 Input 3" "$INPUT3NAME" \
"4 Input 4" "$INPUT4NAME" \
"5 Input 5" "$INPUT5NAME" \
"6 Input 6" "$INPUT6NAME" \
"7 Input 7" "$INPUT7NAME" \
"8 Controller" "Show Controller Screen" \
"9 Status" "Show Status Screen" \
"10 Quad" "Show Quad View" \
"11 Normal" "Normal Repeater Operation" \
"12 Main menu" "Return to Main Menu" \
3>&2 2>&1 1>&3)
case "$menuchoice" in
1\ *) do_1 ;;
2\ *) do_2 ;;
3\ *) do_3 ;;
4\ *) do_4 ;;
5\ *) do_5 ;;
6\ *) do_6 ;;
7\ *) do_7 ;;
8\ *) do_0 ;;
9\ *) do_status ;;
10\ *) do_quad ;;
11\ *) do_normal_repeat ;;
12\ *) status="1" ;;
esac
done
status="0"
}
do_callsign()
{
CALL=$(get_config_var callsign $CONFIGFILE)
CALL=$(whiptail --inputbox "Enter Callsign (no spaces)" 8 78 $CALL --title "Set Repeater Callsign" 3>&1 1>&2 2>&3)
if [ $? -eq 0 ]; then
set_config_var callsign "$CALL" $CONFIGFILE
fi
LOCATOR=$(get_config_var locator $CONFIGFILE)
LOCATOR=$(whiptail --inputbox "Enter Locator (no spaces)" 8 78 $LOCATOR --title "Set Repeater Locator" 3>&1 1>&2 2>&3)
if [ $? -eq 0 ]; then
set_config_var locator "$LOCATOR" $CONFIGFILE
fi
}
do_Active_Hold()
{
ACTIVE_HOLD=$(get_config_var activeinputhold $CONFIGFILE)
if [[ "$ACTIVE_HOLD" == "yes" ]];
then
Radio1=ON
Radio2=OFF
else
Radio1=OFF
Radio2=ON
fi
ACTIVE_HOLD=$(whiptail --title "Choose Whether to Hold an Active Input" --radiolist \
"Highlight choice, select with space bar and then press enter" 20 78 6 \
"yes" "Active Input retains Repeater for all except Priority 1 Inputs" $Radio1 \
"no" "Active Input is dropped in favour of any higher priority Input" $Radio2 \
3>&2 2>&1 1>&3)
if [ $? -eq 0 ]; then
set_config_var activeinputhold $ACTIVE_HOLD $CONFIGFILE
fi
}
do_Input_Count()
{
INPUT_COUNT=$(get_config_var availableinputs $CONFIGFILE)
INPUT_COUNT=$(whiptail --inputbox "Enter the number of active inputs" 8 78 $INPUT_COUNT --title "Set Number of Inputs" 3>&1 1>&2 2>&3)
if [ $? -eq 0 ]; then
if [ $INPUT_COUNT -ge 1 ] && [ $INPUT_COUNT -le 7 ]; then
set_config_var availableinputs "$INPUT_COUNT" $CONFIGFILE
else
whiptail --title "ERROR" --msgbox "Please enter an input count between 1 and 7. Press enter to continue" 8 78
fi
fi
}
do_Priority1()
{
INPUT1PRIORITY=$(get_config_var input1prioritylevel $CONFIGFILE)
INPUT1NAME=$(get_config_var input1name $CONFIGFILE)
INPUT1PRIORITY=$(whiptail --inputbox "$INPUT1NAME Priority:" 8 78 $INPUT1PRIORITY --title "Set Input 1 Priority (9 to disable)" 3>&1 1>&2 2>&3)
if [ $? -eq 0 ]; then
if [ $INPUT1PRIORITY -ge 1 ] && [ $INPUT1PRIORITY -le 9 ]; then
set_config_var input1prioritylevel "$INPUT1PRIORITY" $CONFIGFILE
else
whiptail --title "ERROR" --msgbox "Please enter an input priority between 1 and 9. Press enter to continue" 8 78
fi
fi
}
do_Priority2()
{
INPUT2PRIORITY=$(get_config_var input2prioritylevel $CONFIGFILE)
INPUT2NAME=$(get_config_var input2name $CONFIGFILE)
INPUT2PRIORITY=$(whiptail --inputbox "$INPUT2NAME Priority:" 8 78 $INPUT2PRIORITY --title "Set Input 2 Priority (9 to disable)" 3>&1 1>&2 2>&3)
if [ $? -eq 0 ]; then
if [ $INPUT2PRIORITY -ge 1 ] && [ $INPUT2PRIORITY -le 9 ]; then
set_config_var input2prioritylevel "$INPUT2PRIORITY" $CONFIGFILE
else
whiptail --title "ERROR" --msgbox "Please enter an input priority between 1 and 9. Press enter to continue" 8 78
fi
fi
}
do_Priority3()
{
INPUT3PRIORITY=$(get_config_var input3prioritylevel $CONFIGFILE)
INPUT3NAME=$(get_config_var input3name $CONFIGFILE)
INPUT3PRIORITY=$(whiptail --inputbox "$INPUT3NAME Priority:" 8 78 $INPUT3PRIORITY --title "Set Input 3 Priority (9 to disable)" 3>&1 1>&2 2>&3)
if [ $? -eq 0 ]; then
if [ $INPUT3PRIORITY -ge 1 ] && [ $INPUT3PRIORITY -le 9 ]; then
set_config_var input3prioritylevel "$INPUT3PRIORITY" $CONFIGFILE
else
whiptail --title "ERROR" --msgbox "Please enter an input priority between 1 and 9. Press enter to continue" 8 78
fi
fi
}
do_Priority4()
{
INPUT4PRIORITY=$(get_config_var input4prioritylevel $CONFIGFILE)
INPUT4NAME=$(get_config_var input4name $CONFIGFILE)
INPUT4PRIORITY=$(whiptail --inputbox "$INPUT4NAME Priority:" 8 78 $INPUT4PRIORITY --title "Set Input 4 Priority (9 to disable)" 3>&1 1>&2 2>&3)
if [ $? -eq 0 ]; then
if [ $INPUT4PRIORITY -ge 1 ] && [ $INPUT4PRIORITY -le 9 ]; then
set_config_var input4prioritylevel "$INPUT4PRIORITY" $CONFIGFILE