-
Notifications
You must be signed in to change notification settings - Fork 6
/
setup
executable file
·168 lines (146 loc) · 6.3 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
#!/bin/bash
# adds additional digital inputs and relay outputs to the Raspberry Pi platforms
# the stock RPI Venus distribution includes two relays and two digital inputs
# adding the additional GPIO pins to /etc/venus/gpio_list
# makes additional digital inputs available
# all 5 defined digital inputs are activated by this script
#
# the Raspberry PI default is for the first 8 GPIO pins to have pull UPs
# and the remaining have pull DOWNs. This makes some digital input pins behave differently
# this script also installs a DT overlay that switches to pull UPs for all digital input pins
#
# Only the first relay can be assigned to a function: alarm, genertor start/stop or pump.
# Others are only provided manual on/off control from the menu.
# Six relays are supported. Only the first relay can be assigned to functions
# The remaining relays are manual on/off only.
# run manually initally, then called from reinstallMods
# to uninstall/deactivate, call this script with "uninstall" as first parameter
# original assignments for relays 5 and 6 create conflicts with interrypt pins
# on hat boards such as the Waveshare dual CANbus hats (regular and FD versions)
# An option in this setup script allows selection of different GPIO assignments
# for relays 5 and 6 to avoid these conflicts
#
# Because this conflict will be rare, the option is considered optional.
# That is, an automatic install WILL be permitted even if a manual install has not
# been perfomred.
#
# VeCanSetup will alert the user of conflicts and prevent installing the second
# CANbus interface until this script is rerun to move the relay assignments.
# Note, this script DOES require a system reboot.
gpioListFile="/etc/venus/gpio_list"
configFile="/u-boot/config.txt"
# no log file for this package
packageLogFile=""
#### following line incorporates helper resources into this script
source "/data/SetupHelper/HelperResources/IncludeHelpers"
#### end of lines to include helper resources
####### 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 " Activates 6 relay outputs"
echo " Activates 5 digital inputs"
echo " Changes all digital inputs to have pull-ups in stead of a mix of pull up/down"
standardActionPrompt 'MORE_PROMPTS'
if [ $scriptAction == 'NONE' ]; then
echo
echo "Legacy assignment for relays 5 and 6 may conflict with interrupts for some CANbus interface hat boards"
echo "Conflicts WILL render the Raspberry PI at least partially unresponsive"
echo "To avoid conflicts, an alternate set of GPIO assignments is available"
useCustomGpioFile=false
if [ -f "$setupOptionsDir/gpio_list" ]; then
yesNoPrompt "A custom gpio_list file exists - use it (y/n)?: "
if $yesResponse ; then
echo "CAUTION: manually check custom gpio_list and GPIO overlay for conflicts"
useCustomGpioFile=true
else
rm "$setupOptionsDir/gpio_list"
fi
fi
if ! $useCustomGpioFile ; then
echo
yesNoPrompt "Do you wish to install the alternate set of GPIO assignments (y/n)?: "
if $yesResponse ; then
touch "$setupOptionsDir/alternateGpio"
else
rm -f "$setupOptionsDir/alternateGpio"
fi
fi
scriptAction='INSTALL'
fi
fi
#### installing
if [ $scriptAction == 'INSTALL' ] ; then
# use custom GPIO list if present
if [ -f "$setupOptionsDir/gpio_list" ]; then
logMessage "installing CUSTOM gpio_list"
updateActiveFile "$setupOptionsDir/gpio_list" "$gpioListFile"
# use a alternate gpio list if option is set
elif [ -f "$setupOptionsDir/alternateGpio" ]; then
logMessage "installing ALTERNATE gpio_list"
updateActiveFile "$pkgFileSets/gpio_listForCanHats" "$gpioListFile"
# otherwise use a legacy gpio list
else
logMessage "installing LEGACY gpio_list"
updateActiveFile "$gpioListFile"
fi
# install / update GPIO overlay
# there are two overlays, make sure the "other" one is removed from config.txt
if [ -f "$setupOptionsDir/alternateGpio" ]; then
gpioOverlay="VenusGpioOverlayForCanHats"
if [ $(grep -c "VenusGpioOverlay" "$configFile") == 0 ]; then
sed -i -e '/#### change all digital inputs to pull ups/,/#### end change all digital inputs to pull ups/d' "$configFile"
fi
else
gpioOverlay="VenusGpioOverlay"
if [ $(grep -c "VenusGpioOverlayForCanHats" "$configFile") > 0 ]; then
sed -i -e '/#### change all digital inputs to pull ups/,/#### end change all digital inputs to pull ups/d' "$configFile"
fi
fi
if [ $(grep -c "#### change all digital inputs to pull ups" "$configFile") == 0 ]; then
logMessage "activating $gpioOverlay"
echo "#### change all digital inputs to pull ups" >> "$configFile"
echo "dtoverlay=$gpioOverlay" >> "$configFile"
echo "#### end change all digital inputs to pull ups" >> "$configFile"
filesUpdated=true
fi
fi
# uninstalling - check scriptAction again
# if an install step failed package needs to be removed
if [ $scriptAction == 'UNINSTALL' ] ; then
# remove mods from configFile - do not use restore in case other mods were made manually
if [ -f "$configFile" ]; then
if [ $(grep -c "#### change all digital inputs to pull ups" "$configFile") != 0 ]; then
sed -i -e '/#### change all digital inputs to pull ups/,/#### end change all digital inputs to pull ups/d' "$configFile"
filesUpdated=true
fi
fi
fi
if $filesUpdated ; then
rebootNeeded=true
fi
# thats all folks - SCRIPT EXITS INSIDE THE FUNCTION
endScript 'INSTALL_FILES'