forked from snaptec/openWB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
openwb-install.sh
executable file
·217 lines (197 loc) · 5.4 KB
/
openwb-install.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
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
#!/bin/bash
echo "update system"
apt-get update
echo "check for vim"
if ! [ -x "$(command -v vim)" ]; then
apt-get -qq install -y vim
echo "... installed"
else
echo "...ok"
fi
echo "check for timezone"
if grep -Fxq "Europe/Berlin" /etc/timezone
then
echo "...ok"
else
echo 'Europe/Berlin' > /etc/timezone
dpkg-reconfigure -f noninteractive tzdata
cp /usr/share/zoneinfo/Europe/Berlin /etc/localtime
echo "...changed"
fi
echo "check for bc"
if ! [ -x "$(command -v bc)" ];then
apt-get -qq install bc
echo "...installed"
else
echo "...ok"
fi
echo "check for apache"
if ! [ -x "$(command -v apachectl)" ]; then
apt-get -qq install -y apache2
sleep 2
apt-get -qq install -y php
sleep 1
apt-get -qq install -y php-gd
sleep 1
#prepare for Buster
if [ -d "/etc/php/7.0/" ]; then
apt-get -qq install -y php7.0-xml
elif [ -d "/etc/php/7.3/" ]; then
apt-get -qq install -y php7.3-xml
fi
sleep 2
apt-get -qq install -y php-curl
sleep 1
#prepare for Buster
if [ -d "/etc/php/7.0/" ]; then
apt-get -qq install -y libapache2-mod-php7.0
elif [ -d "/etc/php/7.3/" ]; then
apt-get -qq install -y libapache2-mod-php7.3
fi
sleep 2
apt-get -qq install -y jq
sleep 2
apt-get -qq install -y raspberrypi-kernel-headers
echo "... installed"
else
echo "...ok"
fi
echo "check for i2c bus"
if grep -Fxq "i2c-bcm2835" /etc/modules
then
echo "...ok"
else
echo "i2c-dev" >> /etc/modules
echo "i2c-bcm2708" >> /etc/modules
echo "snd-bcm2835" >> /etc/modules
echo "dtparam=i2c1=on" >> /etc/modules
echo "dtparam=i2c_arm=on" >> /etc/modules
fi
echo "check for i2c package"
if ! [ -x "$(command -v i2cdetect)" ]; then
apt-get -qq install -y i2c-tools
echo "... installed"
else
echo "...ok"
fi
echo "check for git"
if ! [ -x "$(command -v git)" ]; then
apt-get -qq install -y git
echo "... installed"
else
echo "...ok"
fi
echo "check for initial git clone"
if [ ! -d /var/www/html/openWB/web ]; then
cd /var/www/html/
git clone https://github.com/snaptec/openWB.git --branch master
chown -R pi:pi openWB
echo "... git cloned"
else
echo "...ok"
fi
if ! grep -Fq "bootmodus=" /var/www/html/openWB/openwb.conf
then
echo "bootmodus=3" >> /var/www/html/openWB/openwb.conf
fi
echo "check for ramdisk"
if grep -Fxq "tmpfs /var/www/html/openWB/ramdisk tmpfs nodev,nosuid,size=32M 0 0" /etc/fstab
then
echo "...ok"
else
mkdir -p /var/www/html/openWB/ramdisk
echo "tmpfs /var/www/html/openWB/ramdisk tmpfs nodev,nosuid,size=32M 0 0" >> /etc/fstab
mount -a
echo "0" > /var/www/html/openWB/ramdisk/ladestatus
echo "0" > /var/www/html/openWB/ramdisk/llsoll
echo "0" > /var/www/html/openWB/ramdisk/soc
echo "...created"
fi
echo "check for crontab"
if grep -Fxq "@reboot /var/www/html/openWB/runs/atreboot.sh &" /var/spool/cron/crontabs/root
then
echo "...ok"
else
echo "@reboot /var/www/html/openWB/runs/atreboot.sh &" >> /tmp/tocrontab
crontab -l -u root | cat - /tmp/tocrontab | crontab -u root -
rm /tmp/tocrontab
echo "...added"
fi
#echo "check for MCP4725"
####### Library is deprecated. the manual install doesn't work anymore pip3 install for compatibility reasons
#if [ ! -d /home/pi/Adafruit_Python_MCP4725 ]; then
#apt-get install build-essential python-dev
#cd /home/pi
#git clone https://github.com/adafruit/Adafruit_Python_MCP4725.git
#cd Adafruit_Python_MCP4725
#python setup.py install
#echo "... installed"
#else
#echo "...ok"
#fi
echo "check for socat"
if ! [ -x "$(command -v socat)" ]; then
apt-get -qq install -y socat
echo "... installed"
else
echo "...ok"
fi
echo "disable cronjob logging"
if grep -Fxq "EXTRA_OPTS=\"-L 0\"" /etc/default/cron
then
echo "...ok"
else
echo "EXTRA_OPTS=\"-L 0\"" >> /etc/default/cron
fi
#prepare for Buster
echo -n "fix upload limit..."
if [ -d "/etc/php/7.0/" ]; then
echo "OS Stretch"
sudo /bin/su -c "echo 'upload_max_filesize = 300M' > /etc/php/7.0/apache2/conf.d/20-uploadlimit.ini"
sudo /bin/su -c "echo 'post_max_size = 300M' >> /etc/php/7.0/apache2/conf.d/20-uploadlimit.ini"
elif [ -d "/etc/php/7.3/" ]; then
echo "OS Buster"
sudo /bin/su -c "echo 'upload_max_filesize = 300M' > /etc/php/7.3/apache2/conf.d/20-uploadlimit.ini"
sudo /bin/su -c "echo 'post_max_size = 300M' >> /etc/php/7.3/apache2/conf.d/20-uploadlimit.ini"
fi
echo "checking for pip..."
if ! [ -x "$(command -v pip)" ]; then
sudo apt-get -qq install -y python-pip
echo "...OK"
else
echo "pip is installed"
fi
echo "checking for pip3..."
if ! [ -x "$(command -v pip3)" ]; then
sudo apt-get -qq install -y python3-pip
echo "...OK"
else
echo "pip3 is installed"
fi
echo "installing pymodbus"
sudo pip install -U pymodbus
echo "check for paho-mqtt"
if python3 -c "import paho.mqtt.publish as publish" &> /dev/null; then
echo 'mqtt installed...'
else
sudo pip3 install paho-mqtt
fi
#Adafruit install
echo "check for MCP4725"
#if python3 -c "import Adafruit_MCP4725" &> /dev/null; then
#echo 'Adafruit_MCP4725 installed...'
#else
#sudo pip3 install Adafruit_MCP4725
#fi
if python -c "import Adafruit_MCP4725" &> /dev/null; then
echo 'Adafruit_MCP4725 installed...'
else
sudo pip install Adafruit_MCP4725
fi
echo "www-data ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/010_pi-nopasswd
chmod 777 /var/www/html/openWB/openwb.conf
chmod +x /var/www/html/openWB/modules/*
chmod +x /var/www/html/openWB/runs/*
touch /var/log/openWB.log
chmod 777 /var/log/openWB.log
/var/www/html/openWB/runs/atreboot.sh