forked from arkime/arkime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
easybutton-build.sh
executable file
·321 lines (279 loc) · 10.4 KB
/
easybutton-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
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
317
318
319
320
321
#!/bin/sh
# Use this script to install OS dependencies, downloading and compile moloch dependencies, compile moloch capture, optionally install
# This script will
# * use apt-get/yum to install OS dependancies
# * download known working versions of moloch dependancies
# * build them statically
# * configure moloch-capture to use them
# * build moloch-capture
# * install node unless --nonode
# * install moloch if --install
GLIB=2.56.2
YARA=3.10.0
MAXMIND=1.3.2
PCAP=1.9.0
CURL=7.66.0
LUA=5.3.5
DAQ=2.0.6
NODE=10.16.3
TDIR="/data/moloch"
DOPFRING=0
DODAQ=0
DOCLEAN=0
DONODE=1
DOINSTALL=0
DORMINSTALL=0
while :
do
case $1 in
-p | --pf_ring | --pfring)
DOPFRING=1
shift
;;
-d | --dir)
TDIR=$2
shift 2
;;
--daq)
DODAQ=1
shift
;;
--clean)
DOCLEAN=1
shift
;;
--install)
DOINSTALL=1
shift
;;
--rminstall)
DORMINSTALL=1
shift
;;
--nonode)
DONODE=0
shift
;;
--help)
echo "Make it easier to build Moloch! This will download and build thirdparty libraries plus build Moloch."
echo "--dir <directory> = The directory to install everything into [/data/moloch]"
echo "--clean = Do a 'make clean' first"
echo "--rminstall = Do a 'rm -rf <dir>' first"
echo "--install = Do a 'make install' at the end, adding our node to the path"
echo "--nonode = Do NOT download and install nodejs into the moloch directory"
echo "--pfring = Build pfring support"
echo "--daq = Build daq support"
exit 0;
;;
-*)
echo "Unknown option '$1', try '--help'"
exit 1
;;
*)
break
;;
esac
done
# Check the existance of sudo
command -v sudo >/dev/null 2>&1 || { echo >&2 "MOLOCH: sudo is required to be installed"; exit 1; }
MAKE=make
UNAME="$(uname)"
# Installing dependencies
echo "MOLOCH: Installing Dependencies"
if [ -f "/etc/redhat-release" ]; then
sudo yum -y install wget curl pcre pcre-devel pkgconfig flex bison gcc-c++ zlib-devel e2fsprogs-devel openssl-devel file-devel make gettext libuuid-devel perl-JSON bzip2-libs bzip2-devel perl-libwww-perl libpng-devel xz libffi-devel readline-devel libtool libyaml-devel perl-Socket6 perl-Test-Differences
if [ $? -ne 0 ]; then
echo "MOLOCH: yum failed"
exit 1
fi
fi
if [ -f "/etc/debian_version" ]; then
sudo apt-get -y install wget curl libpcre3-dev uuid-dev libmagic-dev pkg-config g++ flex bison zlib1g-dev libffi-dev gettext libgeoip-dev make libjson-perl libbz2-dev libwww-perl libpng-dev xz-utils libffi-dev libssl-dev libreadline-dev libtool libyaml-dev dh-autoreconf libsocket6-perl libtest-differences-perl
if [ $? -ne 0 ]; then
echo "MOLOCH: apt-get failed"
exit 1
fi
fi
if [ "$UNAME" = "FreeBSD" ]; then
sudo pkg_add -Fr wget curl pcre flex bison gettext e2fsprogs-libuuid glib gmake libexecinfo
MAKE=gmake
fi
if [ "$UNAME" = "Darwin" ]; then
if [ -x "/opt/local/bin/port" ]; then
sudo port install libpcap yara glib2 jansson ossp-uuid libmaxminddb libmagic pcre lua libyaml
echo "MOLOCH: Building capture"
echo './configure --with-libpcap=/opt/local --with-yara=/opt/local LDFLAGS="-L/opt/local/lib" --with-glib2=no GLIB2_CFLAGS="-I/opt/local/include/glib-2.0 -I/opt/local/lib/glib-2.0/include" GLIB2_LIBS="-L/opt/local/lib -lglib-2.0 -lgmodule-2.0 -lgobject-2.0 -lgio-2.0" --with-pfring=no --with-curl=yes --with-lua=no LUA_CFLAGS="-I/opt/local/include" LUA_LIBS="-L/opt/local/lib -llua"'
./configure --with-libpcap=/opt/local --with-yara=/opt/local LDFLAGS="-L/opt/local/lib" --with-glib2=no GLIB2_CFLAGS="-I/opt/local/include/glib-2.0 -I/opt/local/lib/glib-2.0/include" GLIB2_LIBS="-L/opt/local/lib -lglib-2.0 -lgmodule-2.0 -lgobject-2.0 -lgio-2.0" --with-pfring=no --with-curl=yes --with-lua=no LUA_CFLAGS="-I/opt/local/include" LUA_LIBS="-L/opt/local/lib -llua"
elif [ -x "/usr/local/bin/brew" ]; then
brew install libpcap yara glib jansson ossp-uuid libmaxminddb libmagic pcre lua libyaml openssl
echo "MOLOCH: Building capture"
echo './configure --with-libpcap=/usr/local/opt/libpcap --with-yara=/usr/local LDFLAGS="-L/usr/local/lib" --with-glib2=no GLIB2_CFLAGS="-I/usr/local/include/glib-2.0 -I/usr/local/lib/glib-2.0/include -I/usr/local/opt/[email protected]/include" GLIB2_LIBS="-L/usr/local/lib -lglib-2.0 -lgmodule-2.0 -lgobject-2.0 -lgio-2.0 -L/usr/local/opt/[email protected]/lib" --with-pfring=no --with-curl=yes --with-lua=no LUA_CFLAGS="-I/usr/local/include/lua" LUA_LIBS="-L/usr/local/lib -llua'
./configure --with-libpcap=/usr/local/opt/libpcap --with-yara=/usr/local LDFLAGS="-L/usr/local/lib" --with-glib2=no GLIB2_CFLAGS="-I/usr/local/include/glib-2.0 -I/usr/local/lib/glib-2.0/include -I/usr/local/opt/[email protected]/include" GLIB2_LIBS="-L/usr/local/lib -lglib-2.0 -lgmodule-2.0 -lgobject-2.0 -lgio-2.0 -L/usr/local/opt/[email protected]/lib" --with-pfring=no --with-curl=yes --with-lua=no LUA_CFLAGS="-I/usr/local/include/lua" LUA_LIBS="-L/usr/local/lib -llua"
else
echo "MOLOCH: Please install MacPorts or Homebrew"
exit 1
fi
else
echo "MOLOCH: Downloading and building static thirdparty libraries"
if [ ! -d "thirdparty" ]; then
mkdir thirdparty
fi
cd thirdparty || exit
TPWD=`pwd`
# glib
if [ "$UNAME" = "FreeBSD" ]; then
#Screw it, use whatever the OS has
WITHGLIB=" "
else
WITHGLIB="--with-glib2=thirdparty/glib-$GLIB"
if [ ! -f "glib-$GLIB.tar.xz" ]; then
GLIBDIR=$(echo $GLIB | cut -d. -f 1-2)
wget "http://ftp.gnome.org/pub/gnome/sources/glib/$GLIBDIR/glib-$GLIB.tar.xz"
fi
if [ ! -f "glib-$GLIB/gio/.libs/libgio-2.0.a" ] || [ ! -f "glib-$GLIB/glib/.libs/libglib-2.0.a" ]; then
xzcat glib-$GLIB.tar.xz | tar xf -
(cd glib-$GLIB ; ./configure --disable-xattr --disable-shared --enable-static --disable-libelf --disable-selinux --disable-libmount --with-pcre=internal; $MAKE)
if [ $? -ne 0 ]; then
echo "MOLOCH: $MAKE failed"
exit 1
fi
else
echo "MOLOCH: Not rebuilding glib"
fi
fi
# yara
if [ ! -f "yara/yara-$YARA.tar.gz" ]; then
mkdir -p yara
wget https://github.com/VirusTotal/yara/archive/v$YARA.tar.gz -O yara/yara-$YARA.tar.gz
fi
if [ ! -f "yara/yara-$YARA/libyara/.libs/libyara.a" ]; then
(cd yara ; tar zxf yara-$YARA.tar.gz)
(cd yara/yara-$YARA; ./bootstrap.sh ; ./configure --enable-static; $MAKE)
if [ $? -ne 0 ]; then
echo "MOLOCH: $MAKE failed"
exit 1
fi
else
echo "MOLOCH: Not rebuilding yara"
fi
# Maxmind
if [ ! -f "libmaxminddb-$MAXMIND.tar.gz" ]; then
wget https://github.com/maxmind/libmaxminddb/releases/download/$MAXMIND/libmaxminddb-$MAXMIND.tar.gz
fi
if [ ! -f "libmaxminddb-$MAXMIND/src/.libs/libmaxminddb.a" ]; then
tar zxf libmaxminddb-$MAXMIND.tar.gz
(cd libmaxminddb-$MAXMIND ; ./configure --enable-static; $MAKE)
if [ $? -ne 0 ]; then
echo "MOLOCH: $MAKE failed"
exit 1
fi
else
echo "MOLOCH: Not rebuilding libmaxmind"
fi
# libpcap
if [ ! -f "libpcap-$PCAP.tar.gz" ]; then
wget http://www.tcpdump.org/release/libpcap-$PCAP.tar.gz
fi
if [ ! -f "libpcap-$PCAP/libpcap.a" ]; then
tar zxf libpcap-$PCAP.tar.gz
echo "MOLOCH: Building libpcap";
(cd libpcap-$PCAP; ./configure --disable-rdma --disable-dbus --disable-usb --disable-bluetooth --with-snf=no; $MAKE)
if [ $? -ne 0 ]; then
echo "MOLOCH: $MAKE failed"
exit 1
fi
else
echo "MOLOCH: NOT rebuilding libpcap";
fi
PCAPDIR=$TPWD/libpcap-$PCAP
PCAPBUILD="--with-libpcap=$PCAPDIR"
# curl
if [ ! -f "curl-$CURL.tar.gz" ]; then
wget http://curl.haxx.se/download/curl-$CURL.tar.gz
fi
if [ ! -f "curl-$CURL/lib/.libs/libcurl.a" ]; then
tar zxf curl-$CURL.tar.gz
( cd curl-$CURL; ./configure --disable-ldap --disable-ldaps --without-libidn2 --without-librtmp --without-libpsl --without-nghttp2 --without-nghttp2 --without-nss; $MAKE)
if [ $? -ne 0 ]; then
echo "MOLOCH: $MAKE failed"
exit 1
fi
else
echo "MOLOCH: Not rebuilding curl"
fi
# lua
if [ ! -f "lua-$LUA.tar.gz" ]; then
wget https://www.lua.org/ftp/lua-$LUA.tar.gz
fi
if [ ! -f "lua-$LUA/src/liblua.a" ]; then
tar zxf lua-$LUA.tar.gz
( cd lua-$LUA; make MYCFLAGS=-fPIC linux)
if [ $? -ne 0 ]; then
echo "MOLOCH: $MAKE failed"
exit 1
fi
else
echo "MOLOCH: Not rebuilding lua"
fi
# daq
if [ $DODAQ -eq 1 ]; then
if [ ! -f "daq-$DAQ.tar.gz" ]; then
wget https://www.snort.org/downloads/snort/daq-$DAQ.tar.gz
fi
if [ ! -f "daq-$DAQ/api/.libs/libdaq_static.a" ]; then
tar zxf daq-$DAQ.tar.gz
( cd daq-$DAQ; ./configure --with-libpcap-includes=$TPWD/libpcap-$PCAP/ --with-libpcap-libraries=$TPWD/libpcap-$PCAP; make; sudo make install)
if [ $? -ne 0 ]; then
echo "MOLOCH: $MAKE failed"
exit 1
fi
else
echo "MOLOCH: Not rebuilding daq"
fi
fi
# Now build moloch
echo "MOLOCH: Building capture"
cd ..
echo "./configure --prefix=$TDIR $PCAPBUILD --with-yara=thirdparty/yara/yara-$YARA --with-maxminddb=thirdparty/libmaxminddb-$MAXMIND $WITHGLIB --with-curl=thirdparty/curl-$CURL --with-lua=thirdparty/lua-$LUA"
./configure --prefix=$TDIR $PCAPBUILD --with-yara=thirdparty/yara/yara-$YARA --with-maxminddb=thirdparty/libmaxminddb-$MAXMIND $WITHGLIB --with-curl=thirdparty/curl-$CURL --with-lua=thirdparty/lua-$LUA
fi
if [ $DOCLEAN -eq 1 ]; then
$MAKE clean
fi
$MAKE
if [ $? -ne 0 ]; then
echo "MOLOCH: $MAKE failed"
exit 1
fi
# Build plugins
(cd capture/plugins/lua; $MAKE)
if [ $DOPFRING -eq 1 ] || [ -f "/usr/local/lib/libpfring.so" ]; then
(cd capture/plugins/pfring; $MAKE)
fi
if [ $DODAQ -eq 1 ]; then
(cd capture/plugins/daq; $MAKE)
fi
if [ -f "/opt/snf/lib/libsnf.so" ]; then
(cd capture/plugins/snf; $MAKE)
fi
# Remove old install dir
if [ $DORMINSTALL -eq 1 ]; then
rm -rf $TDIR
fi
# Install node if not already there
if [ $DONODE -eq 1 ] && [ ! -f "$TDIR/bin/node" ]; then
echo "MOLOCH: Installing node $NODE"
sudo mkdir -p $TDIR/bin $TDIR/etc
if [ ! -f node-v$NODE-linux-x64.tar.xz ] ; then
wget https://nodejs.org/download/release/v$NODE/node-v$NODE-linux-x64.tar.xz
fi
sudo tar xfC node-v$NODE-linux-x64.tar.xz $TDIR
(cd $TDIR/bin ; sudo ln -sf ../node-v$NODE-linux-x64/bin/* .)
fi
if [ $DOINSTALL -eq 1 ]; then
sudo env "PATH=$TDIR/bin:$PATH" make install
echo "MOLOCH: Installed, now type sudo make config'"
else
echo "MOLOCH: Now type 'sudo make install' and 'sudo make config'"
fi
exit 0