forked from asb/raspi-config
-
Notifications
You must be signed in to change notification settings - Fork 212
/
raspi-config
executable file
·3959 lines (3748 loc) · 117 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
#
# See LICENSE file for copyright and license details
INTERACTIVE=True
ASK_TO_REBOOT=0
BLACKLIST=/etc/modprobe.d/raspi-blacklist.conf
if [ -e /boot/firmware/config.txt ] ; then
FIRMWARE=/firmware
else
FIRMWARE=
fi
CONFIG=/boot${FIRMWARE}/config.txt
USER=${SUDO_USER:-$(who -m | awk '{ print $1 }')}
if [ -z "$USER" ] && [ -n "$HOME" ]; then
USER=$(getent passwd | awk -F: "\$6 == \"$HOME\" {print \$1}")
fi
if [ -z "$USER" ] || [ "$USER" = "root" ]; then
USER=$(getent passwd | awk -F: '$3 == "1000" {print $1}')
fi
INIT="$(ps --no-headers -o comm 1)"
HOMEDIR="$(getent passwd "$USER" | cut -d: -f6)"
WAYFIRE_FILE="$HOMEDIR/.config/wayfire.ini"
LABWCENV_FILE="$HOMEDIR/.config/labwc/environment"
LABWCAST_FILE="$HOMEDIR/.config/labwc/autostart"
is_pi () {
ARCH=$(dpkg --print-architecture)
if [ "$ARCH" = "armhf" ] || [ "$ARCH" = "arm64" ] ; then
return 0
else
return 1
fi
}
is_64bit () {
ARCH=$(dpkg --print-architecture)
if [ "$ARCH" = "arm64" ] ; then
return 0
else
return 1
fi
}
if is_pi ; then
if [ -e /proc/device-tree/chosen/os_prefix ]; then
PREFIX="$(tr -d '\0' < /proc/device-tree/chosen/os_prefix)"
fi
CMDLINE="/boot${FIRMWARE}/${PREFIX}cmdline.txt"
else
CMDLINE=/proc/cmdline
fi
# tests for Pi 1, 2 and 0 all test for specific boards...
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 $?
}
# ...while tests for Pi 3 and 4 just test processor type, so will also find CM3, CM4, Zero 2 etc.
is_pithree() {
grep -q "^Revision\s*:\s*[ 123][0-9a-fA-F][0-9a-fA-F]2[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]$" /proc/cpuinfo
return $?
}
is_pifour() {
grep -q "^Revision\s*:\s*[ 123][0-9a-fA-F][0-9a-fA-F]3[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]$" /proc/cpuinfo
return $?
}
is_pifive() {
grep -q "^Revision\s*:\s*[ 123][0-9a-fA-F][0-9a-fA-F]4[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]$" /proc/cpuinfo
return $?
}
is_cmfive() {
grep -q "^Revision\s*:\s*[ 123][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]1[8aA][0-9a-fA-F]$" /proc/cpuinfo
return $?
}
get_pi_type() {
if is_pione; then
echo 1
elif is_pitwo; then
echo 2
elif is_pithree; then
echo 3
elif is_pifour; then
echo 4
elif is_pifive; then
echo 5
elif is_pizero; then
echo 0
else
echo -1
fi
}
gpu_has_mmu() {
if is_pifour || is_pifive ; then
return 0
else
return 1
fi
}
is_live() {
grep -q "boot=live" $CMDLINE
return $?
}
is_ssh() {
if pstree -p | grep -qE ".*sshd.*\($$\)"; then
return 0
else
return 1
fi
}
is_kms() {
return 0
}
is_pulseaudio() {
pgrep pulseaudio > /dev/null || pgrep pipewire-pulse > /dev/null
return $?
}
is_wayfire() {
pgrep wayfire > /dev/null
return $?
}
is_labwc() {
pgrep labwc > /dev/null
return $?
}
is_wayland() {
if is_wayfire; then
return 0
elif is_labwc; then
return 0
else
return 1
fi
}
has_analog() {
if [ $(get_leds) -eq -1 ] ; then
return 0
else
return 1
fi
}
is_installed() {
if [ "$(dpkg -l "$1" 2> /dev/null | tail -n 1 | cut -d ' ' -f 1)" != "ii" ]; then
return 1
else
return 0
fi
}
deb_ver () {
ver=$(cut -d . -f 1 < /etc/debian_version)
echo $ver
}
get_package_version() {
dpkg-query --showformat='${Version}' --show "$1"
}
can_configure() {
if [ ! -e /etc/init.d/lightdm ]; then
return 1
fi
if ! is_pi; then
return 0
fi
if [ ! -e /boot${FIRMWARE}/start_x.elf ]; then
return 1
fi
if [ -e $CONFIG ] && grep -q "^device_tree=$" $CONFIG; then
return 1
fi
if ! mountpoint -q /boot${FIRMWARE}; then
return 1
fi
if [ ! -e $CONFIG ]; then
touch $CONFIG
fi
return 0
}
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=18
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 straightforward 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.
$(dpkg -s raspi-config 2> /dev/null | grep Version)\
" 20 70 1
return 0
}
get_can_expand() {
ROOT_PART="$(findmnt / -o source -n)"
ROOT_DEV="/dev/$(lsblk -no pkname "$ROOT_PART")"
PART_NUM="$(echo "$ROOT_PART" | grep -o "[[:digit:]]*$")"
if [ "$PART_NUM" -ne 2 ]; then
echo 1
exit
fi
LAST_PART_NUM=$(parted "$ROOT_DEV" -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="$(findmnt / -o source -n)"
ROOT_DEV="/dev/$(lsblk -no pkname "$ROOT_PART")"
PART_NUM="$(echo "$ROOT_PART" | grep -o "[[:digit:]]*$")"
LAST_PART_NUM=$(parted "$ROOT_DEV" -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 "$ROOT_DEV" -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 "$ROOT_DEV" <<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 "$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_overscan_kms() {
RES=$(grep "HDMI-$1" /usr/share/ovscsetup.sh 2> /dev/null | grep margin | rev | cut -d ' ' -f 1 | rev)
if [ -z $RES ] ; then
echo 1
elif [ $RES -eq 0 ] ; then
echo 1
else
echo 0
fi
}
do_overscan_kms() {
if [ "$INTERACTIVE" = True ]; then
NDEVS=$(xrandr -q | grep -c connected)
if [ $NDEVS -gt 1 ] ; then
DEV=$(whiptail --menu "Select the output for which overscan compensation is to be set" 20 60 10 "1" "HDMI-1" "2" "HDMI-2" 3>&1 1>&2 2>&3)
if [ $? -eq 1 ] ; then
return
fi
else
DEV=1
fi
if [ $(get_overscan_kms $DEV) -eq 1 ]; then
DEFAULT=--defaultno
else
DEFAULT=
fi
if whiptail --yesno "Would you like to enable overscan compensation for HDMI-$DEV?" $DEFAULT 20 60 2 ; then
PIX=16
STATUS="enabled"
else
PIX=0
STATUS="disabled"
fi
else
DEV=$1
if [ $2 -eq 1 ] ; then
PIX=0
else
PIX=16
fi
fi
xrandr --output HDMI-$DEV --set "left margin" $PIX --set "right margin" $PIX --set "top margin" $PIX --set "bottom margin" $PIX
# hack to force reload when not using mutter
if ! pgrep mutter > /dev/null ; then
xrandr --output HDMI-$DEV --reflect x
xrandr --output HDMI-$DEV --reflect normal
fi
sed $CONFIG -i -e "s/^overscan_/#overscan_/"
set_config_var disable_overscan 1 $CONFIG
if [ -e /usr/share/ovscsetup.sh ] ; then
if grep "HDMI-$DEV" /usr/share/ovscsetup.sh 2> /dev/null | grep -q margin ; then
sed /usr/share/ovscsetup.sh -i -e "s/xrandr --output HDMI-$DEV.*margin.*/xrandr --output HDMI-$DEV --set \"left margin\" $PIX --set \"right margin\" $PIX --set \"top margin\" $PIX --set \"bottom margin\" $PIX/"
else
echo "xrandr --output HDMI-$DEV --set \"left margin\" $PIX --set \"right margin\" $PIX --set \"top margin\" $PIX --set \"bottom margin\" $PIX" >> /usr/share/ovscsetup.sh
fi
else
echo "#!/bin/sh" > /usr/share/ovscsetup.sh
echo "xrandr --output HDMI-$DEV --set \"left margin\" $PIX --set \"right margin\" $PIX --set \"top margin\" $PIX --set \"bottom margin\" $PIX" >> /usr/share/ovscsetup.sh
fi
if ! grep -q ovscsetup /usr/share/dispsetup.sh 2> /dev/null ; then
sed /usr/share/dispsetup.sh -i -e "s#exit#if [ -e /usr/share/ovscsetup.sh ] ; then\n. /usr/share/ovscsetup.sh\nfi\nexit#"
fi
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "Display overscan compensation for HDMI-$DEV is $STATUS" 20 60 1
fi
}
get_blanking() {
if is_wayfire; then
if ! grep -q dpms_timeout $WAYFIRE_FILE ; then
echo 1
elif ! grep -q "dpms_timeout.*-1" $WAYFIRE_FILE ; then
echo 0
else
echo 1
fi
elif is_labwc; then
if [ -e $LABWCAST_FILE ] && grep -q swayidle $LABWCAST_FILE ; then
echo 0
else
echo 1
fi
else
if ! [ -f "/etc/X11/xorg.conf.d/10-blanking.conf" ]; then
echo 0
else
echo 1
fi
fi
}
do_blanking() {
DEFAULT=--defaultno
CURRENT=0
if [ "$(get_blanking)" -eq 0 ]; then
DEFAULT=
CURRENT=1
fi
if is_wayfire; then
if [ "$INTERACTIVE" = True ]; then
whiptail --yesno "Would you like to enable screen blanking?" $DEFAULT 20 60 2
RET=$?
else
RET=$1
fi
if [ "$RET" -eq 0 ] ; then
if grep -q dpms_timeout $WAYFIRE_FILE ; then
sed -i 's/dpms_timeout.*/dpms_timeout=600/' $WAYFIRE_FILE
else
if grep -q "\[idle\]" $WAYFIRE_FILE ; then
sed -i 's/\[idle]/[idle]\ndpms_timeout=600/' $WAYFIRE_FILE
else
echo '\n[idle]\ndpms_timeout=600' >> $WAYFIRE_FILE
chown $USER:$USER $WAYFIRE_FILE
fi
fi
STATUS=enabled
elif [ "$RET" -eq 1 ]; then
if grep -q dpms_timeout $WAYFIRE_FILE ; then
sed -i 's/dpms_timeout.*/dpms_timeout=-1/' $WAYFIRE_FILE
else
if grep -q "\[idle\]" $WAYFIRE_FILE ; then
sed -i 's/\[idle]/[idle]\ndpms_timeout=-1/' $WAYFIRE_FILE
else
echo '\n[idle]\ndpms_timeout=-1' >> $WAYFIRE_FILE
chown $USER:$USER $WAYFIRE_FILE
fi
fi
STATUS=disabled
else
return "$RET"
fi
elif is_labwc; then
if [ "$INTERACTIVE" = True ]; then
whiptail --yesno "Would you like to enable screen blanking?" $DEFAULT 20 60 2
RET=$?
else
RET=$1
fi
if [ "$RET" -eq "$CURRENT" ]; then
ASK_TO_REBOOT=1
fi
mkdir -p "$HOMEDIR/.config/labwc/"
chown -R $USER:$USER "$HOMEDIR/.config/labwc/"
if [ "$RET" -eq 0 ] ; then
echo "swayidle -w timeout 600 'wlopm --off \\*' resume 'wlopm --on \\*' &" >> $LABWCAST_FILE
chown $USER:$USER $LABWCAST_FILE
STATUS=enabled
elif [ "$RET" -eq 1 ]; then
if [ -e $LABWCAST_FILE ] ; then
sed -i '/swayidle/d' $LABWCAST_FILE
fi
STATUS=disabled
else
return "$RET"
fi
else
if [ "$INTERACTIVE" = True ]; then
if [ "$(dpkg -l xscreensaver | tail -n 1 | cut -d ' ' -f 1)" = "ii" ]; then
whiptail --msgbox "Warning: xscreensaver is installed and may override raspi-config settings" 20 60 2
fi
whiptail --yesno "Would you like to enable screen blanking?" $DEFAULT 20 60 2
RET=$?
else
RET=$1
fi
if [ "$RET" -eq "$CURRENT" ]; then
ASK_TO_REBOOT=1
fi
rm -f /etc/X11/xorg.conf.d/10-blanking.conf
sed -i '/^\o033/d' /etc/issue
if [ "$RET" -eq 0 ] ; then
STATUS=enabled
elif [ "$RET" -eq 1 ]; then
mkdir -p /etc/X11/xorg.conf.d/
cp /usr/share/raspi-config/10-blanking.conf /etc/X11/xorg.conf.d/
printf "\\033[9;0]" >> /etc/issue
STATUS=disabled
else
return "$RET"
fi
fi
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "Screen blanking is $STATUS" 20 60 1
fi
}
do_change_pass() {
whiptail --msgbox "You will now be asked to enter a new password for the $USER user" 20 60 1
passwd $USER &&
whiptail --msgbox "Password changed successfully" 20 60 1
}
update_wayfire_keyboard() {
if ! is_wayfire ; then
return
fi
MODEL=$(grep XKBMODEL /etc/default/keyboard | cut -d= -f2 | tr -d '"')
LAYOUT=$(grep XKBLAYOUT /etc/default/keyboard | cut -d= -f2 | tr -d '"')
VARIANT=$(grep XKBVARIANT /etc/default/keyboard | cut -d= -f2 | tr -d '"')
OPTIONS=$(grep XKBOPTIONS /etc/default/keyboard | cut -d= -f2 | tr -d '"')
UFILE=$WAYFIRE_FILE
if [ ! -e $UFILE ] && [ -e /etc/wayfire/template.ini ] ; then
CONFIG_DIR="$(dirname "$UFILE")"
if ! [ -d "$CONFIG_DIR" ]; then
install -o "$USER" -g "$USER" -d "$CONFIG_DIR"
fi
cp /etc/wayfire/template.ini $UFILE
chown $USER:$USER $UFILE
fi
if [ -e $UFILE ] ; then
grep -q "\\[input\\]" $UFILE || printf "\n[input]" >> $UFILE
if grep -q xkb_model $UFILE ; then sed -i s/xkb_model.*/xkb_model=$MODEL/ $UFILE ; else sed -i s/\\[input\\]/[input]\\nxkb_model=$MODEL/ $UFILE ; fi
if grep -q xkb_layout $UFILE ; then sed -i s/xkb_layout.*/xkb_layout=$LAYOUT/ $UFILE ; else sed -i s/\\[input\\]/[input]\\nxkb_layout=$LAYOUT/ $UFILE ; fi
if grep -q xkb_variant $UFILE ; then sed -i s/xkb_variant.*/xkb_variant=$VARIANT/ $UFILE ; else sed -i s/\\[input\\]/[input]\\nxkb_variant=$VARIANT/ $UFILE ; fi
if grep -q xkb_options $UFILE ; then sed -i s/xkb_options.*/xkb_options=$OPTIONS/ $UFILE ; else sed -i s/\\[input\\]/[input]\\nxkb_options=$OPTIONS/ $UFILE ; fi
fi
UFILE="/usr/share/greeter.ini"
if [ ! -e $UFILE ] && [ -e /etc/wayfire/gtemplate.ini ] ; then
cp /etc/wayfire/gtemplate.ini $UFILE
fi
if [ -e $UFILE ] ; then
grep -q "\\[input\\]" $UFILE || printf "\n[input]" >> $UFILE
if grep -q xkb_model $UFILE ; then sed -i s/xkb_model.*/xkb_model=$MODEL/ $UFILE ; else sed -i s/\\[input\\]/[input]\\nxkb_model=$MODEL/ $UFILE ; fi
if grep -q xkb_layout $UFILE ; then sed -i s/xkb_layout.*/xkb_layout=$LAYOUT/ $UFILE ; else sed -i s/\\[input\\]/[input]\\nxkb_layout=$LAYOUT/ $UFILE ; fi
if grep -q xkb_variant $UFILE ; then sed -i s/xkb_variant.*/xkb_variant=$VARIANT/ $UFILE ; else sed -i s/\\[input\\]/[input]\\nxkb_variant=$VARIANT/ $UFILE ; fi
if grep -q xkb_options $UFILE ; then sed -i s/xkb_options.*/xkb_options=$OPTIONS/ $UFILE ; else sed -i s/\\[input\\]/[input]\\nxkb_options=$OPTIONS/ $UFILE ; fi
fi
}
update_labwc_keyboard() {
MODEL=$(grep XKBMODEL /etc/default/keyboard | cut -d= -f2 | tr -d '"')
LAYOUT=$(grep XKBLAYOUT /etc/default/keyboard | cut -d= -f2 | tr -d '"')
VARIANT=$(grep XKBVARIANT /etc/default/keyboard | cut -d= -f2 | tr -d '"')
OPTIONS=$(grep XKBOPTIONS /etc/default/keyboard | cut -d= -f2 | tr -d '"')
UFILE=$LABWCENV_FILE
mkdir -p "$HOMEDIR/.config/labwc/"
chown -R $USER:$USER "$HOMEDIR/.config/labwc/"
if [ -e $UFILE ] ; then
if grep -q XKB_DEFAULT_MODEL $UFILE ; then sed -i s/XKB_DEFAULT_MODEL.*/XKB_DEFAULT_MODEL=$MODEL/ $UFILE ; else echo XKB_DEFAULT_MODEL=$MODEL >> $UFILE ; fi
if grep -q XKB_DEFAULT_LAYOUT $UFILE ; then sed -i s/XKB_DEFAULT_LAYOUT.*/XKB_DEFAULT_LAYOUT=$LAYOUT/ $UFILE ; else echo XKB_DEFAULT_LAYOUT=$LAYOUT >> $UFILE ; fi
if grep -q XKB_DEFAULT_VARIANT $UFILE ; then sed -i s/XKB_DEFAULT_VARIANT.*/XKB_DEFAULT_VARIANT=$VARIANT/ $UFILE ; else echo XKB_DEFAULT_VARIANT=$VARIANT >> $UFILE ; fi
if grep -q XKB_DEFAULT_OPTIONS $UFILE ; then sed -i s/XKB_DEFAULT_OPTIONS.*/XKB_DEFAULT_OPTIONS=$OPTIONS/ $UFILE ; else echo XKB_DEFAULT_OPTIONS=$OPTIONS >> $UFILE ; fi
else
echo XKB_DEFAULT_MODEL=$MODEL >> $UFILE
echo XKB_DEFAULT_LAYOUT=$LAYOUT >> $UFILE
echo XKB_DEFAULT_VARIANT=$VARIANT >> $UFILE
echo XKB_DEFAULT_OPTIONS=$OPTIONS >> $UFILE
fi
chown $USER:$USER $UFILE
UFILE="/usr/share/labwc/environment"
if [ -e $UFILE ] ; then
if grep -q XKB_DEFAULT_MODEL $UFILE ; then sed -i s/XKB_DEFAULT_MODEL.*/XKB_DEFAULT_MODEL=$MODEL/ $UFILE ; else echo XKB_DEFAULT_MODEL=$MODEL >> $UFILE ; fi
if grep -q XKB_DEFAULT_LAYOUT $UFILE ; then sed -i s/XKB_DEFAULT_LAYOUT.*/XKB_DEFAULT_LAYOUT=$LAYOUT/ $UFILE ; else echo XKB_DEFAULT_LAYOUT=$LAYOUT >> $UFILE ; fi
if grep -q XKB_DEFAULT_VARIANT $UFILE ; then sed -i s/XKB_DEFAULT_VARIANT.*/XKB_DEFAULT_VARIANT=$VARIANT/ $UFILE ; else echo XKB_DEFAULT_VARIANT=$VARIANT >> $UFILE ; fi
if grep -q XKB_DEFAULT_OPTIONS $UFILE ; then sed -i s/XKB_DEFAULT_OPTIONS.*/XKB_DEFAULT_OPTIONS=$OPTIONS/ $UFILE ; else echo XKB_DEFAULT_OPTIONS=$OPTIONS >> $UFILE ; fi
fi
if is_labwc ; then
kill -HUP `pgrep -x labwc` # does the equivalent of labwc --reconfigure, but works as sudo...
fi
}
update_squeekboard() {
PREFIX=""
if [ -n "$SUDO_USER" ] ; then
PREFIX="sudo -u $USER XDG_RUNTIME_DIR=/run/user/$SUDO_UID DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$SUDO_UID/bus "
fi
LAYOUT1=$(grep XKBLAYOUT /etc/default/keyboard | cut -d= -f2 | tr -d '"' | cut -d, -f1)
VARIANT1=$(grep XKBVARIANT /etc/default/keyboard | cut -d= -f2 | tr -d '"' | cut -d, -f1)
LAYOUT2=$(grep XKBLAYOUT /etc/default/keyboard | cut -d= -f2 | tr -d '"' | cut -d, -f2 -s)
VARIANT2=$(grep XKBVARIANT /etc/default/keyboard | cut -d= -f2 | tr -d '"' | cut -d, -f2 -s)
GSET="[('xkb', '$LAYOUT1"
if [ -z "$VARIANT1" ] ; then
GSET=$GSET"')"
else
GSET=$GSET"+$VARIANT1')"
fi
if ! [ -z "$LAYOUT2" ] ; then
GSET=$GSET", ('xkb', '$LAYOUT2"
if [ -z "$VARIANT2" ] ; then
GSET=$GSET"')"
else
GSET=$GSET"+$VARIANT2')"
fi
fi
GSET=$GSET"]"
if ! [ -e /etc/dconf/profile/user ] ; then
mkdir -p "/etc/dconf/profile/"
echo "user-db:user\nsystem-db:local" >> /etc/dconf/profile/user
fi
FILE=/etc/dconf/db/local.d/00_keyboard
if [ -e $FILE ] ; then
if grep -q "^sources" $FILE ; then
sed $FILE -i -e "s/^sources=.*/sources=$GSET/"
else
if grep -q "\[org/gnome/desktop/input-sources\]" $FILE ; then
sed $FILE -i -e "s#\[org/gnome/desktop/input-sources\]#\[org/gnome/desktop/input-sources\]\nsources=$GSET#"
else
echo "[org/gnome/desktop/input-sources]\nsources=$GSET" >> $FILE
fi
fi
else
mkdir -p "/etc/dconf/db/local.d/"
echo "[org/gnome/desktop/input-sources]\nsources=$GSET" > $FILE
fi
dconf update
if [ "$1" = restart ] ; then
if pgrep squeekboard > /dev/null ; then
pkill squeekboard
$PREFIX squeekboard > /dev/null 2> /dev/null &
fi
fi
}
do_configure_keyboard() {
printf "Reloading keymap. This may take a short while\n"
rm -f /etc/console-setup/cached_*
if [ "$INTERACTIVE" = True ]; then
dpkg-reconfigure keyboard-configuration
else
KEYMAP="$1"
sed -i /etc/default/keyboard -e "s/^XKBLAYOUT.*/XKBLAYOUT=\"$KEYMAP\"/"
dpkg-reconfigure -f noninteractive keyboard-configuration
fi
update_wayfire_keyboard
update_labwc_keyboard
update_squeekboard restart
if [ "$INIT" = "systemd" ]; then
systemctl restart keyboard-setup
fi
setsid sh -c 'exec setupcon --save -k --force <> /dev/tty1 >&0 2>&1'
udevadm trigger --subsystem-match=input --action=change
return 0
}
do_change_keyboard_rc_gui () {
grep -q XKBMODEL /etc/default/keyboard && sed -i "s/XKBMODEL=.*/XKBMODEL=\"$1\"/g" /etc/default/keyboard || echo "XKBMODEL=\"$1\"" >> /etc/default/keyboard
grep -q XKBLAYOUT /etc/default/keyboard && sed -i "s/XKBLAYOUT=.*/XKBLAYOUT=\"$2\"/g" /etc/default/keyboard || echo "XKBLAYOUT=\"$2\"" >> /etc/default/keyboard
grep -q XKBVARIANT /etc/default/keyboard && sed -i "s/XKBVARIANT=.*/XKBVARIANT=\"$3\"/g" /etc/default/keyboard || echo "XKBVARIANT=\"$3\"" >> /etc/default/keyboard
grep -q XKBOPTIONS /etc/default/keyboard && sed -i "s/XKBOPTIONS=.*/XKBOPTIONS=\"$4\"/g" /etc/default/keyboard || echo "XKBOPTIONS=\"$4\"" >> /etc/default/keyboard
update_wayfire_keyboard
update_labwc_keyboard
update_squeekboard restart
if ! is_wayland ; then
invoke-rc.d keyboard-setup start
fi
setsid sh -c 'exec setupcon -k --force <> /dev/tty1 >&0 2>&1'
if ! is_wayland ; then
udevadm trigger --subsystem-match=input --action=change
udevadm settle
KBSTR="-model $1 -layout $2"
if [ -n "$3" ] ; then
KBSTR="$KBSTR -variant $3"
fi
if [ -n "$4" ] ; then
KBSTR="$KBSTR -option -option $4"
fi
setxkbmap "$KBSTR"
fi
}
do_change_locale() {
if [ "$INTERACTIVE" = True ]; then
dpkg-reconfigure locales
else
if ! LOCALE_LINE="$(grep -E "^$1( |$)" /usr/share/i18n/SUPPORTED)"; then
return 1
fi
export LC_ALL=C
export LANG=C
LG="/etc/locale.gen"
NEW_LANG="$(echo $LOCALE_LINE | cut -f1 -d " ")"
[ -L "$LG" ] && [ "$(readlink $LG)" = "/usr/share/i18n/SUPPORTED" ] && rm -f "$LG"
echo "$LOCALE_LINE" > /etc/locale.gen
update-locale --no-checks LANG
update-locale --no-checks "LANG=$NEW_LANG"
dpkg-reconfigure -f noninteractive locales
fi
}
do_change_locale_rc_gui() {
sed -i "s/^\([^#].*\)/# \1/g" /etc/locale.gen
if grep -q "$1 " /etc/locale.gen ; then
LOC="$1"
else
LOC="$1.UTF-8"
fi
sed -i "s/^# \($LOC\s\)/\1/g" /etc/locale.gen
locale-gen
LC_ALL=$LOC LANG=$LOC LANGUAGE=$LOC update-locale LANG=$LOC LC_ALL=$LOC LANGUAGE=$LOC
}
do_change_timezone() {
if [ "$INTERACTIVE" = True ]; then
dpkg-reconfigure tzdata
else
TIMEZONE="$1"
if [ ! -f "/usr/share/zoneinfo/$TIMEZONE" ]; then
return 1;
fi
rm /etc/localtime
echo "$TIMEZONE" > /etc/timezone
dpkg-reconfigure -f noninteractive tzdata 2> /dev/null
fi
}
do_change_timezone_rc_gui() {
echo $1 | tee /etc/timezone
rm /etc/localtime
dpkg-reconfigure --frontend noninteractive tzdata
}
get_wifi_country() {
CODE=${1:-0}
if is_installed crda && [ -e /etc/default/crda ]; then
. /etc/default/crda
elif grep -q "cfg80211.ieee80211_regdom=" "$CMDLINE"; then
REGDOMAIN="$(sed -n 's/.*cfg80211.ieee80211_regdom=\(\S*\).*/\1/p' "$CMDLINE")"
elif systemctl -q is-active dhcpcd; then
REGDOMAIN="$(wpa_cli get country | tail -n 1)"
else
REGDOMAIN="$(iw reg get | sed -n "0,/country/s/^country \(.\+\):.*$/\1/p")"
fi
if [ -z "$REGDOMAIN" ] \
|| ! grep -q "^${REGDOMAIN}[[:space:]]" /usr/share/zoneinfo/iso3166.tab; then
return 1
fi
if [ "$CODE" = 0 ]; then
echo "$REGDOMAIN"
fi
return 0
}
do_wifi_country() {
if [ "$INTERACTIVE" = True ]; then
value=$(sed '/^#/d' /usr/share/zoneinfo/iso3166.tab | tr '\t\n' '/')
oIFS="$IFS"
IFS="/"
#shellcheck disable=2086
REGDOMAIN=$(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
REGDOMAIN=$1
fi
if ! grep -q "^${REGDOMAIN}[[:space:]]" /usr/share/zoneinfo/iso3166.tab; then
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "$REGDOMAIN is not a valid ISO/IEC 3166-1 alpha2 code" 20 60
fi
return 1
fi
sed -i \
-e "s/\s*cfg80211.ieee80211_regdom=\S*//" \
-e "s/\(.*\)/\1 cfg80211.ieee80211_regdom=$REGDOMAIN/" \
"$CMDLINE"
if is_installed crda && [ -e /etc/default/crda ]; then
# This mechanism has been removed from Bookworm and should no longer be used
rm -f /etc/default/crda
fi
if ! ischroot; then
iw reg set "$REGDOMAIN"
fi
IFACE="$(list_wlan_interfaces | head -n 1)"
if [ "$INIT" = "systemd" ] && [ -n "$IFACE" ] && systemctl -q is-active dhcpcd; then
wpa_cli -i "$IFACE" set country "$REGDOMAIN" > /dev/null 2>&1
wpa_cli -i "$IFACE" save_config > /dev/null 2>&1
fi
if [ "$INIT" = "systemd" ] && ! ischroot && systemctl -q is-active NetworkManager; then
nmcli radio wifi on
elif hash rfkill 2> /dev/null; then
rfkill unblock wifi
if [ -f /var/lib/NetworkManager/NetworkManager.state ]; then
sed -i 's/^WirelessEnabled=.*/WirelessEnabled=true/' /var/lib/NetworkManager/NetworkManager.state
fi
fi
if is_pi; then
for filename in /var/lib/systemd/rfkill/*:wlan ; do
if ! [ -e "$filename" ]; then
continue
fi
echo 0 > "$filename"
done
fi
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "Wireless LAN country set to $REGDOMAIN" 20 60 1
fi
if ! ischroot && pgrep wf-panel-pi > /dev/null; then
wfpanelctl netman cset
fi
if ! ischroot && pgrep lxpanel > /dev/null; then
lxpanelctl command netman cset
fi
}
get_hostname() {
tr -d " \t\n\r" < /etc/hostname
}
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=$(get_hostname)
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
if [ "$INIT" = "systemd" ] && systemctl -q is-active dbus && ! ischroot; then
hostnamectl set-hostname "$NEW_HOSTNAME" 2> /dev/null
else
echo "$NEW_HOSTNAME" > /etc/hostname
fi
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_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