This repository has been archived by the owner on Aug 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 93
/
raspi-config
2288 lines (2129 loc) · 63.1 KB
/
raspi-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/sh
# Part of raspi-config https://github.com/RPi-Distro/raspi-config
#
# Modified to be safer for Ubuntu 18.04.3 unofficial
INTERACTIVE=True
ASK_TO_REBOOT=0
BLACKLIST=/etc/modprobe.d/raspi-blacklist.conf
CONFIG=/boot/firmware/config.txt
is_pi () {
ARCH=$(dpkg --print-architecture)
if [ "$ARCH" = "arm64" ] ; then
return 0
else
return 1
fi
}
if is_pi ; then
CMDLINE=/boot/firmware/cmdline.txt
else
CMDLINE=/proc/cmdline
fi
is_pione() {
if grep -q "^Revision\s*:\s*00[0-9a-fA-F][0-9a-fA-F]$" /proc/cpuinfo; then
return 0
elif grep -q "^Revision\s*:\s*[ 123][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]0[0-36][0-9a-fA-F]$" /proc/cpuinfo ; then
return 0
else
return 1
fi
}
is_pitwo() {
grep -q "^Revision\s*:\s*[ 123][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]04[0-9a-fA-F]$" /proc/cpuinfo
return $?
}
is_pizero() {
grep -q "^Revision\s*:\s*[ 123][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]0[9cC][0-9a-fA-F]$" /proc/cpuinfo
return $?
}
is_pifour() {
grep -q "^Revision\s*:\s*[ 123][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]11[0-9a-fA-F]$" /proc/cpuinfo
return $?
}
get_pi_type() {
if is_pione; then
echo 1
elif is_pitwo; then
echo 2
else
echo 0
fi
}
is_live() {
grep -q "boot=live" $CMDLINE
return $?
}
is_ssh() {
if pstree -p | egrep --quiet --extended-regexp ".*sshd.*\($$\)"; then
return 0
else
return 1
fi
}
is_fkms() {
if grep -q okay /proc/device-tree/soc/v3d@7ec00000/status 2> /dev/null || grep -q okay /proc/device-tree/soc/firmwarekms@7e600000/status 2> /dev/null ; then
return 0
else
return 1
fi
}
deb_ver () {
ver=`cat /etc/debian_version | cut -d . -f 1`
echo $ver
}
calc_wt_size() {
# NOTE: it's tempting to redirect stderr to /dev/null, so supress error
# output from tput. However in this case, tput detects neither stdout or
# stderr is a tty and so only gives default 80, 24 values
WT_HEIGHT=17
WT_WIDTH=$(tput cols)
if [ -z "$WT_WIDTH" ] || [ "$WT_WIDTH" -lt 60 ]; then
WT_WIDTH=80
fi
if [ "$WT_WIDTH" -gt 178 ]; then
WT_WIDTH=120
fi
WT_MENU_HEIGHT=$(($WT_HEIGHT-7))
}
do_about() {
whiptail --msgbox "\
This tool provides a straight-forward way of doing initial
configuration of the Raspberry Pi. Although it can be run
at any time, some of the options may have difficulties if
you have heavily customised your installation.\
" 20 70 1
}
get_can_expand() {
ROOT_PART=$(mount | sed -n 's|^/dev/\(.*\) on / .*|\1|p')
PART_NUM=${ROOT_PART#mmcblk0p}
if [ "$PART_NUM" = "$ROOT_PART" ]; then
echo 1
exit
fi
if [ "$PART_NUM" -ne 2 ]; then
echo 1
exit
fi
LAST_PART_NUM=$(parted /dev/mmcblk0 -ms unit s p | tail -n 1 | cut -f 1 -d:)
if [ $LAST_PART_NUM -ne $PART_NUM ]; then
echo 1
exit
fi
echo 0
}
do_expand_rootfs() {
ROOT_PART=$(mount | sed -n 's|^/dev/\(.*\) on / .*|\1|p')
PART_NUM=${ROOT_PART#mmcblk0p}
if [ "$PART_NUM" = "$ROOT_PART" ]; then
whiptail --msgbox "$ROOT_PART is not an SD card. Don't know how to expand" 20 60 2
return 0
fi
# NOTE: the NOOBS partition layout confuses parted. For now, let's only
# agree to work with a sufficiently simple partition layout
if [ "$PART_NUM" -ne 2 ]; then
whiptail --msgbox "Your partition layout is not currently supported by this tool. You are probably using NOOBS, in which case your root filesystem is already expanded anyway." 20 60 2
return 0
fi
LAST_PART_NUM=$(parted /dev/mmcblk0 -ms unit s p | tail -n 1 | cut -f 1 -d:)
if [ $LAST_PART_NUM -ne $PART_NUM ]; then
whiptail --msgbox "$ROOT_PART is not the last partition. Don't know how to expand" 20 60 2
return 0
fi
# Get the starting offset of the root partition
PART_START=$(parted /dev/mmcblk0 -ms unit s p | grep "^${PART_NUM}" | cut -f 2 -d: | sed 's/[^0-9]//g')
[ "$PART_START" ] || return 1
# Return value will likely be error for fdisk as it fails to reload the
# partition table because the root fs is mounted
fdisk /dev/mmcblk0 <<EOF
p
d
$PART_NUM
n
p
$PART_NUM
$PART_START
p
w
EOF
ASK_TO_REBOOT=1
# now set up an init.d script
cat <<EOF > /etc/init.d/resize2fs_once &&
#!/bin/sh
### BEGIN INIT INFO
# Provides: resize2fs_once
# Required-Start:
# Required-Stop:
# Default-Start: 3
# Default-Stop:
# Short-Description: Resize the root filesystem to fill partition
# Description:
### END INIT INFO
. /lib/lsb/init-functions
case "\$1" in
start)
log_daemon_msg "Starting resize2fs_once" &&
resize2fs /dev/$ROOT_PART &&
update-rc.d resize2fs_once remove &&
rm /etc/init.d/resize2fs_once &&
log_end_msg \$?
;;
*)
echo "Usage: \$0 start" >&2
exit 3
;;
esac
EOF
chmod +x /etc/init.d/resize2fs_once &&
update-rc.d resize2fs_once defaults &&
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "Root partition has been resized.\nThe filesystem will be enlarged upon the next reboot" 20 60 2
fi
}
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"
}
clear_config_var() {
lua - "$1" "$2" <<EOF > "$2.bak"
local key=assert(arg[1])
local fn=assert(arg[2])
local file=assert(io.open(fn))
for line in file:lines() do
if line:match("^%s*"..key.."=.*$") then
line="#"..line
end
print(line)
end
EOF
mv "$2.bak" "$2"
}
get_config_var() {
lua - "$1" "$2" <<EOF
local key=assert(arg[1])
local fn=assert(arg[2])
local file=assert(io.open(fn))
local found=false
for line in file:lines() do
local val = line:match("^%s*"..key.."=(.*)$")
if (val ~= nil) then
print(val)
found=true
break
end
end
if not found then
print(0)
end
EOF
}
get_overscan() {
OVS=$(get_config_var disable_overscan $CONFIG)
if [ $OVS -eq 1 ]; then
echo 1
else
echo 0
fi
}
do_overscan() {
DEFAULT=--defaultno
CURRENT=0
if [ $(get_overscan) -eq 0 ]; then
DEFAULT=
CURRENT=1
fi
if [ "$INTERACTIVE" = True ]; then
whiptail --yesno "Would you like to enable compensation for displays with overscan?" $DEFAULT 20 60 2
RET=$?
else
RET=$1
fi
if [ $RET -eq $CURRENT ]; then
ASK_TO_REBOOT=1
fi
if [ $RET -eq 0 ] ; then
set_config_var disable_overscan 0 $CONFIG
STATUS=enabled
elif [ $RET -eq 1 ]; then
sed $CONFIG -i -e "s/^overscan_/#overscan_/"
set_config_var disable_overscan 1 $CONFIG
STATUS=disabled
else
return $RET
fi
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "Display overscan compensation is $STATUS" 20 60 1
fi
}
get_pixdub() {
if is_pi ; then
FBW=$(get_config_var framebuffer_width $CONFIG)
if [ $FBW -eq 0 ]; then
echo 1
else
echo 0
fi
else
if [ -e /etc/profile.d/pd.sh ] ; then
echo 0
else
echo 1
fi
fi
}
is_number() {
case $1 in
''|*[!0-9]*) return 0 ;;
*) return 1 ;;
esac
}
do_pixdub() {
if is_fkms ; then
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "Pixel doubling cannot be used with the GL driver" 20 60 1
fi
return 1
fi
DEFAULT=--defaultno
CURRENT=0
if [ $(get_pixdub) -eq 0 ]; then
DEFAULT=
CURRENT=1
fi
if [ "$INTERACTIVE" = True ]; then
whiptail --yesno "Would you like to enable pixel doubling?" $DEFAULT 20 60 2
RET=$?
else
RET=$1
fi
if is_pi ; then
if [ $RET -eq 0 ] ; then
XVAL=$(xrandr 2>&1 | grep current | cut -f2 -d, | cut -f3 -d' ')
YVAL=$(xrandr 2>&1 | grep current | cut -f2 -d, | cut -f5 -d' ')
if is_number $XVAL || is_number $YVAL ; then
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "Could not read current screen dimensions - unable to enable pixel doubling" 20 60 1
fi
return 1
fi
NEWX=`expr $XVAL / 2`
NEWY=`expr $YVAL / 2`
set_config_var framebuffer_width $NEWX $CONFIG
set_config_var framebuffer_height $NEWY $CONFIG
set_config_var scaling_kernel 8 $CONFIG
STATUS=enabled
elif [ $RET -eq 1 ]; then
clear_config_var framebuffer_width $CONFIG
clear_config_var framebuffer_height $CONFIG
clear_config_var scaling_kernel $CONFIG
STATUS=disabled
else
return $RET
fi
else
if [ -e /etc/profile.d/pd.sh ] ; then
rm /etc/profile.d/pd.sh
fi
if [ $RET -eq 0 ] ; then
DEV=$(xrandr | grep -w connected | cut -f1 -d' ')
for item in $DEV
do
echo xrandr --output $item --scale 0.5x0.5 >> /etc/profile.d/pd.sh
done
STATUS=enabled
elif [ $RET -eq 1 ]; then
STATUS=disabled
else
return $RET
fi
fi
if [ $RET -eq $CURRENT ]; then
ASK_TO_REBOOT=1
fi
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "Pixel doubling is $STATUS" 20 60 1
fi
}
do_change_pass() {
whiptail --msgbox "You will now be asked to enter a new password for the $SUDO_USER user" 20 60 1
passwd $SUDO_USER &&
whiptail --msgbox "Password changed successfully" 20 60 1
}
do_configure_keyboard() {
printf "Reloading keymap. This may take a short while\n"
if [ "$INTERACTIVE" = True ]; then
dpkg-reconfigure keyboard-configuration
else
local KEYMAP="$1"
sed -i /etc/default/keyboard -e "s/^XKBLAYOUT.*/XKBLAYOUT=\"$KEYMAP\"/"
dpkg-reconfigure -f noninteractive keyboard-configuration
fi
invoke-rc.d keyboard-setup start
setsid sh -c 'exec setupcon -k --force <> /dev/tty1 >&0 2>&1'
udevadm trigger --subsystem-match=input --action=change
return 0
}
do_change_locale() {
if [ "$INTERACTIVE" = True ]; then
dpkg-reconfigure locales
else
local LOCALE="$1"
if ! LOCALE_LINE="$(grep "^$LOCALE " /usr/share/i18n/SUPPORTED)"; then
return 1
fi
local ENCODING="$(echo $LOCALE_LINE | cut -f2 -d " ")"
echo "$LOCALE $ENCODING" > /etc/locale.gen
sed -i "s/^\s*LANG=\S*/LANG=$LOCALE/" /etc/default/locale
dpkg-reconfigure -f noninteractive locales
fi
}
do_change_timezone() {
if [ "$INTERACTIVE" = True ]; then
dpkg-reconfigure tzdata
else
local TIMEZONE="$1"
if [ ! -f "/usr/share/zoneinfo/$TIMEZONE" ]; then
return 1;
fi
rm /etc/localtime
echo "$TIMEZONE" > /etc/timezone
dpkg-reconfigure -f noninteractive tzdata
fi
}
get_wifi_country() {
CODE=${1:-0}
IFACE="$(list_wlan_interfaces | head -n 1)"
if [ -z "$IFACE" ]; then
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "No wireless interface found" 20 60
fi
return 1
fi
if ! wpa_cli -i "$IFACE" status > /dev/null 2>&1; then
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "Could not communicate with wpa_supplicant" 20 60
fi
return 1
fi
wpa_cli -i "$IFACE" save_config > /dev/null 2>&1
COUNTRY="$(wpa_cli -i "$IFACE" get country)"
if [ "$COUNTRY" = "FAIL" ]; then
return 1
fi
if [ $CODE = 0 ]; then
echo "$COUNTRY"
fi
return 0
}
do_wifi_country() {
IFACE="$(list_wlan_interfaces | head -n 1)"
if [ -z "$IFACE" ]; then
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "No wireless interface found" 20 60
fi
return 1
fi
if ! wpa_cli -i "$IFACE" status > /dev/null 2>&1; then
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "Could not communicate with wpa_supplicant" 20 60
fi
return 1
fi
oIFS="$IFS"
if [ "$INTERACTIVE" = True ]; then
IFS="/"
value=$(cat /usr/share/zoneinfo/iso3166.tab | tail -n +26 | tr '\t' '/' | tr '\n' '/')
COUNTRY=$(whiptail --menu "Select the country in which the Pi is to be used" 20 60 10 ${value} 3>&1 1>&2 2>&3)
IFS=$oIFS
else
COUNTRY=$1
true
fi
if [ $? -eq 0 ];then
wpa_cli -i "$IFACE" set country "$COUNTRY"
wpa_cli -i "$IFACE" save_config > /dev/null 2>&1
if ! iw reg set "$COUNTRY" 2> /dev/null; then
ASK_TO_REBOOT=1
fi
if hash rfkill 2> /dev/null; then
rfkill unblock wifi
fi
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "Wi-fi country set to $COUNTRY" 20 60 1
fi
fi
}
get_hostname() {
cat /etc/hostname | tr -d " \t\n\r"
}
do_hostname() {
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "\
Please note: RFCs mandate that a hostname's labels \
may contain only the ASCII letters 'a' through 'z' (case-insensitive),
the digits '0' through '9', and the hyphen.
Hostname labels cannot begin or end with a hyphen.
No other symbols, punctuation characters, or blank spaces are permitted.\
" 20 70 1
fi
CURRENT_HOSTNAME=`cat /etc/hostname | tr -d " \t\n\r"`
if [ "$INTERACTIVE" = True ]; then
NEW_HOSTNAME=$(whiptail --inputbox "Please enter a hostname" 20 60 "$CURRENT_HOSTNAME" 3>&1 1>&2 2>&3)
else
NEW_HOSTNAME=$1
true
fi
if [ $? -eq 0 ]; then
echo $NEW_HOSTNAME > /etc/hostname
sed -i "s/127.0.1.1.*$CURRENT_HOSTNAME/127.0.1.1\t$NEW_HOSTNAME/g" /etc/hosts
ASK_TO_REBOOT=1
fi
}
do_memory_split() { # Memory Split
if [ -e /boot/firmware/start_cd.elf ]; then
# New-style memory split setting
## get current memory split from /boot/firmware/config.txt
arm=$(vcgencmd get_mem arm | cut -d '=' -f 2 | cut -d 'M' -f 1)
gpu=$(vcgencmd get_mem gpu | cut -d '=' -f 2 | cut -d 'M' -f 1)
tot=$(($arm+$gpu))
if [ $tot -gt 512 ]; then
CUR_GPU_MEM=$(get_config_var gpu_mem_1024 $CONFIG)
elif [ $tot -gt 256 ]; then
CUR_GPU_MEM=$(get_config_var gpu_mem_512 $CONFIG)
else
CUR_GPU_MEM=$(get_config_var gpu_mem_256 $CONFIG)
fi
if [ -z "$CUR_GPU_MEM" ] || [ $CUR_GPU_MEM = "0" ]; then
CUR_GPU_MEM=$(get_config_var gpu_mem $CONFIG)
fi
[ -z "$CUR_GPU_MEM" ] || [ $CUR_GPU_MEM = "0" ] && CUR_GPU_MEM=64
## ask users what gpu_mem they want
if [ "$INTERACTIVE" = True ]; then
NEW_GPU_MEM=$(whiptail --inputbox "How much memory (MB) should the GPU have? e.g. 16/32/64/128/256" \
20 70 -- "$CUR_GPU_MEM" 3>&1 1>&2 2>&3)
else
NEW_GPU_MEM=$1
true
fi
if [ $? -eq 0 ]; then
if [ $(get_config_var gpu_mem_1024 $CONFIG) != "0" ] || [ $(get_config_var gpu_mem_512 $CONFIG) != "0" ] || [ $(get_config_var gpu_mem_256 $CONFIG) != "0" ]; then
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "Device-specific memory settings were found. These have been cleared." 20 60 2
fi
clear_config_var gpu_mem_1024 $CONFIG
clear_config_var gpu_mem_512 $CONFIG
clear_config_var gpu_mem_256 $CONFIG
fi
set_config_var gpu_mem "$NEW_GPU_MEM" $CONFIG
ASK_TO_REBOOT=1
fi
else # Old firmware so do start.elf renaming
get_current_memory_split
MEMSPLIT=$(whiptail --menu "Set memory split.\n$MEMSPLIT_DESCRIPTION" 20 60 10 \
"240" "240MiB for ARM, 16MiB for VideoCore" \
"224" "224MiB for ARM, 32MiB for VideoCore" \
"192" "192MiB for ARM, 64MiB for VideoCore" \
"128" "128MiB for ARM, 128MiB for VideoCore" \
3>&1 1>&2 2>&3)
if [ $? -eq 0 ]; then
set_memory_split ${MEMSPLIT}
ASK_TO_REBOOT=1
fi
fi
}
get_current_memory_split() {
AVAILABLE_SPLITS="128 192 224 240"
MEMSPLIT_DESCRIPTION=""
for SPLIT in $AVAILABLE_SPLITS;do
if [ -e /boot/firmware/arm${SPLIT}_start.elf ] && cmp /boot/firmware/arm${SPLIT}_start.elf /boot/firmware/start.elf >/dev/null 2>&1;then
CURRENT_MEMSPLIT=$SPLIT
MEMSPLIT_DESCRIPTION="Current: ${CURRENT_MEMSPLIT}MiB for ARM, $((256 - $CURRENT_MEMSPLIT))MiB for VideoCore"
break
fi
done
}
set_memory_split() {
cp -a /boot/firmware/arm${1}_start.elf /boot/firmware/start.elf
sync
}
do_overclock() {
if ! is_pione && ! is_pitwo; then
whiptail --msgbox "Only Pi 1 or Pi 2 can be overclocked with this tool." 20 60 2
return 1
fi
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "\
Be aware that overclocking may reduce the lifetime of your
Raspberry Pi. If overclocking at a certain level causes
system instability, try a more modest overclock. Hold down
shift during boot to temporarily disable overclock.
See https://www.raspberrypi.org/documentation/configuration/config-txt/overclocking.md for more information.\
" 20 70 1
if is_pione; then
OVERCLOCK=$(whiptail --menu "Choose overclock preset" 20 60 10 \
"None" "700MHz ARM, 250MHz core, 400MHz SDRAM, 0 overvolt" \
"Modest" "800MHz ARM, 250MHz core, 400MHz SDRAM, 0 overvolt" \
"Medium" "900MHz ARM, 250MHz core, 450MHz SDRAM, 2 overvolt" \
"High" "950MHz ARM, 250MHz core, 450MHz SDRAM, 6 overvolt" \
"Turbo" "1000MHz ARM, 500MHz core, 600MHz SDRAM, 6 overvolt" \
3>&1 1>&2 2>&3)
elif is_pitwo; then
OVERCLOCK=$(whiptail --menu "Choose overclock preset" 20 60 10 \
"None" "900MHz ARM, 250MHz core, 450MHz SDRAM, 0 overvolt" \
"High" "1000MHz ARM, 500MHz core, 500MHz SDRAM, 2 overvolt" \
3>&1 1>&2 2>&3)
fi
else
OVERCLOCK=$1
true
fi
if [ $? -eq 0 ]; then
case "$OVERCLOCK" in
None)
clear_overclock
;;
Modest)
set_overclock Modest 800 250 400 0
;;
Medium)
set_overclock Medium 900 250 450 2
;;
High)
if is_pione; then
set_overclock High 950 250 450 6
else
set_overclock High 1000 500 500 2
fi
;;
Turbo)
set_overclock Turbo 1000 500 600 6
;;
*)
whiptail --msgbox "Programmer error, unrecognised overclock preset" 20 60 2
return 1
;;
esac
ASK_TO_REBOOT=1
fi
}
set_overclock() {
set_config_var arm_freq $2 $CONFIG &&
set_config_var core_freq $3 $CONFIG &&
set_config_var sdram_freq $4 $CONFIG &&
set_config_var over_voltage $5 $CONFIG &&
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "Set overclock to preset '$1'" 20 60 2
fi
}
clear_overclock () {
clear_config_var arm_freq $CONFIG &&
clear_config_var core_freq $CONFIG &&
clear_config_var sdram_freq $CONFIG &&
clear_config_var over_voltage $CONFIG &&
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "Set overclock to preset 'None'" 20 60 2
fi
}
get_ssh() {
if service ssh status | grep -q inactive; then
echo 1
else
echo 0
fi
}
do_ssh() {
if [ -e /var/log/regen_ssh_keys.log ] && ! grep -q "^finished" /var/log/regen_ssh_keys.log; then
whiptail --msgbox "Initial ssh key generation still running. Please wait and try again." 20 60 2
return 1
fi
DEFAULT=--defaultno
if [ $(get_ssh) -eq 0 ]; then
DEFAULT=
fi
if [ "$INTERACTIVE" = True ]; then
whiptail --yesno "Would you like the SSH server to be enabled?" $DEFAULT 20 60 2
RET=$?
else
RET=$1
fi
if [ $RET -eq 0 ]; then
ssh-keygen -A &&
update-rc.d ssh enable &&
invoke-rc.d ssh start &&
STATUS=enabled
elif [ $RET -eq 1 ]; then
update-rc.d ssh disable &&
invoke-rc.d ssh stop &&
STATUS=disabled
else
return $RET
fi
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "The SSH server is $STATUS" 20 60 1
fi
}
get_vnc() {
if systemctl status vncserver-x11-serviced.service | grep -q inactive; then
echo 1
else
echo 0
fi
}
do_vnc() {
DEFAULT=--defaultno
if [ $(get_vnc) -eq 0 ]; then
DEFAULT=
fi
if [ "$INTERACTIVE" = True ]; then
whiptail --yesno "Would you like the VNC Server to be enabled?" $DEFAULT 20 60 2
RET=$?
else
RET=$1
fi
if [ $RET -eq 0 ]; then
if [ ! -d /usr/share/doc/realvnc-vnc-server ] ; then
apt-get install realvnc-vnc-server
fi
systemctl enable vncserver-x11-serviced.service &&
systemctl start vncserver-x11-serviced.service &&
STATUS=enabled
elif [ $RET -eq 1 ]; then
systemctl disable vncserver-x11-serviced.service &&
systemctl stop vncserver-x11-serviced.service &&
STATUS=disabled
else
return $RET
fi
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "The VNC Server is $STATUS" 20 60 1
fi
}
get_spi() {
if grep -q -E "^(device_tree_param|dtparam)=([^,]*,)*spi(=(on|true|yes|1))?(,.*)?$" $CONFIG; then
echo 0
else
echo 1
fi
}
do_spi() {
DEFAULT=--defaultno
if [ $(get_spi) -eq 0 ]; then
DEFAULT=
fi
if [ "$INTERACTIVE" = True ]; then
whiptail --yesno "Would you like the SPI interface to be enabled?" $DEFAULT 20 60 2
RET=$?
else
RET=$1
fi
if [ $RET -eq 0 ]; then
SETTING=on
STATUS=enabled
elif [ $RET -eq 1 ]; then
SETTING=off
STATUS=disabled
else
return $RET
fi
set_config_var dtparam=spi $SETTING $CONFIG &&
if ! [ -e $BLACKLIST ]; then
touch $BLACKLIST
fi
sed $BLACKLIST -i -e "s/^\(blacklist[[:space:]]*spi[-_]bcm2708\)/#\1/"
dtparam -d /boot/firmware/overlays spi=$SETTING
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "The SPI interface is $STATUS" 20 60 1
fi
}
get_i2c() {
if grep -q -E "^(device_tree_param|dtparam)=([^,]*,)*i2c(_arm)?(=(on|true|yes|1))?(,.*)?$" $CONFIG; then
echo 0
else
echo 1
fi
}
do_i2c() {
DEFAULT=--defaultno
if [ $(get_i2c) -eq 0 ]; then
DEFAULT=
fi
if [ "$INTERACTIVE" = True ]; then
whiptail --yesno "Would you like the ARM I2C interface to be enabled?" $DEFAULT 20 60 2
RET=$?
else
RET=$1
fi
if [ $RET -eq 0 ]; then
SETTING=on
STATUS=enabled
elif [ $RET -eq 1 ]; then
SETTING=off
STATUS=disabled
else
return $RET
fi
set_config_var dtparam=i2c_arm $SETTING $CONFIG &&
if ! [ -e $BLACKLIST ]; then
touch $BLACKLIST
fi
sed $BLACKLIST -i -e "s/^\(blacklist[[:space:]]*i2c[-_]bcm2708\)/#\1/"
sed /etc/modules -i -e "s/^#[[:space:]]*\(i2c[-_]dev\)/\1/"
if ! grep -q "^i2c[-_]dev" /etc/modules; then
printf "i2c-dev\n" >> /etc/modules
fi
dtparam -d /boot/firmware/overlays i2c_arm=$SETTING
modprobe i2c-dev
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "The ARM I2C interface is $STATUS" 20 60 1
fi
}
get_serial() {
if grep -q -E "console=(serial0|ttyAMA0|ttyS0)" $CMDLINE ; then
echo 0
else
echo 1
fi
}
get_serial_hw() {
if grep -q -E "^enable_uart=1" $CONFIG ; then
echo 0
elif grep -q -E "^enable_uart=0" $CONFIG ; then
echo 1
elif [ -e /dev/serial0 ] ; then
echo 0
else
echo 1
fi
}
do_serial() {
DEFAULTS=--defaultno
DEFAULTH=--defaultno
CURRENTS=0
CURRENTH=0
if [ $(get_serial) -eq 0 ]; then
DEFAULTS=
CURRENTS=1
fi
if [ $(get_serial_hw) -eq 0 ]; then
DEFAULTH=
CURRENTH=1
fi
if [ "$INTERACTIVE" = True ]; then
whiptail --yesno "Would you like a login shell to be accessible over serial?" $DEFAULTS 20 60 2
RET=$?
else
RET=$1
fi
if [ $RET -eq $CURRENTS ]; then
ASK_TO_REBOOT=1
fi
if [ $RET -eq 0 ]; then
if grep -q "console=ttyAMA0" $CMDLINE ; then
if [ -e /proc/device-tree/aliases/serial0 ]; then
sed -i $CMDLINE -e "s/console=ttyAMA0/console=serial0/"
fi
elif ! grep -q "console=ttyAMA0" $CMDLINE && ! grep -q "console=serial0" $CMDLINE ; then
if [ -e /proc/device-tree/aliases/serial0 ]; then
sed -i $CMDLINE -e "s/root=/console=serial0,115200 root=/"
else
sed -i $CMDLINE -e "s/root=/console=ttyAMA0,115200 root=/"
fi
fi
set_config_var enable_uart 1 $CONFIG
SSTATUS=enabled
HSTATUS=enabled
elif [ $RET -eq 1 ] || [ $RET -eq 2 ]; then
sed -i $CMDLINE -e "s/console=ttyAMA0,[0-9]\+ //"
sed -i $CMDLINE -e "s/console=serial0,[0-9]\+ //"
SSTATUS=disabled
if [ "$INTERACTIVE" = True ]; then
whiptail --yesno "Would you like the serial port hardware to be enabled?" $DEFAULTH 20 60 2
RET=$?
else
RET=$((2-$RET))
fi
if [ $RET -eq $CURRENTH ]; then
ASK_TO_REBOOT=1
fi
if [ $RET -eq 0 ]; then
set_config_var enable_uart 1 $CONFIG
HSTATUS=enabled
elif [ $RET -eq 1 ]; then
set_config_var enable_uart 0 $CONFIG
HSTATUS=disabled
else
return $RET
fi
else
return $RET
fi
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "The serial login shell is $SSTATUS\nThe serial interface is $HSTATUS" 20 60 1
fi
}
disable_raspi_config_at_boot() {
if [ -e /etc/profile.d/raspi-config.sh ]; then
rm -f /etc/profile.d/raspi-config.sh
if [ -e /etc/systemd/system/[email protected]/raspi-config-override.conf ]; then
rm /etc/systemd/system/[email protected]/raspi-config-override.conf
fi
telinit q
fi
}
get_boot_cli() {
if systemctl get-default | grep -q multi-user ; then
echo 0
else
echo 1
fi
}
get_autologin() {
if [ $(get_boot_cli) -eq 0 ]; then
# booting to CLI
# stretch or buster - is there an autologin conf file?
if [ -e /etc/systemd/system/[email protected]/autologin.conf ] ; then
echo 0
else
# stretch or earlier - check the getty service symlink for autologin
if [ $(deb_ver) -le 9 ] && grep -q autologin /etc/systemd/system/getty.target.wants/[email protected] ; then
echo 0
else
echo 1
fi
fi
else
# booting to desktop - check the autologin for lightdm
if grep -q "^autologin-user=" /etc/lightdm/lightdm.conf ; then
echo 0
else
echo 1
fi
fi
}
get_pi4video () {
if grep -q "^hdmi_enable_4kp60=1" $CONFIG ; then
echo 1
elif grep -q "^enable_tvout=1" $CONFIG ; then
echo 2
else
echo 0
fi
}
do_pi4video() {