-
-
Notifications
You must be signed in to change notification settings - Fork 495
/
dietpi-config
executable file
·3961 lines (3155 loc) · 147 KB
/
dietpi-config
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
{
#////////////////////////////////////
# DietPi-Config Script
#
#////////////////////////////////////
# Created by Daniel Knight / daniel.knight@dietpi.com / dietpi.com
#
#////////////////////////////////////
#
# Info:
# - Location: /boot/dietpi/dietpi-config
#
# Usage:
# dietpi-config [TARGETMENUID]
# - TARGETMENUID=n - Launch DietPi-Config at given TARGETMENUID and exit DietPi-Config directly from this menu
#////////////////////////////////////
# Import DietPi-Globals --------------------------------------------------------------
. /boot/dietpi/func/dietpi-globals
readonly G_PROGRAM_NAME='DietPi-Config'
G_CHECK_ROOT_USER
G_CHECK_ROOTFS_RW
G_INIT
# Import DietPi-Globals --------------------------------------------------------------
# Grab input
[[ $1 =~ ^[1-9][0-9]*$ ]] && TARGETMENUID=$1 || TARGETMENUID=0
#/////////////////////////////////////////////////////////////////////////////////////
# MENUS
#/////////////////////////////////////////////////////////////////////////////////////
EXITONMENUID=$TARGETMENUID
WHIP_SELECTION_PREVIOUS=
REBOOT_REQUIRED=0
# Integer min/max value holders
MIN_VALUE=0
MAX_VALUE=0
Info_HW_OptionNotSupported(){ G_WHIP_MSG "This option is not available for $G_HW_MODEL_NAME"; }
# TARGETMENUID=-1
# $1: TARGETMENUID to return to
Back_or_Exit()
{
# If this is not the menu to exit from, return to input (parent) menu
(( $EXITONMENUID == $TARGETMENUID )) || { TARGETMENUID=$1; return 0; }
# Offer to reboot if required to apply changes and when not run from dietpi-software
(( $REBOOT_REQUIRED )) && ! pgrep 'dietpi-software' > /dev/null && G_WHIP_YESNO 'A reboot is required to apply your new settings.\nWould you like to reboot now?' && reboot
# Apply exit ID
TARGETMENUID=-1
}
# TARGETMENUID=0
Menu_Main()
{
G_WHIP_MENU_ARRAY=(
'1' ': Display Options'
'2' ': Audio Options'
)
# Hide performance options on VM and container
(( $G_HW_MODEL == 20 || $G_HW_MODEL == 75 )) || G_WHIP_MENU_ARRAY+=('3' ': Performance Options')
G_WHIP_MENU_ARRAY+=(
'4' ': Advanced Options'
'5' ': Language/Regional Options'
'6' ': Security Options'
'7' ': Network Options: Adapters'
'8' ': Network Options: Misc'
'9' ': AutoStart Options'
'10' ': Tools'
)
G_WHIP_MENU "Hardware : $G_HW_MODEL_NAME" || { Back_or_Exit 0; return 0; }
case $G_WHIP_RETURNED_VALUE in
1) TARGETMENUID=1;;
2) TARGETMENUID=14;;
3) TARGETMENUID=4;;
4) TARGETMENUID=3;;
5) TARGETMENUID=7;;
6) TARGETMENUID=5;;
7) TARGETMENUID=8;;
8) TARGETMENUID=16;;
9) /boot/dietpi/dietpi-autostart;;
10) TARGETMENUID=11;;
*) :;;
esac
}
# $1: 0=landscape 1=portrait
Display_Rotation_Calc_XY_Invert()
{
local framebuffer_x=$(grep -m1 '^[[:blank:]]*framebuffer_width=' /boot/config.txt || vcgencmd get_config framebuffer_width)
framebuffer_x=${framebuffer_x#*=}; framebuffer_x=${framebuffer_x:-0}
local framebuffer_y=$(grep -m1 '^[[:blank:]]*framebuffer_height=' /boot/config.txt || vcgencmd get_config framebuffer_height)
framebuffer_y=${framebuffer_y#*=}; framebuffer_y=${framebuffer_y:-0}
# 0/180 landscape
if (( $1 == 0 && $framebuffer_x < $framebuffer_y ))
then
G_CONFIG_INJECT 'framebuffer_width=' "framebuffer_width=$framebuffer_y" /boot/config.txt
G_CONFIG_INJECT 'framebuffer_height=' "framebuffer_height=$framebuffer_x" /boot/config.txt
# 90/270 portrait
elif (( $1 == 1 && $framebuffer_x > $framebuffer_y ))
then
G_CONFIG_INJECT 'framebuffer_width=' "framebuffer_width=$framebuffer_y" /boot/config.txt
G_CONFIG_INJECT 'framebuffer_height=' "framebuffer_height=$framebuffer_x" /boot/config.txt
fi
}
# TARGETMENUID=1
Menu_DisplayOptions()
{
# Driver/Resolution
if (( $G_HW_MODEL == 21 ))
then
G_WHIP_MENU_ARRAY=('1' ': Display Driver')
else
G_WHIP_MENU_ARRAY=('1' ': Display Resolution')
if (( $G_HW_MODEL < 20 ))
then
local lcdpanel_text=$(sed -n '/^[[:blank:]]*CONFIG_LCDPANEL=/{s/^[^=]*=//p;q}' /boot/dietpi.txt)
G_WHIP_MENU_ARRAY+=('3' ": LCD/OLED Panel addon: [${lcdpanel_text:=none}]")
fi
fi
# Brightness
G_WHIP_MENU_ARRAY+=('16' ': Display Brightness')
# X11 DPI
local xorg_dpi_current=$(sed -n '/^[[:blank:]]*SOFTWARE_XORG_DPI=/{s/^[^=]*=//p;q}' /boot/dietpi.txt)
G_WHIP_MENU_ARRAY+=('17' ": X.Org DPI: [${xorg_dpi_current:-N/A}]")
# LED control: Hide on VM/container
(( $G_HW_MODEL == 20 || $G_HW_MODEL == 75 )) || G_WHIP_MENU_ARRAY+=('14' ': LED Control')
# RPi only
if (( $G_HW_MODEL < 10 ))
then
# GPU memory split
G_WHIP_MENU_ARRAY+=('2' ': GPU/RAM memory split')
# HDMI rotation
local rotation_hdmi_current=$(sed -n '/^[[:blank:]]*display_hdmi_rotate=/{s/^[^=]*=//p;q}' /boot/config.txt)
G_WHIP_MENU_ARRAY+=('4' ": Rotation (HDMI) : [${rotation_hdmi_current:=0}]")
# LCD rotation
local rotation_lcd_current=$(sed -n '/^[[:blank:]]*lcd_rotate=/{s/^[^=]*=//p;q}' /boot/config.txt)
G_WHIP_MENU_ARRAY+=('5' ": Rotation (LCD) : [${rotation_lcd_current:=0}]")
# Display overscan
local overscan_disabled=$(grep -cm1 '^[[:blank:]]*disable_overscan=1' /boot/config.txt)
local overscan_text='On'
(( $overscan_disabled )) && overscan_text='Off'
G_WHIP_MENU_ARRAY+=('6' ": Overscan : [$overscan_text]")
# - Overscan sizes
if (( ! $overscan_disabled ))
then
local overscan_options=('overscan_left' 'overscan_right' 'overscan_top' 'overscan_bottom')
local overscan_left=$(grep -m1 '^[[:blank:]]*overscan_left=' /boot/config.txt || vcgencmd get_config overscan_left); overscan_left=${overscan_left#*=}
local overscan_right=$(grep -m1 '^[[:blank:]]*overscan_right=' /boot/config.txt || vcgencmd get_config overscan_right); overscan_right=${overscan_right#*=}
local overscan_top=$(grep -m1 '^[[:blank:]]*overscan_top=' /boot/config.txt || vcgencmd get_config overscan_top); overscan_top=${overscan_top#*=}
local overscan_bottom=$(grep -m1 '^[[:blank:]]*overscan_bottom=' /boot/config.txt || vcgencmd get_config overscan_bottom); overscan_bottom=${overscan_bottom#*=}
G_WHIP_MENU_ARRAY+=('15' ": Overscan Compensation [L:${overscan_left:-N/A}] [R:${overscan_right:-N/A}] [T:${overscan_top:-N/A}] [B:${overscan_bottom:-N/A}]")
fi
# HDMI signal boost, RPi up to 3 only
if (( $G_HW_MODEL < 4 ))
then
local hdmi_boost_current=$(grep -m1 '^[[:blank:]]*config_hdmi_boost=' /boot/config.txt || vcgencmd get_config config_hdmi_boost); hdmi_boost_current=${hdmi_boost_current#*=}
G_WHIP_MENU_ARRAY+=('7' ": HDMI Boost : [${hdmi_boost_current:-N/A}]")
fi
# RPi codecs
local rpi_codecs_enabled=0 rpi_codecs_text='Off'
[[ -f '/etc/modprobe.d/dietpi-disable_rpi_codec.conf' ]] || rpi_codecs_enabled=1 rpi_codecs_text='On'
G_WHIP_MENU_ARRAY+=('18' ": RPi Codecs : [$rpi_codecs_text] V4L2 hardware video codecs")
# RPi camera module
local rpi_camera_module_enabled=$(grep -cm1 '^[[:blank:]]*start_x=1' /boot/config.txt)
local rpi_camera_module_text='Off'
(( $rpi_camera_module_enabled )) && rpi_camera_module_text='On'
G_WHIP_MENU_ARRAY+=('8' ": RPi Camera : [$rpi_camera_module_text]")
# RPi camera LED
local rpi_camera_led_disabled=$(grep -cm1 '^[[:blank:]]*disable_camera_led=1' /boot/config.txt)
local rpi_camera_led_text='On'
(( $rpi_camera_led_disabled )) && rpi_camera_led_text='Off'
G_WHIP_MENU_ARRAY+=('9' ": RPi Camera LED : [$rpi_camera_led_text]")
# JustBoom IR Remote
local justboom_ir_remote_text='Off' justboom_ir_remote_enabled=0
[[ -f '/etc/systemd/system/justboom-ir-mpd.service' ]] && justboom_ir_remote_text='On' justboom_ir_remote_enabled=1
G_WHIP_MENU_ARRAY+=('11' ": JustBoom IR remote : [$justboom_ir_remote_text]")
# VC1 key
local vc1_key_current=$(sed -n '/^[[:blank:]]*decode_WVC1=/{s/^[^=]*=//p;q}' /boot/config.txt)
G_WHIP_MENU_ARRAY+=('12' ": VC1 Key : [${vc1_key_current:-none}]")
# MPEG2 key
local mpeg2_key_current=$(sed -n '/^[[:blank:]]*decode_MPG2=/{s/^[^=]*=//p;q}' /boot/config.txt)
G_WHIP_MENU_ARRAY+=('13' ": MPEG2 Key : [${mpeg2_key_current:-none}]")
# Odroids only
elif (( $G_HW_MODEL < 13 ))
then
# Remote
local odroid_remote_text='Off'
local odroid_remote_enabled=0
if grep -Eq '^[[:blank:]]*(gpio-ir-recv|meson_ir)[[:blank:]]*$' /etc/modules || systemctl -q is-enabled lircd 2> /dev/null
then
odroid_remote_text='On'
odroid_remote_enabled=1
fi
G_WHIP_MENU_ARRAY+=('10' ": Odroid remote : [$odroid_remote_text]")
fi
G_WHIP_DEFAULT_ITEM=$WHIP_SELECTION_PREVIOUS
G_WHIP_MENU 'Please select an option:' || { Back_or_Exit 0; return 0; } # Main menu
WHIP_SELECTION_PREVIOUS=$G_WHIP_RETURNED_VALUE
if (( $G_WHIP_RETURNED_VALUE == 15 ))
then
for i in "${overscan_options[@]}"
do
G_WHIP_DEFAULT_ITEM=${!i}
G_WHIP_INPUTBOX "Please enter a value (pixel count) for $i\n - E.g.: 16" || break
G_CONFIG_INJECT "$i=" "$i=$G_WHIP_RETURNED_VALUE" /boot/config.txt
REBOOT_REQUIRED=1
done
elif (( $G_WHIP_RETURNED_VALUE == 1 ))
then
TARGETMENUID=2
elif (( $G_WHIP_RETURNED_VALUE == 3 ))
then
G_WHIP_MENU_ARRAY=('none' ': Uninstall all panels')
G_WHIP_MENU_ARRAY+=('waveshare32' ': 320x240 panel with touch input')
if (( $G_HW_MODEL < 10 ))
then
G_WHIP_MENU_ARRAY+=('esp01215e' ': Elecrow 1024x600 7" IPS HDMI panel with touch input')
G_WHIP_MENU_ARRAY+=('allo-boss2-oled' ': Allo Boss2 DAC OLED display')
else
G_WHIP_MENU_ARRAY+=('odroid-lcd35' ': 480x320 panel with touch input')
(( $G_HW_MODEL == 11 )) && G_WHIP_MENU_ARRAY+=('odroid-cloudshell' ': 320x240 panel' 'odroid-cloudshell2' ': Odroid XU4 CloudShell 2 LCD')
fi
G_WHIP_DEFAULT_ITEM=$lcdpanel_text
G_WHIP_MENU 'Please select an option:' || return 0
/boot/dietpi/func/dietpi-set_hardware lcdpanel "$G_WHIP_RETURNED_VALUE" && REBOOT_REQUIRED=1
elif (( $G_WHIP_RETURNED_VALUE == 2 ))
then
TARGETMENUID=6
elif (( $G_WHIP_RETURNED_VALUE == 6 ))
then
if (( $overscan_disabled ))
then
G_CONFIG_INJECT 'disable_overscan=' 'disable_overscan=0' /boot/config.txt
else
G_CONFIG_INJECT 'disable_overscan=' 'disable_overscan=1' /boot/config.txt
for i in "${overscan_options[@]}"
do
sed --follow-symlinks -i "/^[[:blank:]]*$i=/c\#$i=0" /boot/config.txt
done
fi
REBOOT_REQUIRED=1
elif (( $G_WHIP_RETURNED_VALUE == 7 ))
then
G_WHIP_MENU_ARRAY=(
'0' ': Disabled'
'2' ': RPi 1 A/B Default'
'5' ': RPi 1+/2/3 Default'
'6' ''
'7' ': High (May increase stability)'
'8' ''
'9' ''
'10' ''
'11' ': Max (Not recommended)'
)
G_WHIP_DEFAULT_ITEM=$hdmi_boost_current
G_WHIP_MENU 'Please select a HDMI boost level.\n
A long (or insufficiently manufactured) cable may required a higher boost setting to achieve correct signal.' || return 0
G_CONFIG_INJECT 'config_hdmi_boost=' "config_hdmi_boost=$G_WHIP_RETURNED_VALUE" /boot/config.txt && REBOOT_REQUIRED=1
elif (( $G_WHIP_RETURNED_VALUE == 18 ))
then
/boot/dietpi/func/dietpi-set_hardware rpi-codec $(( ! $rpi_codecs_enabled )) && REBOOT_REQUIRED=1
elif (( $G_WHIP_RETURNED_VALUE == 8 ))
then
/boot/dietpi/func/dietpi-set_hardware rpi-camera $(( ! $rpi_camera_module_enabled )) && REBOOT_REQUIRED=1
elif (( $G_WHIP_RETURNED_VALUE == 9 ))
then
G_CONFIG_INJECT 'disable_camera_led=' "disable_camera_led=$(( ! $rpi_camera_led_disabled ))" /boot/config.txt && REBOOT_REQUIRED=1
elif (( $G_WHIP_RETURNED_VALUE == 10 ))
then
if (( $odroid_remote_enabled ))
then
/boot/dietpi/func/dietpi-set_hardware remoteir none && REBOOT_REQUIRED=1
elif G_WHIP_YESNO 'This will enable the IR modules, setup Lirc and the Odroid Remote for Odroid C1, C2 and XU4 CloudShell.
\nNB: Other remotes can be configured by running "irrecord" and applying the codes to "/etc/lirc/lircd.conf"\n\nDo you wish to continue?'
then
/boot/dietpi/func/dietpi-set_hardware remoteir odroid_remote && REBOOT_REQUIRED=1
fi
elif (( $G_WHIP_RETURNED_VALUE == 11 ))
then
if (( $justboom_ir_remote_enabled ))
then
/boot/dietpi/func/dietpi-set_hardware remoteir none && REBOOT_REQUIRED=1
elif G_WHIP_YESNO 'Got a JustBoom IR Remote? Excellent!
\nDietPi will enable the IR modules, setup Lirc and enable support for MPD controls by default:\n\nDo you wish to continue?'
then
/boot/dietpi/func/dietpi-set_hardware remoteir justboom_ir_remote && REBOOT_REQUIRED=1
fi
elif (( $G_WHIP_RETURNED_VALUE == 12 ))
then
G_WHIP_DEFAULT_ITEM=$vc1_key_current
if G_WHIP_INPUTBOX 'Please enter your key for VC1:\n - EG: 0x00000000'
then
G_CONFIG_INJECT 'decode_WVC1=' "decode_WVC1=$G_WHIP_RETURNED_VALUE" /boot/config.txt
# https://github.com/MichaIng/DietPi/issues/1487
local current_gpu_mem=$(sed -n '/^[[:blank:]]*gpu_mem_1024=/{s/^[^=]*=//p;q}' /boot/config.txt)
(( ${current_gpu_mem:=76} < 96 )) && /boot/dietpi/func/dietpi-set_hardware gpumemsplit 96
REBOOT_REQUIRED=1
fi
elif (( $G_WHIP_RETURNED_VALUE == 13 ))
then
G_WHIP_DEFAULT_ITEM=$mpeg2_key_current
if G_WHIP_INPUTBOX 'Please enter your key for MPEG2:\n - EG: 0x00000000'
then
G_CONFIG_INJECT 'decode_MPG2=' "decode_MPG2=$G_WHIP_RETURNED_VALUE" /boot/config.txt
# https://github.com/MichaIng/DietPi/issues/1487
local current_gpu_mem=$(sed -n '/^[[:blank:]]*gpu_mem_1024=/{s/^[^=]*=//p;q}' /boot/config.txt)
(( ${current_gpu_mem:=76} < 96 )) && /boot/dietpi/func/dietpi-set_hardware gpumemsplit 96
REBOOT_REQUIRED=1
fi
elif (( $G_WHIP_RETURNED_VALUE == 4 ))
then
G_WHIP_MENU_ARRAY=(
'0' ': Disabled (default)'
'1' ': 90 degrees'
'2' ': 180 degrees'
'3' ': 270 degrees'
'0x10000' ': Horizontal flip'
'0x20000' ': Vertical flip'
)
G_WHIP_DEFAULT_ITEM=$rotation_hdmi_current
G_WHIP_MENU "Please select an option:
\nNB: If you have the RPi touchscreen, please set this to 0 and use LCD rotation option." || return 0
G_CONFIG_INJECT 'display_hdmi_rotate=' "display_hdmi_rotate=$G_WHIP_RETURNED_VALUE" /boot/config.txt
# rotation 90/270 | invert x/y on framebuffer (Y > X)
if [[ $G_WHIP_RETURNED_VALUE == [13] ]]
then
Display_Rotation_Calc_XY_Invert 1
# X > Y
else
Display_Rotation_Calc_XY_Invert 0
fi
REBOOT_REQUIRED=1
elif (( $G_WHIP_RETURNED_VALUE == 5 ))
then
G_WHIP_MENU_ARRAY=(
'0' ': Disabled (default)'
'2' ': 180 degrees'
)
G_WHIP_DEFAULT_ITEM=$rotation_lcd_current
if G_WHIP_MENU 'Please select an option:\n\nNB: This option is for RPi touchscreen.'
then
G_CONFIG_INJECT 'lcd_rotate=' "lcd_rotate=$G_WHIP_RETURNED_VALUE" /boot/config.txt && REBOOT_REQUIRED=1
fi
elif (( $G_WHIP_RETURNED_VALUE == 14 ))
then
/boot/dietpi/dietpi-led_control
elif (( $G_WHIP_RETURNED_VALUE == 16 ))
then
# Find and obtain values for all backlight devices
local fp_brightness iTotalAvailable=0 aFp_Brightness_Available=() aBrightness_Name=() aBrightness_Current=() aBrightness_Max=()
for fp_brightness in /sys/class/backlight/*
do
(( iTotalAvailable++ ))
aFp_Brightness_Available+=("$fp_brightness")
aBrightness_Name+=("${fp_brightness##*/}")
aBrightness_Current+=("$(<"$fp_brightness/actual_brightness")")
aBrightness_Max+=("$(<"$fp_brightness/max_brightness")")
done
# Return if no backlist device has been found
if (( iTotalAvailable ))
then
# Convert current brightness to %
local i aBrightness_Percent=()
for (( i=0; i<$iTotalAvailable; i++ ))
do
aBrightness_Percent+=("$(echo "${aBrightness_Current[i]} ${aBrightness_Max[i]}" | mawk '{printf "%.0f\n", $1*100/$2}')")
done
# List backlight devices to selection if multiple were found, else select 1st/only one
local iIndex=0
if (( iTotalAvailable > 1 ))
then
G_WHIP_MENU_ARRAY=()
for (( i=0; i<$iTotalAvailable; i++ ))
do
G_WHIP_MENU_ARRAY+=("${aBrightness_Name[i]}" ": [${aBrightness_Percent[i]}%]")
done
G_WHIP_MENU 'Please select a Brightness item to change its value:' || return 0
# Obtain array index
for (( i=0; i<$iTotalAvailable; i++ ))
do
[[ ${aBrightness_Name[i]} == "$G_WHIP_RETURNED_VALUE" ]] || continue
iIndex=$i
break
done
fi
# Generate % menu
G_WHIP_MENU_ARRAY=('Custom' ': Manually enter a value')
for i in {0..100..10}
do
G_WHIP_MENU_ARRAY+=("$i" '%')
done
G_WHIP_DEFAULT_ITEM=${aBrightness_Percent[iIndex]}
G_WHIP_MENU "Please select a new Brightness level for [${aBrightness_Name[iIndex]}]:\n - Current Value = ${aBrightness_Percent[iIndex]}%" || return 0
# Handle custom
if [[ $G_WHIP_RETURNED_VALUE == 'Custom' ]]
then
local MIN_VALUE=0 MAX_VALUE=100
G_WHIP_INPUTBOX "Please enter a value between $MIN_VALUE and $MAX_VALUE:" || return 0
G_CHECK_VALIDINT "$G_WHIP_RETURNED_VALUE" "$MIN_VALUE" "$MAX_VALUE" || return 1
fi
# Convert % back and apply
echo "$G_WHIP_RETURNED_VALUE ${aBrightness_Max[iIndex]}" | mawk '{printf "%.0f\n", $1*$2/100}' > "${aFp_Brightness_Available[iIndex]}/brightness"
else
Info_HW_OptionNotSupported
fi
elif (( $G_WHIP_RETURNED_VALUE == 17 ))
then
G_WHIP_MENU_ARRAY=(
'96' ': Default'
'120' ": +25% larger"
'144' ": +50% larger"
'168' ": +75% larger"
'192' ": +100% larger"
)
G_WHIP_DEFAULT_ITEM=$xorg_dpi_current
if G_WHIP_MENU "Please select a DPI value for Xorg:
- A higher value will make text and windows larger
- Has no effect on local terminal (eg: no desktop installed)
\nNB: Setting will only take effect, once system is restarted."
then
G_CONFIG_INJECT 'SOFTWARE_XORG_DPI=' "SOFTWARE_XORG_DPI=$G_WHIP_RETURNED_VALUE" /boot/dietpi.txt
G_EXEC mkdir -p /etc/X11/Xsession.d
echo "xrandr --dpi $G_WHIP_RETURNED_VALUE" > /etc/X11/Xsession.d/99-dietpi-dpi
REBOOT_REQUIRED=1
fi
fi
}
# TARGETMENUID=2
Menu_DisplayOptions_Driver_Resolution()
{
G_WHIP_BUTTON_CANCEL_TEXT='Cancel'
# VM
if (( $G_HW_MODEL == 20 ))
then
local current=$(sed -n '/^[[:blank:]]*GRUB_GFXMODE=/{s/^[^=]*=//p;q}' /etc/default/grub)
[[ $current ]] || current='System default'
G_WHIP_MENU_ARRAY=(
'System default' ''
'1600x1200' ''
'1280x1024' ''
'1152x864' ''
'1024x768' ''
'800x600' ''
)
G_WHIP_DEFAULT_ITEM=$current
G_WHIP_MENU "Please select a display resolution. Current: $current
\nNB: This only affects the virtual screen resolution, not the SSH session.
You might need to increase the maximum guest screen resolution within your VM software." || { Back_or_Exit 1; return 0; } # Display Options
if [[ $G_WHIP_RETURNED_VALUE == 'System default' ]]
then
sed --follow-symlinks -i 's/^[[:blank:]]*GRUB_GFXMODE=/#GRUB_GFXMODE=/' /etc/default/grub
sed --follow-symlinks -i 's/^[[:blank:]]*GRUB_GFXPAYLOAD_LINUX=/#GRUB_GFXPAYLOAD_LINUX=/' /etc/default/grub
else
G_CONFIG_INJECT 'GRUB_GFXMODE=' "GRUB_GFXMODE=$G_WHIP_RETURNED_VALUE" /etc/default/grub
G_CONFIG_INJECT 'GRUB_GFXPAYLOAD_LINUX=' 'GRUB_GFXPAYLOAD_LINUX=keep' /etc/default/grub 'GRUB_GFXMODE='
fi
update-grub
# Native PC
elif (( $G_HW_MODEL == 21 ))
then
local gpu_current=$(sed -n '/^[[:blank:]]*CONFIG_GPU_DRIVER=/{s/^[^=]*=//p;q}' /boot/dietpi.txt)
gpu_current=${gpu_current,,}
local driver_installed=()
for i in {0..3}
do
driver_installed+=('Install')
done
local installed_index=-1
if [[ $gpu_current == 'nvidia' ]]
then
installed_index=0
elif [[ $gpu_current == 'intel' ]]
then
installed_index=1
elif [[ $gpu_current == 'amd' ]]
then
installed_index=2
elif [[ $gpu_current == 'custom' ]]
then
installed_index=3
fi
if (( $installed_index >= 0 ))
then
driver_installed[$installed_index]='[Installed]'
fi
G_WHIP_MENU_ARRAY=(
'Nvidia' ": ${driver_installed[0]} | Proprietary GPU driver"
'Intel' ": ${driver_installed[1]} | Open-Source VA-API GPU drivers"
'AMD' ": ${driver_installed[2]} | Proprietary GPU driver"
'Custom' ": ${driver_installed[3]} | Manual User Install"
'None' ": Uninstall all GPU drivers"
)
G_WHIP_BUTTON_CANCEL_TEXT='Back'
G_WHIP_DEFAULT_ITEM=${gpu_current^}
G_WHIP_MENU 'Please select an option:' || { Back_or_Exit 1; return 0; } # Display Options
local gpu_new=${G_WHIP_RETURNED_VALUE,,}
if [[ $gpu_new != "$gpu_current" ||
$gpu_new = 'none' ]] # Always run uninstall when selected
then
/boot/dietpi/func/dietpi-set_hardware gpudriver "$gpu_new"
G_WHIP_YESNO 'X11 auto-configuration
\nThis feature generates a configuration for X11 at /etc/X11/xorg.conf based on available drivers. It is not always required, but helps to assure the right driver is used after one has been installed or uninstalled.
\nNB: This feature will only work if an X server (desktop) is NOT currently running. If a desktop is running, please set "dietpi-autostart" to "Console", reboot the system, then run the auto-configuration manually:
- Xorg -configure
\nWould you like to auto-configure X11 now?' || return 0
G_EXEC Xorg -configure
[[ -f '/root/xorg.conf.new' ]] && G_EXEC mv /root/xorg.conf{.new,}
fi
# RPi
elif (( $G_HW_MODEL < 10 ))
then
local framebuffer_x=$(grep -m1 '^[[:blank:]]*framebuffer_width=' /boot/config.txt || vcgencmd get_config framebuffer_width)
framebuffer_x=${framebuffer_x#*=}; framebuffer_x=${framebuffer_x:-0}
local framebuffer_y=$(grep -m1 '^[[:blank:]]*framebuffer_height=' /boot/config.txt || vcgencmd get_config framebuffer_height)
framebuffer_y=${framebuffer_y#*=}; framebuffer_y=${framebuffer_y:-0}
local current_value=$(sed -n '/^[[:blank:]]*dtoverlay=vc4-/{s/^[^=]*=//p;q}' /boot/config.txt) # OpenGL check 1st
if [[ ! $current_value ]]
then
# Framebuffer
current_value="$framebuffer_x X $framebuffer_y"
# Check for headless
grep -q '^[[:blank:]]*AUTO_SETUP_HEADLESS=1' /boot/dietpi.txt && current_value='Headless'
fi
G_WHIP_MENU_ARRAY=(
'vc4-kms-v3d' ': OpenGL | 1920 x 1080'
'vc4-fkms-v3d' ': OpenGL | 1920 x 1080'
'1080p' ': 1920 x 1080'
'720p' ': 1280 x 720'
'480p' ': 854 x 480'
'RPi Touchscreen' ': 800 x 480'
'PC1' ': 1024 x 768'
'PC2' ': 800 x 640'
'PC3' ': 640 x 480'
'DietPi-CloudShell' ': 320 x 240'
'sdtv_mode=0' ': Composite NTSC'
'sdtv_mode=1' ': Composite Japanese NTSC'
'sdtv_mode=2' ': Composite PAL'
'sdtv_mode=3' ': Composite Brazilian PAL'
'Headless' ': Disables HDMI & Composite Output'
)
G_WHIP_DEFAULT_ITEM=$current_value
G_WHIP_MENU "Hardware: $G_HW_MODEL_NAME\nCurrent resolution: $current_value" || { Back_or_Exit 1; return 0; } # Display Options
REBOOT_REQUIRED=1
# Enable headless if chosen, else always disable
if [[ $G_WHIP_RETURNED_VALUE == 'Headless' ]]
then
G_WHIP_YESNO 'Using the Headless option will:
- Disable HDMI and composite output
- Disable the framebuffer
- Lower energy consumption by 0.1+ Watts
- Improve RAM performance by 1-5% (VideoCore shares RAM bandwidth)
Source: https://www.raspberrypi.org/forums/viewtopic.php?p=105008#p105008\n
Re-enabling HDMI requires a reboot. If you need emergency HDMI output, edit the following files on first partition of the SDcard from external system:
- In config.txt, set "hdmi_ignore_hotplug=0" and comment/remove the "max_framebuffers=0" line.
- In dietpi.txt, set "AUTO_SETUP_HEADLESS=0".' || { REBOOT_REQUIRED=0; return; }
/boot/dietpi/func/dietpi-set_hardware headless 1
else
/boot/dietpi/func/dietpi-set_hardware headless 0
fi
# Disable composite if not chosen
if [[ $G_WHIP_RETURNED_VALUE != 'sdtv_mode'* ]]
then
sed --follow-symlinks -i '/sdtv_mode=/c\#sdtv_mode=0' /boot/config.txt
sed --follow-symlinks -i '/enable_tvout=/c\#enable_tvout=0' /boot/config.txt
fi
# Disable OpenGL if not chosen
[[ $G_WHIP_RETURNED_VALUE == 'vc4-'* ]] || /boot/dietpi/func/dietpi-set_hardware rpi-opengl disable
if [[ $G_WHIP_RETURNED_VALUE == 'vc4-'* ]]
then
/boot/dietpi/func/dietpi-set_hardware rpi-opengl "$G_WHIP_RETURNED_VALUE"
elif [[ $G_WHIP_RETURNED_VALUE != 'Headless' ]]
then
case "$G_WHIP_RETURNED_VALUE" in
'sdtv_mode'*)
# Enable SDTV on RPi4, apply to all RPi to allow SD card switch
G_CONFIG_INJECT 'enable_tvout=' 'enable_tvout=1' /boot/config.txt
G_CONFIG_INJECT 'sdtv_mode=' "$G_WHIP_RETURNED_VALUE" /boot/config.txt
framebuffer_x=720 framebuffer_y=576
;;
'DietPi-CloudShell') framebuffer_x=320 framebuffer_y=240;;
'1080p') framebuffer_x=1920 framebuffer_y=1080;;
'720p') framebuffer_x=1280 framebuffer_y=720;;
'480p') framebuffer_x=854 framebuffer_y=480;;
'RPi Touchscreen') framebuffer_x=800 framebuffer_y=480;;
'PC1') framebuffer_x=1024 framebuffer_y=768;;
'PC2') framebuffer_x=800 framebuffer_y=640;;
'PC3') framebuffer_x=640 framebuffer_y=480;;
*) :;;
esac
# Apply framebuffer size and Chromium autostart resolution
G_CONFIG_INJECT 'framebuffer_width=' "framebuffer_width=$framebuffer_x" /boot/config.txt
G_CONFIG_INJECT 'framebuffer_height=' "framebuffer_height=$framebuffer_y" /boot/config.txt
G_CONFIG_INJECT 'SOFTWARE_CHROMIUM_RES_X=' "SOFTWARE_CHROMIUM_RES_X=$framebuffer_x" /boot/dietpi.txt
G_CONFIG_INJECT 'SOFTWARE_CHROMIUM_RES_Y=' "SOFTWARE_CHROMIUM_RES_Y=$framebuffer_y" /boot/dietpi.txt
fi
# Odroid XU4
elif (( $G_HW_MODEL == 11 ))
then
# Get Current Values
local current_resolution=$(grep -Em1 'setenv[[:blank:]]+videoconfig[[:blank:]]' /boot/boot.ini)
case $current_resolution in
*'1920x1080'*) current_resolution='1920x1080';;
*'1280x720'*) current_resolution='1280x720';;
*'720x480'*) current_resolution='720x480';;
*'1024x600'*) current_resolution='1024x600';;
*) :;;
esac
G_WHIP_MENU_ARRAY=(
'1920x1080' ': 1080p'
'1280x720' ': 720p'
'720x480' ': 480p'
'1024x600' ': VU7+'
)
G_WHIP_DEFAULT_ITEM=$current_resolution
G_WHIP_MENU "Hardware : $G_HW_MODEL_NAME\nCurrent: $current_resolution" || { Back_or_Exit 1; return 0; } # Display Options
# DVI or HDMI
if [[ $G_WHIP_RETURNED_VALUE == '1024x600' ]]
then
G_CONFIG_INJECT 'setenv[[:blank:]]+vout[[:blank:]]' 'setenv vout "dvi"' /boot/boot.ini 'ODROIDXU-UBOOT-CONFIG'
else
G_CONFIG_INJECT 'setenv[[:blank:]]+vout[[:blank:]]' 'setenv vout "hdmi"' /boot/boot.ini 'ODROIDXU-UBOOT-CONFIG'
fi
G_CONFIG_INJECT 'setenv[[:blank:]]+videoconfig[[:blank:]]' "setenv videoconfig \"drm_kms_helper.edid_firmware=edid/$G_WHIP_RETURNED_VALUE.bin\"" /boot/boot.ini 'ODROIDXU-UBOOT-CONFIG'
REBOOT_REQUIRED=1
else
Info_HW_OptionNotSupported
Back_or_Exit 1 # Display Options
fi
}
# TARGETMENUID=19
Menu_AdvancedOptions_APT()
{
apt-config dump Dir::{Cache,State} > apt_conf
local cache_enabled=$(grep -cm1 '^Dir::Cache::pkgcache "[^"]' apt_conf)
local cache_in_ram=$(grep -cm1 '^Dir::Cache "/tmp' apt_conf)
local lists_in_ram=$(grep -cm1 '^Dir::State "/tmp' apt_conf)
local list_compression='On'
[[ -f '/etc/apt/apt.conf.d/98dietpi-nocompress' ]] && list_compression='Off'
local archives_in_ram=0
(( $cache_in_ram )) && grep -q '^Dir::Cache::archives "[^/]' apt_conf || grep -q '^Dir::Cache::archives "/tmp' apt_conf && archives_in_ram=1
local cache_text='On disk'
(( $cache_in_ram )) && cache_text='In RAM'
(( $cache_enabled )) || cache_text='Disabled'
local lists_text='On disk'
(( $lists_in_ram )) && lists_text='In RAM'
local archives_text='On disk'
(( $archives_in_ram )) && archives_text='In RAM'
G_WHIP_MENU_ARRAY=(
'Reset' ': Reset to system defaults'
'APT cache' ": [$cache_text]"
'APT lists' ": [$lists_text]"
'List compression' ": [$list_compression]"
)
(( $cache_in_ram )) && G_WHIP_MENU_ARRAY+=('APT archives' ": [$archives_text]")
G_WHIP_MENU 'APT cache: Speeds up apt-cache search/show/... commands
- 50-100 MiB size, gets fully rewritten on every APT update
\nAPT lists: Release files, one each distro and component
- 50-100 MiB size, get individually rewritten if update available
\nList compression: Whether APT lists are stored xz-compressed
- Reduces disk writes (during APT updates) and usage by ~80%
- Slows down reading package lists on APT installs
\nAPT archives: Where APT downloads packages to for install
- Can temporarily consume much space on large APT installs
- Resets to disk if cache is moved to disk' || { Back_or_Exit 3; return 0; } # Advanced Options
[[ $G_WHIP_RETURNED_VALUE == 'Reset' ]] && { /boot/dietpi/func/dietpi-set_software apt reset; return 0; }
[[ $G_WHIP_RETURNED_VALUE == 'List compression' ]] && { /boot/dietpi/func/dietpi-set_software apt compress $(( ! ${list_compression/On/1} )); return 0; }
local item=$G_WHIP_RETURNED_VALUE
G_WHIP_MENU_ARRAY=(
'To disk' ": Move $item to disk (default)"
'To RAM' ": Move $item to RAM"
)
[[ $item == 'APT cache' ]] && G_WHIP_MENU_ARRAY+=('Disable' ": Disable $item")
local note=':'
if [[ $item == 'APT lists' ]]; then
note='.\n\nNB: Afterwards, you need to run "apt update" once before APT installs/upgrades can be done.
When moving lists to RAM, this needs to be done once after each reboot unless CONFIG_CHECK_DIETPI_UPDATES=1 is set in /boot/dietpi.txt.
DietPi scripts, however, automatically update APT lists on demand.'
fi
G_WHIP_MENU "Please select an option for $item$note" || return 0
local option=${G_WHIP_RETURNED_VALUE#To }
/boot/dietpi/func/dietpi-set_software apt "${item#APT }" "${option,,}"
}
# TARGETMENUID=18
Menu_AdvancedOptions_Serial_UART()
{
declare -A aSTATE=()
G_WHIP_MENU_ARRAY=()
(( $G_HW_MODEL < 10 )) && G_WHIP_MENU_ARRAY+=('' '●─ Toggle console ')
for i in /dev/{tty{S,AMA,SAC,AML,SC,GS,FIQ,MV},hvc}[0-9]*
do
[[ -e $i ]] || continue
i=${i#/dev/}
aSTATE[$i]='Off'
systemctl -q is-enabled "serial-getty@$i" || systemctl -q is-active "serial-getty@$i" && aSTATE[$i]='On'
G_WHIP_MENU_ARRAY+=("$i console" ": [${aSTATE[$i]}]")
done
# RPi special
local rpi_text=
if (( $G_HW_MODEL < 10 )); then
local rpi_text='\n\nOn Raspberry Pi you can additionally enable or disable the primary UART device completely (requires reboot).'
G_WHIP_MENU_ARRAY+=('' '●─ Toggle device ')
# Onboard WiFi/BT: "enable_uart" toggles ttyS0 (mini UART), disabled by default
if (( $G_HW_ONBOARD_WIFI )); then
local rpi_uart='ttyS0 (mini UART)'
local rpi_uart_state='Off'
grep -q '^[[:blank:]]*enable_uart=1' /boot/config.txt && rpi_uart_state='On'
# No onboard WiFi/BT: "enable_uart" toggles ttyAMA0 (full UART). enabled by default
else
local rpi_uart='ttyAMA0 (full UART)'
local rpi_uart_state='On'
grep -q '^[[:blank:]]*enable_uart=0' /boot/config.txt && rpi_uart_state='Off'
fi
G_WHIP_MENU_ARRAY+=("$rpi_uart device" ": [$rpi_uart_state]")
fi
(( ${#G_WHIP_MENU_ARRAY[@]} > 2 || ( $G_HW_MODEL > 9 && ${#G_WHIP_MENU_ARRAY[@]} ) )) || { G_WHIP_MSG 'No serial/UART devices have been found on your system.'; Back_or_Exit 3; return 0; } # Advanced Options
G_WHIP_MENU "Select an available serial/UART device to toggle a login console on it.$rpi_text" || { Back_or_Exit 3; return 0; } # Advanced Options
if [[ $G_WHIP_RETURNED_VALUE == *'device' ]]; then
local toggle=1
[[ $rpi_uart_state == 'On' ]] && toggle=0 && /boot/dietpi/func/dietpi-set_hardware serialconsole disable "${G_WHIP_RETURNED_VALUE%% *}"
G_CONFIG_INJECT 'enable_uart=' "enable_uart=$toggle" /boot/config.txt && REBOOT_REQUIRED=1
elif [[ $G_WHIP_RETURNED_VALUE == *'console' ]]; then
local toggle='enable'
[[ ${aSTATE[${G_WHIP_RETURNED_VALUE%% *}]} == 'On' ]] && toggle='disable'
/boot/dietpi/func/dietpi-set_hardware serialconsole "$toggle" "${G_WHIP_RETURNED_VALUE%% *}"
fi
}
# TARGETMENUID=3
Menu_AdvancedOptions()
{
# Swap file
local swap_size=$(free -m | mawk '/Swap:/ {print $2;exit}')
local swap_location=$(sed -n '/^[[:blank:]]*AUTO_SETUP_SWAPFILE_LOCATION=/{s/^[^=]*=//p;q}' /boot/dietpi.txt)
local swap_size_text="$swap_size MB"
(( $swap_size )) || swap_size_text='Off'
G_WHIP_MENU_ARRAY=('Swap file' ": [$swap_size_text | $swap_location]")
# APT
G_WHIP_MENU_ARRAY+=('APT' ': Manage APT cache and list storage')
# Time sync
local ntpd_mode_current=$(sed -n '/^[[:blank:]]*CONFIG_NTP_MODE=/{s/^[^=]*=//p;q}' /boot/dietpi.txt)
local ntpd_mode_text=''
if (( $ntpd_mode_current == 0 )); then
ntpd_mode_text='Custom'
elif (( $ntpd_mode_current == 1 )); then
ntpd_mode_text='Boot Only'
elif (( $ntpd_mode_current == 2 )); then
ntpd_mode_text='Boot + Daily'
elif (( $ntpd_mode_current == 3 )); then
ntpd_mode_text='Boot + Hourly'
elif (( $ntpd_mode_current == 4 )); then
ntpd_mode_text='Daemon + Drift'
fi
G_WHIP_MENU_ARRAY+=('Time sync mode' ": [$ntpd_mode_text]")
# RTC clock: Only show option if a hwclock (connector) is available, otherwise fake-hwclock (default) is required anyway!
if hwclock &> /dev/null; then
local rtc_text='Hardware'
command -v fake-hwclock > /dev/null && rtc_text='Emulated'
G_WHIP_MENU_ARRAY+=('RTC mode' ": [$rtc_text]")
fi
# Armbian U-Boot update
if [[ -f '/usr/lib/u-boot/platform_install.sh' ]]
then
local bootdev=$(lsblk -npo PKNAME "$(findmnt -Ufnro SOURCE -T /boot)")
G_WHIP_MENU_ARRAY+=('Update MMC bootloader' ": Flash current U-Boot to $bootdev")
fi
# RPi 4/5 EEPROM update: https://www.raspberrypi.org/documentation/hardware/raspberrypi/booteeprom.md
if [[ $G_HW_MODEL == [45] ]]
then
if dpkg -s 'rpi-eeprom' &> /dev/null
then
rpi-eeprom-update -m version_eeprom
# shellcheck disable=SC1091
. ./version_eeprom
rm version_eeprom
G_WHIP_MENU_ARRAY+=('Update RPi EEPROM firmware' ": [Bootloader: ${BOOTLOADER_CURRENT:-N/A} | VL805: ${VL805_CURRENT:-N/A}]")
else
G_WHIP_MENU_ARRAY+=('Update RPi EEPROM firmware' ': Install rpi-eeprom APT package')
fi
# Odroid N2, ROCK 4, ROCK 5B, Orange Pi 5 (Plus) and Orange Pi 3B: https://dietpi.com/forum/t/orange-pi-5-boot-from-nvme/16457
elif [[ $G_HW_MODEL =~ ^(15|72|78|80|82|87)$ && -f '/usr/lib/u-boot/platform_install.sh' ]]
then
# Odroid N2/ROCK 4: Device tree overlay required
local spidev='/dev/mtdblock0'
(( $G_HW_MODEL == 15 || $G_HW_MODEL == 72 )) || {
{ [[ -e '/dev/mtd0' ]] && grep -q 'flashcp' /usr/lib/u-boot/platform_install.sh && spidev='/dev/mtd0'; } ||
{ [[ -b '/dev/mtdblock0' ]] && ! grep -q 'flashcp' /usr/lib/u-boot/platform_install.sh; }
} && G_WHIP_MENU_ARRAY+=('Update SPI bootloader' ": Flash current U-Boot to $spidev")
# VisionFive 2/Star64: https://doc-en.rvspace.org/VisionFive2/PDF/VisionFive2_QSG.pdf
elif (( $G_HW_MODEL == 81 || $G_HW_MODEL == 84 ))
then
G_WHIP_MENU_ARRAY+=('Update bootloader' ': on VisionFive 2/Star64 SPI storage')
fi
# Serial/UART devices
G_WHIP_MENU_ARRAY+=('Serial/UART' ': Manage available devices')
# Bluetooth: Not for VM
local bluetooth_state=1 bluetooth_state_text='On'
[[ -f '/etc/modprobe.d/dietpi-disable_bluetooth.conf' ]] && bluetooth_state=0 bluetooth_state_text='Off'
G_WHIP_MENU_ARRAY+=('Bluetooth' ": [$bluetooth_state_text]")
# Orange Pi Zero 3/Zero 2W specific
if (( $G_HW_MODEL == 83 || $G_HW_MODEL == 88 ))
then
# SPI state
local spi_enabled=$(grep -Ecm1 '^[[:blank:]]*overlays=(.*[[:blank:]])?spi1-cs1-spidev([[:blank:]]|$)' /boot/dietpiEnv.txt)
local spi_text='Off'
(( $spi_enabled )) && spi_text='On'
G_WHIP_MENU_ARRAY+=('SPI state' ": [$spi_text]")
# RPi specific
elif (( $G_HW_MODEL < 10 ))
then
# I2C state
local rpi_i2c_enabled=$(grep -cm1 '^[[:blank:]]*dtparam=i2c_arm=on' /boot/config.txt)
local rpi_i2c_text='Off'
(( $rpi_i2c_enabled )) && rpi_i2c_text='On'
G_WHIP_MENU_ARRAY+=('I2C state' ": [$rpi_i2c_text]")
# I2C baudrate
local rpi_i2c_baudrate=$(sed -n '/^[[:blank:]]*dtparam=i2c_arm_baudrate=/{s/^.*=//p;q}' /boot/config.txt)
# - Allow commented/non-existent entry, using default value: https://github.com/raspberrypi/firmware/blob/d69aadedb7c146ba5d3b0b45a661e5669a9141c4/boot/overlays/README#L115-L116
rpi_i2c_baudrate=$(( ${rpi_i2c_baudrate:-100000} / 1000 ))
G_WHIP_MENU_ARRAY+=('I2C frequency' ": [$rpi_i2c_baudrate kHz]")
# SPI state
local spi_enabled=$(grep -cm1 '^[[:blank:]]*dtparam=spi=on' /boot/config.txt)
local spi_text='Off'
(( $spi_enabled )) && spi_text='On'
G_WHIP_MENU_ARRAY+=('SPI state' ": [$spi_text]")
# USB boot option: RPi3 only and not required for RPi3+: https://www.raspberrypi.org/documentation/hardware/raspberrypi/bootmodes/msd.md
if [[ $G_HW_MODEL == 3 && $G_HW_MODEL_NAME != *'+'* ]]
then
local rpi3_usb_boot_bit_enabled=$(vcgencmd otp_dump | grep -cm1 '17:3020000a')
local rpi3_usb_boot_bit_text='Off'
(( $rpi3_usb_boot_bit_enabled )) && rpi3_usb_boot_bit_text='On'
G_WHIP_MENU_ARRAY+=('USB boot support' ": [$rpi3_usb_boot_bit_text]")
fi
# Kernel choice: Requires finished firmware migration
dpkg-query -s 'raspi-firmware' &> /dev/null && G_WHIP_MENU_ARRAY+=('RPi kernel choice' ': Select/deselect optional kernel packages')
fi