-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup
executable file
·179 lines (161 loc) · 6.37 KB
/
setup
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
#!/bin/bash
# adds display and backlight settings
# run manually initally, then called from reinstallMods
# to uninstall/deactivate, call this script with "uninstall" as first parameter
# Note, this script DOES require a system reboot.
overlayFile="/u-boot/overlays/gpio-led.dtbo"
configFile="/u-boot/config.txt"
headlessFlag=/etc/venus/headless
blankDeviceFile=/etc/venus/blank_display_device
#### following lines incorporate SetupHelper utilities into this script
# Refer to the SetupHelper ReadMe file for details.
source "/data/SetupHelper/CommonResources"
#### end of lines to include SetupHelper
####### this is duplicate to code in CommonResources -- keep in case SetupHelepr has not been updated
# prevent installing if not a Raspberry Pi
if [ -f /etc/venus/machine ]; then
machine=$(cat /etc/venus/machine)
fi
if [ -z $machine ]; then
if [ -f "$installedFlag" ]; then
logMessage "can't determine Venus device type - uninstalling"
scriptAction='UNINSTALL'
else
logMessage "can't determine Venus device type - exiting"
exit $INCOMPATIBLE_PLATFORM
fi
elif [ $machine != "raspberrypi2" ] && [ $machine != "raspberrypi4" ]; then
if [ -f "$installedFlag" ]; then
logMessage "$packageName not compatible with $machine - uninstalling"
scriptAction='UNINSTALL'
else
logMessage "$packageName not compatible with $machine - exiting"
exit $INCOMPATIBLE_PLATFORM
fi
fi
#### running manually and OK to proceed - prompt for input
if [ $scriptAction == 'NONE' ] ; then
# display innitial message
echo
echo "This package makes the following modifications:"
echo " - installs the overlay file for the GPIO LED (used for backlight)"
echo " - adds the display setup and backlight overlay to config.txt"
echo
yesNoPrompt "Do you want to continue (y/n)?: "
if $yesResponse ; then
scriptAction='INSTALL'
yesNoPrompt "Rotate the display 180 degrees (y/n)?: "
if $yesResponse ; then
touch "$setupOptionsDir/rotateDisplay"
else
rm -f "$setupOptionsDir/rotateDisplay"
fi
yesNoPrompt "Enter custom GPIO pin for backlight (default: 23) (y/n)?: "
if $yesResponse ; then
read -p "enter GPIO pin to use: " gpioPin
if [ "$gpioPin" != "" ]; then
echo $gpioPin > "$setupOptionsDir/backlight_gpio_pin"
else
rm -f "$setupOptionsDir/backlight_gpio_pin"
fi
else
rm -f "$setupOptionsDir/backlight_gpio_pin"
fi
fi
fi
#### installing
if [ $scriptAction == 'INSTALL' ] ; then
display_rotate=0
if [ -f $setupOptionsDir/rotateDisplay ]; then
display_rotate=2
fi
gpioPin=23
if [ -f $setupOptionsDir/backlight_gpio_pin ]; then
gpioPin=$(cat "$setupOptionsDir/backlight_gpio_pin")
fi
# install overlay only if it doesn't exist
[ -f "$overlayFile" ] || logMessage "installing Display Backlight overlay" && rebootNeeded=true && updateActiveFile "$overlayFile"
logMessage "activating VeTouchDisplay settings in $configFile"
cp $configFile $configFile.tmp
# remove any previouos lines added by this script
sed -i -e "/#### begin VeTouchDisplay/,/#### end VeTouchDisplay/d" "$configFile.tmp"
echo "" >> "$configFile.tmp"
echo "#### begin VeTouchDisplay" >> "$configFile.tmp"
echo "# Elecrow RC050 5 inch HDMI 800 x 480 Capacitive Touch LCD Display for Raspberry Pi/ PC/ SONY PS4" >> "$configFile.tmp"
echo "# https://www.elecrow.com/wiki/index.php?title=RC050_5_inch_HDMI_800_x_480_Capacitive_Touch_LCD_Display_for_Raspberry_Pi/_PC/_SONY_PS4" >> "$configFile.tmp"
echo "hdmi_force_hotplug=1" >> "$configFile.tmp"
echo "max_usb_current=1" >> "$configFile.tmp"
echo "hdmi_drive=1" >> "$configFile.tmp"
echo "hdmi_group=2" >> "$configFile.tmp"
echo "hdmi_mode=1" >> "$configFile.tmp"
echo "hdmi_mode=87" >> "$configFile.tmp"
echo "hdmi_cvt=800 480 60 6 0 0 0" >> "$configFile.tmp"
echo "display_rotate=$display_rotate" >> "$configFile.tmp"
echo "framebuffer_width=800" >> "$configFile.tmp"
echo "framebuffer_height=480" >> "$configFile.tmp"
echo "# for backlight on / off" >> "$configFile.tmp"
echo "# gpio-led overlay allows to invert the backlight (echo 0 for on and 1 for off, like backlight blanking)" >> "$configFile.tmp"
echo "dtoverlay=gpio-led,gpio=$gpioPin,label=backlight,active_low=1" >> "$configFile.tmp"
# comment dtoverlay=vc4-kms-v3c for raspberrypi4 if active
if [ $machine == "raspberrypi4" ]; then
if [ $(grep -c "^\s*dtoverlay=vc4-kms-v3c" "$configFile") != 0 ]; then
logMessage "disabling dtoverlay=vc4-kms-v3c on Raspberry Pi 4"
sed -i 's/^\s*dtoverlay=vc4-kms-v3c/#dtoverlay=vc4-kms-v3c/g' "$configFile.tmp"
rebootNeeded=true
fi
fi
echo "#### end VeTouchDisplay" >> "$configFile.tmp"
echo "" >> "$configFile.tmp"
# detect changes
cmp -s $configFile "$configFile.tmp" > /dev/null
if (( $? == 1 )); then
logMessage "updating config.txt"
updateActiveFile "$configFile.tmp" "$configFile"
if $thisFileUpdated ; then
rebootNeeded=true
fi
else
rm $configFile.tmp
fi
# enable screen saver (blanking) from the Venus
if [ "$gpioPin" != "" ]; then
if [ ! -e "$blankDeviceFile" ] || [ $(grep -c "/sys/class/leds/backlight/brightness" "$blankDeviceFile") == 0 ]; then
logMessage "setting display blanking to GPIO pin $gpioPin"
echo "/sys/class/leds/backlight/brightness" > "$blankDeviceFile"
restartGui=true
fi
fi
if [ -e $headlessFlag ]; then
logMessage "activating local GUI"
rm -f $headlessFlag
rebootNeeded=true
fi
fi
# uninstalling - check scriptAction again
# if an install step failed package needs to be removed
if [ $scriptAction == 'UNINSTALL' ] ; then
logMessage "++ Uninstalling display setup"
if [ -e "$blankDeviceFile" ]; then
logMessage "disabling display blanking"
rm -f "$blankDeviceFile"
restartGui=true
fi
if [ ! -f "/etc/venus/headless" ]; then
echo
logMessage "DISABLING LOCAL GUI - reverts to console"
echo
touch "/etc/venus/headless"
rebootNeeded=true
fi
logMessage "restoring previous overlay file"
restoreActiveFile "$overlayFile"
# remove mods from configFile - do not use restore in case other mods were made manually
if [ -f "$configFile" ]; then
if [ $(grep -c "#### begin VeTouchDisplay" "$configFile") != 0 ]; then
sed -i -e '/#### begin VeTouchDisplay/,/#### end VeTouchDisplay/d' "$configFile"
rebootNeeded=true
fi
fi
fi
# thats all folks - SCRIPT EXITS INSIDE THE FUNCTION
endScript