forked from snaptec/openWB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
openwb-install.sh
executable file
·123 lines (108 loc) · 3.67 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
#!/bin/bash
echo "install required packages..."
# check for outdated sources.list (Stretch only)
if grep -q -e "^deb http://raspbian.raspberrypi.org/raspbian/ stretch" /etc/apt/sources.list; then
echo "sources.list outdated! upgrading..."
sudo sed -i "s/^deb http:\/\/raspbian.raspberrypi.org\/raspbian\/ stretch/deb http:\/\/legacy.raspbian.org\/raspbian\/ stretch/g" /etc/apt/sources.list
else
echo "sources.list already updated"
fi
apt-get update
apt-get -q -y install vim bc apache2 php php-gd php-curl php-xml php-json libapache2-mod-php jq raspberrypi-kernel-headers i2c-tools git mosquitto mosquitto-clients socat python-pip python3-pip sshpass
echo "...done"
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 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 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
# start mosquitto
sudo service mosquitto start
# check for mosquitto configuration
if [ ! -f /etc/mosquitto/conf.d/openwb.conf ]; then
echo "updating mosquitto config file"
sudo cp /var/www/html/openWB/web/files/mosquitto.conf /etc/mosquitto/conf.d/openwb.conf
sudo service mosquitto reload
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 "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 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/*
chmod +x /var/www/html/openWB/*.sh
touch /var/log/openWB.log
chmod 777 /var/log/openWB.log
sudo -u pi /var/www/html/openWB/runs/atreboot.sh