-
Notifications
You must be signed in to change notification settings - Fork 87
/
rpi.sh
executable file
·126 lines (118 loc) · 3.17 KB
/
rpi.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/bin/bash
###
# Helper scripts for setting various parameters and config for
# Raspberry Pi units running Raspberry Pi OS.
###
display_help() {
echo "Raspberry Pi Dash additional install helpers Version 0.3"
echo "Usage: $0 [option...]" >&2
echo
echo " -arb, --addrulebrightness Add udev rules for brightness"
echo " -mem, --memorysplit Set memory split"
echo " -gl, --gldriver Set GL driver"
echo " -krn, --krnbt Set krnbt flag"
echo " -h, --help Show help of script"
echo
echo "Example: Add touchscreen brightness rule on your RPI."
echo " rpi -arb"
echo
echo "Example: Set memory split on your RPI."
echo " rpi -mem 128"
echo
echo "Example: Set GL driver on your RPI."
echo " rpi -gl [G2|G1]"
echo " KMS (G2) / Fake KMS (G1)"
echo
echo "Example: Set krnbt flag on your RPI."
echo " rpi -krn"
echo
exit 1
}
add_brightness_udev_rule() {
FILE=/etc/udev/rules.d/52-dashbrightness.rules
if [[ ! -f "$FILE" ]]; then
# udev rules to allow write access to all users for Raspberry Pi 7" Touch Screen
echo "SUBSYSTEM==\"backlight\", RUN+=\"/bin/chmod 666 /sys/class/backlight/%k/brightness\"" | sudo tee $FILE
if [[ $? -eq 0 ]]; then
echo -e "Permissions created\n"
else
echo -e "Unable to create permissions\n"
fi
else
echo -e "Rules exists\n"
fi
}
set_memory_split() {
sudo raspi-config nonint do_memory_split $2
if [[ $? -eq 0 ]]; then
echo -e "Memory set to 128mb\n"
else
echo "Setting memory failed with error code $? please set manually"
exit 1
fi
}
set_opengl() {
sudo raspi-config nonint do_gldriver $2
if [[ $? -eq 0 ]]; then
echo -e "OpenGL set ok\n"
else
echo "Setting openGL failed with error code $? please set manually"
exit 1
fi
}
enable_krnbt() {
echo "enabling krnbt to speed up boot and improve stability"
echo "dtparam=krnbt" >> /boot/config.txt
}
# Check if Raspberry Pi OS is active, otherwise kill script
if [ ! -f /etc/rpi-issue ]
then
echo "This script works only for Raspberry Pi OS"
exit 1;
fi
# Main Menu
while :
do
case "$1" in
-arb | --addrulebrightness)
add_brightness_udev_rule
exit 0
;;
-mem | --memorysplit)
if [ $# -ne 0 ]; then
set_memory_split $2
exit 0
fi
;;
-gl | --gldriver)
if [ $# -ne 0 ]; then
set_opengl $2
exit 0
fi
;;
-krn | --krnbt)
enable_krnbt
exit 0
;;
-h | --help)
display_help # Call your function
exit 0
;;
"") # If $1 is blank, run display_help
display_help
exit 0
;;
--) # End of all options
shift
break
;;
-*)
echo "Error: Unknown option: $1" >&2
## or call function display_help
exit 1
;;
*) # No more options
break
;;
esac
done