This repository was archived by the owner on Dec 3, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstaller.sh
More file actions
246 lines (213 loc) · 6.99 KB
/
installer.sh
File metadata and controls
246 lines (213 loc) · 6.99 KB
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
#!/bin/sh
# Copyright 2015-2017 Intecture Developers. See the COPYRIGHT file at the
# top-level directory of this distribution and at
# https://intecture.io/COPYRIGHT.
#
# Licensed under the Mozilla Public License 2.0 <LICENSE or
# https://www.tldrlegal.com/l/mpl-2.0>. This file may not be copied,
# modified, or distributed except according to those terms.
# Undefined vars are errors
set -u
# Globals
prefix="{{prefix}}"
libdir="{{libdir}}"
libext="{{libext}}"
sysconfdir="{{sysconfdir}}"
pkgconf="{{pkgconf}}"
pkgconfdir="{{pkgconfdir}}"
os="{{os}}"
do_install() {
need_cmd $pkgconf
local _one=
local _two=
if ! $($pkgconf --exists libzmq); then
if [ "$os" = "darwin" ]; then
_one="5"
_two=$libext
else
_one=$libext
_two="5"
fi
install -m 755 lib/libzmq.$libext $libdir/libzmq.$_one.$_two
ln -s $libdir/libzmq.$_one.$_two $libdir/libzmq.$libext
install -m 644 lib/pkgconfig/libzmq.pc $pkgconfdir
install -m 644 include/zmq.h $prefix/include/
if [ "$os" = "freebsd" ]; then
install -m 644 lib/libstdc++.so.6 $libdir/
fi
fi
if ! $($pkgconf --exists libczmq); then
if [ "$os" = "darwin" ]; then
_one="4"
_two=$libext
else
_one=$libext
_two="4"
fi
install -m 755 lib/libczmq.$libext $libdir/libczmq.$_one.$_two
ln -s $libdir/libczmq.$_one.$_two $libdir/libczmq.$libext
install -m 644 lib/pkgconfig/libczmq.pc $pkgconfdir
install -m 644 include/czmq.h $prefix/include/
install -m 644 include/czmq_library.h $prefix/include/
install -m 644 include/czmq_prelude.h $prefix/include/
install -m 644 include/zactor.h $prefix/include/
install -m 644 include/zarmour.h $prefix/include/
install -m 644 include/zauth.h $prefix/include/
install -m 644 include/zbeacon.h $prefix/include/
install -m 644 include/zcert.h $prefix/include/
install -m 644 include/zcertstore.h $prefix/include/
install -m 644 include/zchunk.h $prefix/include/
install -m 644 include/zclock.h $prefix/include/
install -m 644 include/zconfig.h $prefix/include/
install -m 644 include/zdigest.h $prefix/include/
install -m 644 include/zdir.h $prefix/include/
install -m 644 include/zdir_patch.h $prefix/include/
install -m 644 include/zfile.h $prefix/include/
install -m 644 include/zframe.h $prefix/include/
install -m 644 include/zgossip.h $prefix/include/
install -m 644 include/zhash.h $prefix/include/
install -m 644 include/zhashx.h $prefix/include/
install -m 644 include/ziflist.h $prefix/include/
install -m 644 include/zlist.h $prefix/include/
install -m 644 include/zlistx.h $prefix/include/
install -m 644 include/zloop.h $prefix/include/
install -m 644 include/zmonitor.h $prefix/include/
install -m 644 include/zmsg.h $prefix/include/
install -m 644 include/zpoller.h $prefix/include/
install -m 644 include/zproxy.h $prefix/include/
install -m 644 include/zrex.h $prefix/include/
install -m 644 include/zsock.h $prefix/include/
install -m 644 include/zstr.h $prefix/include/
install -m 644 include/zsys.h $prefix/include/
install -m 644 include/zuuid.h $prefix/include/
fi
case "$os" in
centos | fedora | debian | ubuntu)
if $(stat --format=%N /proc/1/exe|grep -qs systemd); then
if [ -d $prefix/usr/systemd/system ]; then
install -m 644 systemd $prefix/lib/systemd/system/inagent.service
elif [ -d /lib/systemd/system ]; then
install -m 644 systemd /lib/systemd/system/inagent.service
fi
else
install -m 755 init $sysconfdir/init.d/inagent
fi
;;
freebsd)
install -m 555 init $sysconfdir/rc.d/inagent;
;;
esac
mkdir -p $sysconfdir/intecture
install -m 644 agent.json $sysconfdir/intecture/
install -m 755 inagent $prefix/bin
}
install_certs() {
install -m 600 $1 $sysconfdir/intecture/agent.crt
install -m 600 $2 $sysconfdir/intecture/auth.crt_public
}
amend_conf() {
local _confpath=$sysconfdir/intecture/agent.json
if [ ! -f $_confpath ]; then
echo "Agent conf file not found. Run `installer.sh install` first."
exit 1
fi
# If value is int, don't enclose in quotes
if [ $2 -eq $2 2> /dev/null ]; then
local _quotes=""
else
local _quotes='"'
fi
local _q='"' # Need this for FreeBSD, which doesn't respect escapes
local _line=$(grep -n "$_q$1$_q:" $_confpath | cut -f1 -d:)
local _total=$(wc -l $_confpath | sed 's/^ *//' | cut -f1 -d' ')
if [ `expr $_total - $_line` -gt 1 ]; then
local _comma=","
else
local _comma=""
fi
local _tmpfile=$(mktemp 2>/dev/null || mktemp -t inagent-conf)
sed "s~\"$1\": .*~\"$1\": $_quotes$2$_quotes$_comma~" < $_confpath > $_tmpfile || exit 1
install -m 600 $_tmpfile $_confpath
}
start_daemon() {
case "$os" in
centos | fedora | debian | ubuntu)
if $(stat --format=%N /proc/1/exe|grep -qs systemd); then
systemctl start inagent
else
service inagent start
fi
;;
freebsd)
printf '\ninagent_enable="YES"\n' >> /etc/rc.conf
service inagent start
;;
darwin)
nohup /usr/local/bin/inagent &
;;
*)
echo "unrecognized OS type: $os" >&2
exit 1
;;
esac
}
do_uninstall() {
rm -f $prefix/bin/inagent \
$sysconfdir/intecture/agent.json \
/lib/systemd/system/inagent.service \
$prefix/lib/systemd/system/inagent.service \
$sysconfdir/init.d/inagent \
$sysconfdir/rc.d/inagent
if [ -d $sysconfdir/intecture -a -z "$(ls -A $sysconfdir/intecture)" ]; then
rmdir "$sysconfdir/intecture"
fi
}
need_cmd() {
if ! command -v "$1" > /dev/null 2>&1; then
echo "need '$1' (command not found)" >&2
exit 1
fi
}
usage() {
echo "Usage:
installer.sh <install|uninstall>
installer.sh install_certs <agent_prikey_path> <auth_pubkey_path>
installer.sh amend_conf <key> <value>
installer.sh start_daemon"
}
main() {
if [ $# -eq 0 ]; then
usage
exit 0
fi
case "$1" in
install)
do_install
;;
uninstall)
do_uninstall
;;
install_certs)
if [ -z $2 -o -z $3 ]; then
usage
exit 1
fi
install_certs $2 $3
;;
amend_conf)
if [ -z $2 -o -z $3 ]; then
usage
exit 1
fi
amend_conf $2 $3
;;
start_daemon)
start_daemon
;;
*)
echo "Unknown option $1"
exit 1
;;
esac
}
main "$@"