-
Notifications
You must be signed in to change notification settings - Fork 123
/
install.sh
executable file
·316 lines (268 loc) · 6.74 KB
/
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
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
#!/bin/bash
#
# Installer
#
# @copyright Copyright (c) 2015 - 2023, The volkszaehler.org project
# @license http://www.opensource.org/licenses/gpl-license.php GNU Public License
# @author Andreas Goetz
#
##
# The installer will clone all required repositories or update them if necessary.
# Then the modules are compiled and installed
#
# USAGE:
#
# Run install.sh from vzlogger or parent folder
#
# ./install.sh
#
# To execute specific parts of the build select which ones to run:
#
# ./install.sh <list of modules>
#
# Modules:
# - vzlogger (libraries must be in place already)
# - libsmljson
# - libsml
# - mqtt
# - clean (will clean the respective make targets, requires explicitly naming the modules)
#
# To run a clean build:
#
# ./install.sh vzlogger libjson libsml clean
#
##
# This file is part of volkzaehler.org
#
# volkzaehler.org is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# volkzaehler.org is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with volkszaehler.org. If not, see <http://www.gnu.org/licenses/>.
##
set -e
shopt -s nocasematch
###############################
# some defaults
lib_dir=libs
build_dir=build
vzlogger_conf=/etc/vzlogger.conf
git_config=.git/config
systemd_unit=/etc/systemd/system/vzlogger.service
cmake_args=-DBUILD_TEST=off
###############################
# functions
ask() {
question="$1"
default="$2"
read -e -p "$question [$default] "
REPLY="${REPLY:-$default}"
}
contains() {
[[ $1 =~ $2 ]] && true || false
}
git_is_repo() {
folder="$1"
match="${2-$folder}"
if [ -e "$folder/$git_config" ] && grep -q "$match" "$folder/$git_config"; then
true
else
false
fi
}
git_update() {
folder="$1"
git_repo="$2"
match="${3-$folder}"
git_params="${4-}"
if git_is_repo $folder $match; then
echo "$folder folder: $(pwd)/$folder"
git_dirty=$(cd $folder; git fetch; git log HEAD.. --oneline)
else
echo "$folder not found"
echo "cloning $folder git repository"
git clone $git_params "$git_repo" $folder
fi
if [ -n "$git_dirty" ]; then
echo "updating $folder git repository with remote changes"
pushd $folder
git pull
popd
fi
}
###############################
# header
echo "vzlogger installation script"
###############################
# check prerequisites
echo
echo -n "checking prerequisites:"
deps=( grep extrace git cmake pkg-config dh-autoreconf )
for binary in "${deps[@]}"; do
if binpath="$(which $binary)" ; then
echo -n " $binary"
else
echo
echo " $binary: not found. Please install to use this script (e.g. sudo apt-get install $binary)."
echo " For complete list of build requirements please check http://wiki.volkszaehler.org/software/controller/vzlogger/installation_cpp-version"
exit 1
fi
done
echo
###############################
echo
echo "vzlogger setup..."
if [ -n "$1" ]; then
echo "setup modules: $1"
fi
###############################
echo
echo "checking for vzlogger folder"
if ! git_is_repo . vzlogger ; then
# move to parent folder
if git_is_repo vzlogger ; then
cd vzlogger
else
if [ -d vzlogger ]; then
echo "directory ./vzlogger does not contain a recognized git repo"
fi
mkdir vzlogger
cd vzlogger
fi
fi
if [ -z "$1" ] || contains "$*" vzlogger; then
git_update . https://github.com/volkszaehler/vzlogger.git vzlogger
fi
###############################
echo
echo "checking for libraries"
if [ ! -d "$lib_dir" ]; then
echo "creating library folder $lib_dir"
mkdir "$lib_dir"
fi
pushd "$lib_dir"
###############################
# libjson
if [ -z "$1" ] || contains "$*" libjson; then
echo
echo "checking for libjson"
git_update json-c https://github.com/json-c/json-c json-c "-b json-c-0.12"
fi
# libsml
if [ -z "$1" ] || contains "$*" libsml; then
echo
echo "checking for libsml"
git_update libsml https://github.com/volkszaehler/libsml.git
fi
# libmbus
if [ -z "$1" ] || contains "$*" libmbus; then
echo
echo "checking for libmbus"
git_update libmbus https://github.com/rscada/libmbus.git
fi
# mqtt
if contains "$*" mqtt; then
echo
echo "checking for libmosquitto"
if ! ldconfig -p | grep -q libmosquitto.so; then
echo
echo "libmosquitto-dev is not installed"
exit 1
else
cmake_args="${cmake_args} -DENABLE_MQTT=on"
fi
fi
###############################
echo
echo "building and installing libraries"
# libjson
if [ -z "$1" ] || contains "$*" libjson; then
echo
echo "building and installing libjson"
pushd json-c
if [ ! -e Makefile ]; then
sh autogen.sh
./configure
else
if contains "$*" clean; then make clean; fi
fi
make
sudo make install
popd
fi
# libsml
if [ -z "$1" ] || contains "$*" libsml; then
echo
echo "building and installing libsml"
pushd libsml
if contains "$*" clean; then make clean; fi
make
sudo cp sml/lib/libsml.* /usr/lib/
sudo cp -R sml/include/* /usr/include/
sudo cp sml.pc /usr/lib/pkgconfig/
popd
fi
# libmbus
if [ -z "$1" ] || contains "$*" libmbus; then
echo
echo "building and installing libmbus"
pushd libmbus
if contains "$*" clean; then make clean; fi
./build.sh
sudo make install
popd
fi
popd
###############################
# vzlogger
if [ -z "$1" ] || contains "$*" vzlogger; then
echo
echo "building and installing vzlogger"
if [ ! -d "$build_dir" ]; then
echo "creating folder $build_dir"
mkdir "$build_dir"
fi
pushd "$build_dir"
if contains "$*" clean; then
echo "clearing cmake cache"
rm CMakeCache.txt
fi
echo
echo "building vzlogger"
cmake $cmake_args ..
make
echo
echo "installing vzlogger"
sudo make install
popd
if [ ! -e "$systemd_unit" ]; then
echo
echo "could not find $systemd_unit"
echo "it is recommended to configure a vzlogger systemd service"
echo
read -p "add the systemd unit file? [y/N]" -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo
echo "installing systemd unit file"
sudo cp ./etc/vzlogger.service "$systemd_unit"
sudo sed -i "s|/etc/vzlogger.conf|$vzlogger_conf|g" "$systemd_unit"
fi
fi
if [ ! -e "$vzlogger_conf" ]; then
echo
echo "could not find global config file $vzlogger_conf"
echo "make sure to configure vzlogger before running (see etc/vzlogger.conf)"
fi
if [ -n "$(pidof vzlogger)" ]; then
echo
echo "vzlogger is already running"
echo "make sure to restart vzlogger"
fi
fi