-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup
More file actions
executable file
·124 lines (106 loc) · 4.08 KB
/
setup
File metadata and controls
executable file
·124 lines (106 loc) · 4.08 KB
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
#!/bin/bash
# setup Rasperry Pi Temprature measurement and fan control
# This modification adds the raspberry pi temperature to Victron Venus OS
# and allows a PWM fan control
packageLogFile="/var/log/VeFanControl/current"
overlayFile="/u-boot/overlays/pwm.dtbo"
configFile="/u-boot/config.txt"
#### following lines incorporate SetupHelper utilities into this script
# Refer to the SetupHelper ReadMe file for details.
source "/data/SetupHelper/HelperResources/IncludeHelpers"
#### end of lines to include SetupHelper
#### running manually and OK to proceed - prompt for input
if [ $scriptAction == 'NONE' ] ; then
echo
echo "The VeFanControl adds Rasperry Pi CPU Temperture bases PWM fan control"
echo
echo " - installs the overlay file for the PWM pin"
echo " - adds the PWM setup to config.txt"
echo
yesNoPrompt "Do you want to continue (y/n)?: "
if $yesResponse ; then
scriptAction='INSTALL'
eval `python3 read_config.py`
yesNoPrompt "Change GPIO pin for PWM (default: $pwm_pin) (y/n)?: "
if $yesResponse ; then
read -p "enter GPIO pin to use for PWM: " gpioPin
if [ "$gpioPin" != "" ]; then
# check it
python3 write_pwm_pin.py $gpioPin
if [ "$?" -ne 0 ]; then
scriptAction=''
echo "Invalid pin $gpioPin given!"
else
echo "Using PWM pin $gpioPin"
fi
else
scriptAction=''
echo "No pin given!"
fi
fi
fi
fi
#### here to do the actual work
if [ $scriptAction == 'INSTALL' ] ; then
# read config entries to get the pwm pin
pushd $scriptDir && eval `python3 read_config.py` && popd
logMessage "++ Installing VeFanControl with the following settings:\n pwm_pin=$pwm_pin pwm_freq=$pwm_freq wait_time=$wait_time\n off_temp=$off_temp min_temp=$min_temp max_temp=$max_temp\n off_pwm=$off_pwm min_pwm=$min_pwm max_pwm=$max_pwm\n pwm_chan=$pwm_chan pin_func=$pin_func"
logMessage "activating VeFanControl settings in $configFile"
overlayTemplate="/tmp/overlay"
cat >$overlayTemplate <<EOF
#### begin VeFanControl
dtoverlay=pwm,pin=$pwm_pin,func=$pin_func
#### end VeFanControl
EOF
if (( $(grep -c "#### begin VeFanControl" "$configFile") != 0 )); then
removeOverlay=true
oldOverlayText=$(sed -n -e "/#### begin VeFanControl/,/#### end VeFanControl/p" "$configFile" | grep dtoverlay)
else
oldOverlayText=""
removeOverlay=false
fi
if [ -f "$overlayTemplate" ]; then
installOverlay=true
newOverlayText=$(grep dtoverlay "$overlayTemplate")
else
installOverlay=false
newOverlayText=""
fi
# logMessage "oldOverlayText: $oldOverlayText"
# logMessage "newOverlayText: $newOverlayText"
# correct overlay already installed - don't make changes
if $removeOverlay && $installOverlay && [ "$oldOverlayText" == "$newOverlayText" ]; then
removeOverlay=false
installOverlay=false
fi
if $removeOverlay ; then
logMessage "removing old overlay from config.txt"
sed -i -e "/#### begin VeFanControl/,/#### end VeFanControl/d" "$configFile"
rebootNeeded=true
fi
if $installOverlay ; then
logMessage "adding new overlay to config.txt"
cat "$overlayTemplate" >> $configFile
rebootNeeded=true
fi
[ -f "$overlayFile" ] || logMessage "installing PWM overlay" && rebootNeeded=true && updateActiveFile "$overlayFile"
installService $packageName
fi
# #### uninstalling - check scriptAction again
# if an install step failed package needs to be removed
if [ $scriptAction == 'UNINSTALL' ] ; then
logMessage "++ Uninstalling VeFanControl"
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 VeFanControl" "$configFile") != 0 ]; then
logMessage "removing VeFanControl settings from config.txt"
sed -i -e '/#### begin VeFanControl/,/#### end VeFanControl/d' "$configFile"
rebootNeeded=true
fi
fi
removeService $packageName
fi
# thats all folks - SCRIPT EXITS INSIDE THE FUNCTION
endScript