forked from OpenSprinkler/OpenSprinkler-Firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·70 lines (52 loc) · 2.05 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
#!/bin/bash
while getopts ":s" opt; do
case $opt in
s)
SILENT=true
command shift
;;
esac
done
echo "Building OpenSprinkler..."
if [ "$1" == "demo" ]; then
g++ -o OpenSprinkler -DDEMO -m32 main.cpp OpenSprinkler.cpp program.cpp server.cpp utils.cpp weather.cpp gpio.cpp etherport.cpp -lpthread
elif [ "$1" == "osbo" ]; then
g++ -o OpenSprinkler -DOSBO main.cpp OpenSprinkler.cpp program.cpp server.cpp utils.cpp weather.cpp gpio.cpp etherport.cpp -lpthread
else
g++ -o OpenSprinkler -DOSPI main.cpp OpenSprinkler.cpp program.cpp server.cpp utils.cpp weather.cpp gpio.cpp etherport.cpp -lpthread
fi
if [ ! "$SILENT" = true ]; then
read -p "Do you want to start OpenSprinkler on startup? " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 0
fi
# Get current directory (binary location)
pushd `dirname $0` > /dev/null
DIR=`pwd`
popd > /dev/null
if [ -d "/run/systemd/system" ] && [ ! -f /etc/systemd/system/ospi.service ]; then
echo "Adding OpenSprinkler systemd service..."
# Update binary location in service
sed -e 's,\_\_OpenSprinkler\_Path\_\_,'"$DIR"',g' OpenSprinkler.systemd > ospi.service
# Move service script to systemd directory
sudo mv ospi.service /etc/systemd/system/
# Add to auto-launch on system startup
sudo systemctl enable ospi.service
# Start the deamon now
sudo systemctl start ospi.service
elif [ -f OpenSprinkler.launch ] && [ ! -f /etc/init.d/OpenSprinkler.sh ]; then
echo "Adding OpenSprinkler launch script..."
# Update binary location in start up script
sed -e 's,\_\_OpenSprinkler\_Path\_\_,'"$DIR"',g' OpenSprinkler.launch > OpenSprinkler.sh
# Make file executable
chmod +x OpenSprinkler.sh
# Move start up script to init.d directory
sudo mv OpenSprinkler.sh /etc/init.d/
# Add to auto-launch on system startup
sudo update-rc.d OpenSprinkler.sh defaults
# Start the deamon now
sudo /etc/init.d/OpenSprinkler.sh start
fi
fi
echo "Done!"