forked from thiagoralves/OpenPLC_v3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
background_installer.sh
executable file
·230 lines (188 loc) · 6.75 KB
/
background_installer.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
218
219
220
221
222
223
224
225
226
227
228
229
230
#!/bin/bash
if [ $# -eq 0 ]; then
echo ""
echo "Error: You must provide a platform name as argument"
echo ""
echo "Usage: ./install.sh [platform] where [platform] can be"
echo " win Install OpenPLC on Windows over Cygwin"
echo " linux Install OpenPLC on a Debian-based Linux distribution"
echo " docker Install OpenPLC in a Docker container"
echo " rpi Install OpenPLC on a Raspberry Pi"
echo " neuron Install OpenPLC on a UniPi Neuron PLC"
echo " custom Skip all specific package installation and tries to install"
echo " OpenPLC assuming your system already has all dependencies met."
echo " This option can be useful if you're trying to install OpenPLC"
echo " on an unsuported Linux platform or had manually installed"
echo " all the dependency packages before."
echo ""
exit 1
fi
WORKING_DIR=$(pwd)
mkdir -p bin
touch etc/Config0.c
touch etc/Res0.c
touch etc/glueVars.cpp
touch etc/oplc_platform
touch etc/openplc_driver
touch etc/active_program
cp webserver/openplc.db ./etc/
# arg1: sudo or blank
function linux_install_deps {
$1 apt-get update
$1 apt-get install -y build-essential pkg-config bison flex autoconf \
automake libtool make git python3 python3-pip \
sqlite3 cmake git
}
function install_py_deps {
$1 pip3 install -r requirements.txt
}
function OPLC_background_service {
echo ""
echo "[OPENPLC SERVICE]"
echo -e "[Unit]\nDescription=OpenPLC Service\nAfter=network.target\n\n[Service]\nType=simple\nRestart=always\nRestartSec=1\nUser=root\nGroup=root\nWorkingDirectory=$WORKING_DIR\nExecStart=$WORKING_DIR/start_openplc.sh\n\n[Install]\nWantedBy=multi-user.target" >> openplc.service
$1 cp -rf ./openplc.service /lib/systemd/system/
rm -rf openplc.service
echo "Enabling OpenPLC Service..."
$1 systemctl daemon-reload
$1 systemctl enable openplc.service
}
function cmake_build_and_test {
echo ""
echo "Building the application"
mkdir build
cd build
cmake .. -DOPLC_ALL=ON
make
echo "Executing platform tests"
cd ../bin
if [ "$1" == "win" ]; then
./gg_unit_test.exe
# fakeit doesn't support O3 optimizations, and we don't have a way
# to detect optimizations, so disable for now.
#./oplc_unit_test.exe
else
./gg_unit_test
# fakeit doesn't support O3 optimizations, and we don't have a way
# to detect optimizations, so disable for now.
#./oplc_unit_test
fi
}
if [ "$1" == "win" ]; then
echo "Installing OpenPLC on Windows"
fileformat=unix
cp ./utils/apt-cyg/apt-cyg ./
cp ./utils/apt-cyg/wget.exe /bin
install apt-cyg /bin
apt-cyg update
apt-cyg install lynx
rm -f /bin/wget.exe
apt-cyg remove gcc-core gcc-g++ pkg-config automake autoconf libtool make python3 python3-pip sqlite3
apt-cyg install wget gcc-core gcc-g++ git pkg-config automake autoconf libtool make python3 python3-pip sqlite3
lynx -source https://bootstrap.pypa.io/get-pip.py > get-pip.py
python3 get-pip.py
pip install -r requirements.txt
rm apt-cyg
rm get-pip.py
cmake_build_and_test
if [ $? -ne 0 ]; then
echo "Compilation finished with errors!"
exit 1
fi
echo "Compilation finished successfully!"
cd ../scripts
./change_hardware_layer.sh blank
elif [ "$1" == "linux" ]; then
echo "Installing OpenPLC on Linux"
linux_install_deps sudo
install_py_deps
install_py_deps "sudo -H"
cmake_build_and_test
if [ $? -ne 0 ]; then
echo "Compilation finished with errors!"
exit 1
fi
echo "Compilation finished successfully!"
if [ "$2" != "-d" ]; then
OPLC_background_service sudo
fi
cd ../scripts
./change_hardware_layer.sh blank_linux
elif [ "$1" == "docker" ]; then
echo "Installing OpenPLC on Linux inside Docker"
cmake_build_and_test
if [ $? -ne 0 ]; then
echo "Compilation finished with errors!"
exit 1
fi
echo "Compilation finished successfully!"
cd ../scripts
./change_hardware_layer.sh blank_linux
elif [ "$1" == "rpi" ]; then
echo "Installing OpenPLC on Raspberry Pi"
linux_install_deps sudo
sudo apt-get install -y wiringpi
install_py_deps
install_py_deps "sudo -H"
cmake_build_and_test
if [ $? -ne 0 ]; then
echo "Compilation finished with errors!"
exit 1
fi
echo "Compilation finished successfully!"
if [ "$2" != "-d" ]; then
OPLC_background_service sudo
fi
cd ../scripts
./change_hardware_layer.sh blank_linux
elif [ "$1" == "neuron" ]; then
echo "Installing OpenPLC on UniPi Neuron PLC"
echo ""
echo "[DISABLING UNIPI SERVICES]"
sudo systemctl stop neuronhost.service
sudo systemctl disable neuronhost.service
sudo systemctl stop neurontcp.service
sudo systemctl disable neurontcp.service
sudo systemctl stop evok.service
sudo systemctl disable evok.service
linux_install_deps sudo
install_py_deps
install_py_deps sudo "sudo -H"
cmake_build_and_test
if [ $? -ne 0 ]; then
echo "Compilation finished with errors!"
exit 1
fi
echo "Compilation finished successfully!"
if [ "$2" != "-d" ]; then
OPLC_background_service sudo
fi
cd ../scripts
./change_hardware_layer.sh blank_linux
elif [ "$1" == "custom" ]; then
echo "Installing OpenPLC on Custom Platform"
cmake_build_and_test
if [ $? -ne 0 ]; then
echo "Compilation finished with errors!"
exit 1
fi
echo "Compilation finished successfully!"
cd ../scripts
./change_hardware_layer.sh blank_linux
else
echo ""
echo "Error: You must provide a platform name as argument"
echo ""
echo "Usage: ./install.sh [platform] where [platform] can be"
echo " win Install OpenPLC on Windows over Cygwin"
echo " linux Install OpenPLC on a Debian-based Linux distribution"
echo " docker Install OpenPLC in a Docker container"
echo " rpi Install OpenPLC on a Raspberry Pi"
echo " neuron Install OpenPLC on a UniPi Neuron PLC"
echo " custom Skip all specific package installation and tries to install"
echo " OpenPLC assuming your system already has all dependencies met."
echo " This option can be useful if you're trying to install OpenPLC"
echo " on an unsuported Linux platform or had manually installed"
echo " all the dependency packages before."
echo ""
exit 1
fi