-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsetup
executable file
·577 lines (537 loc) · 19.4 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
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
#!/bin/bash
# setup for Raspberry PI 7" touchscreen display
# also supports HDMI display on HDMI 0
# Much is already installed and set up for this display
# the touch screen calibration included in the image appears to work fine
# even if the display is rotated 180 degrees
# what remains is the screensaver (blanking) and brightness control from Venus GUI
# and activating a local GUI
#
# Do NOT install this package if you do not want a local display (run Venus "headless")
#
# for HDMI displays, no brightness control is possible, only screensaver
# and some displays may not turn off the backlight when blanked, but a black screen will be displayed
#
# run manually initally, then called from reinstallMods after a Venus update
# to uninstall/deactivate, call this script with "uninstall" as first parameter
#
# /u-boot/config.txt modified to remove references to "framebuffer" which isn't needed, even for the RPI display
# and to insure overscan is not active
# and and hdmi_blanking is enabled so RPI display will power down during screen saver
# Note: the display will take longer to come out of screen saver if powered down
# but if this is not done, the display backlight will remain on and be visible as a glow
#
# add HDMI configuration to /u-boot/config.txt
# You may need to make additional changes/additions manaually to support the display in use
#
# Note, this script may reboot the system to comlete all operations
# Dimming the RPI display requires the rpi-backlight overlay
# A reboot is required to activate the overlay and the config.txt changes
headlessFlag=/etc/venus/headless
restartGui=false
overlayFile="/u-boot/overlays/rpi-backlight.dtbo"
configFile="/u-boot/config.txt"
blankDeviceFile=/etc/venus/blank_display_device
dimDeviceFile=/etc/venus/backlight_device
# no log file for this package
packageLogFile=""
doTsCalibrate=false
deferTsCalibrate=false
runTsCalibrateNow=false
#### following line incorporates helper resources into this script
source "/data/SetupHelper/HelperResources/IncludeHelpers"
#### end of lines to include helper resources
# note: the headless flag is no longer used starting with v3.60 betas
versionStringToNumber "v3.60~3"
if (( $venusVersionNumber >= $versionNumber )); then
logMessage "using new GUI control procedures (headless flag no longer used)"
useNewGuiProcedures=true
else
useNewGuiProcedures=false
fi
#### running manually and OK to proceed - prompt for input
if [ $scriptAction == 'NONE' ] ; then
# display innitial message
echo
echo "This package sets up the Raspberry PI for the offical RPI touchscreen"
echo " and for some other DSI or HDMI displays"
echo "Some hand editing of config.txt may be needed for an HDMI display"
echo
echo "The screen saver will switch to a black screen"
echo " with the backlight still on for HDMI displays that do not support standby"
echo "Display brighness controll is enabled only for the RPI touchscreen"
echo
if ! $useNewGuiProcedures ; then
echo "Uninstalling disables the local display (sets headless)"
fi
standardActionPrompt 'MORE_PROMPTS'
# PROMPT is left over from a previous version of SetupHelper
# it is included here for backward compatibility
if [ $scriptAction == 'NONE' ] || [ $scriptAction == 'PROMPT' ]; then
echo
echo "This script supports the following displays:"
echo " (R) Raspberry PI touchscreen - may also work with other DSI displays"
echo " (H) HDMI display connected to port 0 (closest to power connector)"
echo " (C) skip display configuration and run touch screen calibration only"
echo
customControl=false
rpiConfig=false
hdmiConfig=false
while true ; do
read -p "Choose a display from the list above (R / H / C): " display
case $display in
[rR]*)
echo "RPI" > $setupOptionsDir/displayToControl
rpiConfig=true
break
;;
[hH]*)
echo "HDMI" > $setupOptionsDir/displayToControl
hdmiConfig=true
break
;;
[cC]*)
doTsCalibrate=true
break
;;
esac
done
if $hdmiConfig ; then
echo
echo "HDMI displays require configuration lines to be added to /u-boot/config.txt"
echo " and may also require toush screen calibraiton"
echo
echo "HDMI mode"
echo " some displays will automatically configure (A)"
echo " some will conform to predefined settings (P)"
echo " others will require custom configuration settings (C)"
echo
hdmiGroup="-"
hdmiMode="-"
horizontalResolution="-"
verticalResolution="-"
refreshRate="-"
while true ; do
read -p "Select the HDMI mode from the above list (A / P / C): " response
case $response in
[aA]*)
hdmiGroup=0
break
;;
[pP]*)
echo
echo "for group and mode numbers refer to"
echo " https://www.raspberrypi.com/documentation/computers/config_txt.html#hdmi-mode"
while true ; do
read -p "Enter the HDMI group number (1 = CEA, 2 = DMT): " response
case $response in
1 | [cC]*)
hdmiGroup=1
maxMode=107
groupText="CEA"
break
;;
2 | [dD]*)
hdmiGroup=2
maxMode=86
groupText="DMT"
break
;;
*)
echo "invalid group $response"
;;
esac
done
while true ; do
read -p "Enter the $groupText mode number (1 - $maxMode) : " hdmiMode
if [ ! -z $hdmiMode ] && (( $hdmiMode > 0 )) && (( $hdmiMode <= $maxMode )); then
break
else
echo "invalid mode $hdmiMode"
fi
done
break
;;
[cC]*)
hdmiGroup=2
hdmiMode=87
while true ; do
read -p "Enter the horizontal resolution of the display: " horizontalResolution
if [ ! -z $horizontalResolution ] && (( $horizontalResolution > 0 )) && (( $horizontalResolution < 9999 )); then
break
else
echo "invalid H value $horizontalResolution"
fi
done
while true ; do
read -p "Enter the vertical resolution of the display: " verticalResolution
if [ ! -z $verticalResolution ] && (( $verticalResolution > 0 )) && (( $verticalResolution < 9999 )); then
break
else
echo "invalid V value $verticalResolution"
fi
done
read -p "Enter the display refresh rate (cr for 60): " refreshRate
if [ -z $refreshRate ]; then
refreshRate=60
fi
echo "display aspect:"
echo " 1 4:3"
echo " 2 14:9"
echo " 3 16:9"
echo " 4 5:4"
echo " 5 16:10"
echo " 6 15:9"
while true ; do
read -p "Enter the display aspect ratio from the list above: " aspect
if [ ! -z $aspect ] && (( $aspect >= 1 )) && (( $aspect <= 6 )); then
break
else
echo "invalid aspect $aspect"
fi
done
break
;;
esac
done
echo "$hdmiGroup $hdmiMode $horizontalResolution $verticalResolution $refreshRate $aspect" > "$setupOptionsDir/displayRates"
fi # end if $hdmiConfig
if $rpiConfig || $hdmiConfig ; then
if yesNoPrompt "Rotate the display 180 degrees (y/n)?: " ; then
touch "$setupOptionsDir/rotateDisplay"
if $hdmiConfig ; then
touch "$setupOptionsDir/rotateDisplay"
rm -f "$setupOptionsDir/altRotateDisplay"
else
echo "displays may respond to one of two rotate commands"
echo "lcd_rotate rotates most DSI displays and also rotates the touch calibration"
echo "if the display does not rotate run setup again and choose the alternate command here"
if yesNoPrompt "choose the alternate rotate command (display_lcd_rotate) (y/n)?: " ; then
touch "$setupOptionsDir/altRotateDisplay"
rm -f "$setupOptionsDir/rotateDisplay"
echo "the alternate rotate command does not rotate the touch screen"
echo "you must run the touch screen calibration"
else
touch "$setupOptionsDir/rotateDisplay"
rm -f "$setupOptionsDir/altRotateDisplay"
fi
fi
else
rm -f "$setupOptionsDir/rotateDisplay"
rm -f "$setupOptionsDir/altRotateDisplay"
fi
if yesNoPrompt "Enter custom blanking and dimming devices (y/n)?: " ; then
read -p "enter blanking device (/sys/class/...): " blankDevice
if [ "$blankDevice" != "" ]; then
echo $blankDevice > "$setupOptionsDir/blank_display_device"
else
rm -f "$setupOptionsDir/blank_display_device"
fi
read -p "enter dimming device (/sys/class/...): " dimDevice
if [ "$dimDevice" != "" ]; then
echo $dimDevice > "$setupOptionsDir/backlight_device"
else
rm -f "$setupOptionsDir/backlight_device"
fi
else
rm -f "$setupOptionsDir/blank_display_device"
rm -f "$setupOptionsDir/backlight_device"
fi
echo
echo "Touch screen calibration requires the ts_calibtate utility from tsLib"
echo " and temporariliy turning off the local GUI. System must reboot twice"
if [ "$displayToControl" == "RPI" ]; then
echo "RPI display touch screen calibration is optional"
echo "But other DSI displays may require it"
fi
echo
if yesNoPrompt "Do you want to calibrate the touch screen (y/n)?: " ; then
doTsCalibrate=true
fi
scriptAction='INSTALL'
fi # end if ! $rpiConfig || $hdmiConfig
if $doTsCalibrate ; then
tsCalib=$(which ts_calibrate)
if [ -z $tsCalib ]; then
echo
echo "ts_calibrate was not found. Installation requries an internet connection"
if yesNoPrompt "Download and install it now (y/n)?: " ; then
logMessage "installing ts_calibrate"
opkg update
opkg install tslib-calibrate
fi
fi
tsCalib=$(which ts_calibrate)
if [ -z $tsCalib ]; then
logMessage "ts_calibrate was not found - can't run calibration"
logMessage "installation will continue WITHOUT calibration !"
doTsCalibrate=false
fi
fi
fi
fi
#### installing
if [ $scriptAction == 'INSTALL' ]; then
# the overlay is needed to automatically discover display type
if [ ! -f "$overlayFile" ]; then
logMessage "installing RPI Display Backlight overlay"
cp "$scriptDir/rpi-backlight-overlay.dtb" "$overlayFile"
rebootNeeded=true
waitForOverlay=true
else
waitForOverlay=false
fi
# get selected display from NV storage
if [ -f $setupOptionsDir/displayToControl ]; then
displayToControl=$(cat "$setupOptionsDir/displayToControl")
# options not yet set - use auto-discovery
else
if $waitForOverlay ; then
logMessage "install options have not been set - installng overlay and rebooting for auto discovery"
runAgain=true
rebootNeeded=true
# stop setup now and come back later to finish
endScript
# with overlay in place auto-discover display type
else
if [ -e /sys/class/backlight/rpi_backlight ]; then
logMessage "auto-discovered display type RPI"
displayToControl='RPI'
else
logMessage "RPI display not detected - HDMI requires manual configuration !!!"
displayToControl=""
fi
echo $displayToControl > "$setupOptionsDir/displayToControl"
fi
fi
if [ -z "$displayToControl" ]; then
logMessage "++ ERROR: no display specified - can't continue - run install from command line"
exit $EXIT_OPTIONS_NOT_SET
fi
case $displayToControl in
RPI)
blankDevice="/sys/class/backlight/rpi_backlight/bl_power"
dimDevice="/sys/class/backlight/rpi_backlight"
;;
HDMI)
blankDevice="/sys/class/graphics/fb0/blank"
dimDevice=""
;;
default)
blankDevice=""
dimDevice=""
;;
esac
logMessage "++ Installing display config to /u-boot/config.txt for display: $displayToControl"
# remove lines with framebuffer - not needed even with RPI display
sed -e '/framebuffer/d;' -e '/rotate/d' "$configFile" | awk '!NF || !seen[$0]++' > "$configFile.tmp"
# remove any previouos lines added by this script
sed -i -e "/#### RpiDisplaySetup begin/,/#### RpiDisplaySetup end/d" "$configFile.tmp"
# add lines for this display
echo "#### RpiDisplaySetup begin" >> "$configFile.tmp"
echo "disable_overscan=1" >> "$configFile.tmp"
if [ "$displayToControl" == "RPI" ]; then
if [ -f "$setupOptionsDir/rotateDisplay" ]; then
echo "lcd_rotate=2" >> "$configFile.tmp"
elif [ -f "$setupOptionsDir/altRotateDisplay" ]; then
echo "display_lcd_rotate=2" >> "$configFile.tmp"
fi
# HDMI display
else
read group mode horiz vert freq aspect <<< $(cat "$setupOptionsDir/displayRates")
echo "# allow HDMI display to enter low powr mode" >> "$configFile.tmp"
echo "hdmi_blanking=1" >> "$configFile.tmp"
echo "hdmi_force_hotplug=1" >> "$configFile.tmp"
echo "hdmi_group=$group" >> "$configFile.tmp"
######## echo "ignore_lcd=1" >> "$configFile.tmp"
if (( $group != 0 )); then
echo "hdmi_mode=$mode" >> "$configFile.tmp"
if (( $mode == 87 )); then
echo "hdmi_cvt=$horiz $vert $freq $aspect 0 0 0" >> "$configFile.tmp"
fi
fi
if [ -f "$setupOptionsDir/rotateDisplay" ]; then
echo "display_hdmi_rotate=2" >> "$configFile.tmp"
fi
fi
echo "#### RpiDisplaySetup end" >> "$configFile.tmp"
# detect changes
cmp -s $configFile "$configFile.tmp" > /dev/null
if (( $? == 1 )); then
logMessage "updating config.txt"
mv -f "$configFile.tmp" "$configFile"
rebootNeeded=true
else
rm -f $configFile.tmp
fi
# use custom blank device file if provided
if [ -f "$setupOptionsDir/blank_display_device" ]; then
blankDevice=$(cat "$setupOptionsDir/blank_display_device")
logMessage "using custom blank_display_device file: $blankDevice"
fi
# enable screen saver (blanking) from the Venus
if [ "$blankDevice" != "" ]; then
if [ ! -e "$blankDeviceFile" ] || [ $(grep -c $blankDevice "$blankDeviceFile") == 0 ]; then
logMessage "setting display blanking to $blankDevice"
echo $blankDevice > "$blankDeviceFile"
restartGui=true
fi
elif [ -e "$blankDeviceFile" ]; then
logMessage "disabling display blanking"
rm -f "$blankDeviceFile"
restartGui=true
fi
# use custom dimming file if provided
if [ -f "$setupOptionsDir/backlight_device" ]; then
dimDevice=$(cat "$setupOptionsDir/backlight_device")
logMessage "using custom backlight_device file: $dimDevice"
fi
#enable display dimming if device is specified
if [ "$dimDevice" != "" ]; then
if [ ! -e $dimDeviceFile ] || [ $(grep -c $dimDevice "$dimDeviceFile") == 0 ]; then
logMessage "setting up brightness control: $dimDevice"
echo $dimDevice > $dimDeviceFile
restartGui=true
fi
# setup other paremeters for dimming
logMessage "disabling AutoBrightness"
dbus -y com.victronenergy.settings /Settings/Gui/AutoBrightness SetValue 0 > /dev/null
if [ ! -e $dimDeviceFile ] || [ $(grep -c $dimDevice "$dimDeviceFile") == 0 ]; then
logMessage "setting up brightness control to $dimDevice"
echo $dimDevice > "$dimDeviceFile"
restartGui=true
fi
# disable display brightness
elif [ -e "$dimDeviceFile" ]; then
logMessage "disabling display brightness"
rm -f "$dimDeviceFile"
restartGui=true
fi
fi #end if [ $scriptAction == 'INSTALL' ]
if $doTsCalibrate ; then
# defer calibrate until next pass
if ! $useNewGuiProcedures || $rebootNeeded ; then
echo
logMessage "system will reboot for calibration - please wait for targets to appear"
touch "$setupOptionsDir/calibrate"
# prevent PackageManager from running setup - until calibrate has finished
if [ -f "$setupOptionsDir/DO_NOT_AUTO_INSTALL" ]; then
rm -f "$setupOptionsDir/DO_NOT_AUTO_INSTALL"
touch "$setupOptionsDir/RESTORE_DO_NOT_AUTO_INSTALL"
fi
# allow script to finish without additional prompts and run again after reboot
# force an install to allow endScript to reboot the system
scriptAction='INSTALL'
rebootNeeded=true
runAgain=true
userInteraction=false
if ! $useNewGuiProcedures ; then
touch $headlessFlag
fi
doTsCalibrate=false
fi
# if calibrate was deferred, do it now
elif [ -f "$setupOptionsDir/calibrate" ]; then
doTsCalibrate=true
fi
# run ts_calibrate and restore local GUI
if $doTsCalibrate ; then
# shut down the GUI before running calabration
restartGuiService=false
restartStartGuiService=false
if [ $( svstat "/service/gui" |awk '{print $2'} ) == "up" ]; then
logMessage "stopping gui service"
svc -d "/service/gui"
sleep 1
restartGuiService=true
fi
if [ $( svstat "/service/start-gui" |awk '{print $2'} ) == "up" ]; then
logMessage "stopping start-gui service"
svc -d "/service/start-gui"
sleep 1
restartStartGuiService=true
fi
# ts_calibrate modifies /etc/pointercal internally
# make backup original first for uninstall
backupActiveFile "/etc/pointercal"
logMessage "running touchscreen calibration"
ts_calibrate
# save calibration for reinstall after Venus OS update
cp "/etc/pointercal" "$setupOptionsDir"
# new GUI can be restarted without rebooting - just restart the service
if $useNewGuiProcedures ; then
if $restartGuiService ; then
logMessage "starting gui service"
svc -u "/service/gui"
fi
if $restartStartGuiService ; then
logMessage "starting start-gui service"
svc -u "/service/start-gui"
fi
if [ $scriptAction == 'NONE' ]; then
scriptAction='EXIT'
fi
else
rebootNeeded=true
runAgain=true
fi
rm -f "$setupOptionsDir/calibrate"
# restore do not auto install flag
if [ -f "$setupOptionsDir/RESTORE_DO_NOT_AUTO_INSTALL" ]; then
touch "$setupOptionsDir/DO_NOT_AUTO_INSTALL"
rm -f "$setupOptionsDir/RESTORE_DO_NOT_AUTO_INSTALL"
else
rm -f "$setupOptionsDir/DO_NOT_AUTO_INSTALL"
fi
# restore pointercal from last calibrate pass if any
else
if [ -f "$setupOptionsDir/pointercal" ]; then
updateActiveFile "$setupOptionsDir/pointercal" "/etc/pointercal"
fi
fi
# remove the headless flag to allow a local display
if ! $useNewGuiProcedures && [ $scriptAction == 'INSTALL' ] && [ -e $headlessFlag ] && [ ! -f "$setupOptionsDir/calibrate" ]; then
logMessage "activating local GUI"
rm -f $headlessFlag
rebootNeeded=true
fi
#### uninstalling - check scriptAction again
# if an install step failed package needs to be removed
if [ $scriptAction == 'UNINSTALL' ] ; then
logMessage "++ Uninstalling RPI display enhancements"
if [ -e "$blankDeviceFile" ]; then
logMessage "disabling display blanking"
rm -f "$blankDeviceFile"
restartGui=true
fi
if [ -e $dimDeviceFile ]; then
logMessage "disabling display backlight control"
restoreActiveFile "$guiStartFile"
rm -f "$dimDeviceFile"
restartGui=true
fi
# normally, we'd reboot after removing the overlay file
# but the overlay shouldn't have any affect on system behavior
# so waiting until the next reboot cycle should be fine
if [ -f "$overlayFile" ]; then
logMessage "removing $overlayFile"
rm -f "$overlayFile"
fi
if [ -f "/u-boot/config.txt.orig" ] ; then
sed -i -e "/#### rotate display 180 degrees/,/#### end rotate/d" "$configFile"
logMessage "/u-boot/config.txt NOT fully restored - manual restore may be needed"
logMessage "/u-boot.config.txt.orig may help with restore"
rebootNeeded=true
fi
if ! $useNewGuiProcedures && [ ! -f "/etc/venus/headless" ]; then
echo
logMessage "DISABLING LOCAL GUI - reverts to console"
echo
touch "/etc/venus/headless"
rebootNeeded=true
fi
logMessage "restoring previous touch screen calibration"
restoreActiveFile "/etc/pointercal"
fi
#thats all folks - SCRIPT EXITS INSIDE THE FUNCTION
endScript