forked from snaptec/openWB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
openwb-install.sh
executable file
·158 lines (140 loc) · 3.59 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
#/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
apt-get -qq install -y php7.0-xml
sleep 2
apt-get -qq install -y php-curl
sleep 1
apt-get -qq install -y libapache2-mod-php7.0
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 stable
chown -R pi:pi openWB
echo "... git cloned"
else
echo "...ok"
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"
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
sudo /bin/su -c "echo 'upload_max_filesize = 30M' > /etc/php/7.0/apache2/conf.d/20-uploadlimit.ini"
sudo apt-get -qq install -y python-pip
sudo pip install -U pymodbus
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