forked from OpenSprinkler/OpenSprinkler-Firmware
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.sh
executable file
·127 lines (106 loc) · 3.74 KB
/
build.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
#!/bin/bash
set -e
function enable_i2c {
if command -v raspi-config &> /dev/null; then
if [[ $(sudo raspi-config nonint get_i2c) -eq 1 ]] ; then
echo "Enabling i2c"
sudo modprobe i2c-dev
sudo raspi-config nonint do_i2c 0
fi
if [[ $(grep -c '^dtparam=i2c_arm=on$' /boot/config.txt) -ge 1 ]] ; then
echo "Setting the i2c clock speed to 400 kHz, you will have to reboot for this to take effect."
sudo sed -i -e 's/dtparam=i2c_arm=on$/dtparam=i2c_arm=on,i2c_arm_baudrate=400000/g' /boot/config.txt
fi
else
echo "Can not automatically enable i2c you might have to do this manually"
fi
}
DEBUG=""
while getopts ":s:d" opt; do
case $opt in
s)
SILENT=true
command shift
;;
d)
DEBUG="-DENABLE_DEBUG -DSERIAL_DEBUG"
command shift
;;
esac
done
FILENAME="sopts.dat"
if [[ ! "$SILENT" && -f "$FILENAME" ]]; then
FILESIZE=$(stat -c%s "$FILENAME")
if [[ "$FILESIZE" != "4160" ]]; then
echo "This version has a new configuration data structure."
echo "Please backup configuration and restore after update!"
echo "Otherwise your configuration is lost"
echo "however, if this is a new installation, then you can proceed directly"
read -p "Press ctrl-c to stop now or enter to continue"
fi
fi
echo "Building OpenSprinkler..."
if [ -f /etc/init.d/OpenSprinkler.sh ]; then
/etc/init.d/OpenSprinkler.sh stop
elif [ -f /etc/systemd/system/OpenSprinkler.service ]; then
systemctl stop OpenSprinkler
fi
#Git update submodules
if git submodule status | grep --quiet '^-'; then
echo "A git submodule is not initialized."
git submodule update --recursive --init
else
echo "Updating submodules."
git submodule update --recursive
fi
if [ "$1" == "demo" ]; then
echo "Installing required libraries..."
apt-get install -y libmosquitto-dev libssl-dev
echo "Compiling demo firmware..."
ws=$(ls external/TinyWebsockets/tiny_websockets_lib/src/*.cpp)
otf=$(ls external/OpenThings-Framework-Firmware-Library/*.cpp)
ifx=$(ls external/influxdb-cpp/*.cpp)
g++ -o OpenSprinkler -DDEMO -DSMTP_OPENSSL $DEBUG -std=c++14 -include string.h main.cpp \
OpenSprinkler.cpp program.cpp opensprinkler_server.cpp utils.cpp weather.cpp gpio.cpp \
mqtt.cpp smtp.c RCSwitch.cpp \
-Iexternal/TinyWebsockets/tiny_websockets_lib/include \
$ws \
-Iexternal/OpenThings-Framework-Firmware-Library/ \
$otf \
$ifx \
-lpthread -lmosquitto -lssl -lcrypto
else
echo "Installing required libraries..."
apt-get update
apt-get install -y libmosquitto-dev libi2c-dev libssl-dev libgpiod-dev gpiod libmodbus-dev
enable_i2c
./build2.sh
fi
if [ -f /etc/init.d/OpenSprinkler.sh ]; then
echo "Detected the only init.d start up script, removing."
echo "If you still want OpenSprinkler to launch on startup make sure when you run the build script to answer \"Y\" to the following question."
/etc/init.d/OpenSprinkler.sh stop
rm /etc/init.d/OpenSprinkler.sh
fi
if [ ! "$SILENT" = true ] && [ -f OpenSprinkler.service ] && [ -f startOpenSprinkler.sh ] && [ ! -f /etc/systemd/system/OpenSprinkler.service ]; then
read -p "Do you want to start OpenSprinkler on startup? " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 0
fi
echo "Adding OpenSprinkler launch service..."
# Get current directory (binary location)
pushd "$(dirname $0)" > /dev/null
DIR="$(pwd)"
popd > /dev/null
# Update binary location in start up script
sed -e 's,\_\_OpenSprinkler\_Path\_\_,'"$DIR"',g' OpenSprinkler.service > /etc/systemd/system/OpenSprinkler.service
# Make file executable
chmod +x startOpenSprinkler.sh
fi
# Reload systemd
systemctl daemon-reload
# Enable and start the service
systemctl enable OpenSprinkler
systemctl start OpenSprinkler
echo "Done!"