forked from bmcgonag/Vector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vector_install.sh
419 lines (341 loc) · 10 KB
/
vector_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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
#!/bin/bash
echo "Would you like to have the installation also create an NGinX Rerverse Proxy with LetsEncrypt Certificates? (Y/N) "
read installNginx
echo ""
echo ""
echo "Please enter your domain name for this server: "
read userDomain
echo "**********************************"
echo "* *"
echo "* First we clean up a bit *"
echo "* *"
echo "**********************************"
echo ""
echo ""
echo ""
sleep 3s
####################################
# We kill our node server main.js #
####################################
echo "**** Kill the node server"
sudo pkill -f node
echo ""
echo "****************************************************"
echo ""
echo "**** Install and set some settings"
apt remove -y dnsmasq
# install OpenResolv for DNS handling
echo ''
echo ''
echo 'Install OpenResolv'
sleep 1
apt install openresolv -y
# Load Modules
echo ''
echo ''
echo 'Load the Modules for WireGuard'
sleep 1
echo '--> modprobe wireguard'
modprobe wireguard
echo '--> modprobe iptable_nat'
modprobe iptable_nat
echo '--> modprobe ip6table_nat'
modprobe ip6table_nat
# Enable IP Packet forwarding
echo ''
echo ''
echo 'Enable IP Packet Forwarding'
sleep 1
sysctl -w net.ipv4.ip_forward=1
sysctl -w net.ipv6.conf.all.forwarding=1
####################################
# remove the folders and old stuff #
####################################
cd
if [ -f ~/Vector.tar.gz ]
then
echo "**** removing Vector.tar.gz"
rm Vector.tar.gz
echo ""
fi
if [ -d ~/Vector-Production ]
then
echo "**** removing Vector-Production folder"
rm -rf Vector-Production
echo ""
fi
if [ -f ~/install_nvm.sh ]
then
echo "**** removing install_nvm.sh file"
rm install_nvm.sh
echo ""
fi
if [ -f ~/.forever/forever.log ]
then
echo "**** remove the current forever.log"
sudo rm ~/.forever/forever.log
echo ""
fi
###############################
# Install WireGuard with PPA #
###############################
echo "***************************************"
echo "* *"
echo "* WireGuard is necessary for Vector *"
echo "* to work for you. *"
echo "* *"
echo "***************************************"
if [ ! -d /etc/wireguard ]
then
echo ""
echo ""
echo "**** Ok, we will install wireguard"
echo ""
echo ""
sudo add-apt-repository ppa:wireguard/wireguard
sudo apt update
sudo apt install wireguard -y
else
echo ""
echo ""
echo "**** WireGuard appears to be installed - good!"
fi
########################################################################
echo ""
echo ""
if [ $installNginx = "Y" ] || [ $installNginx = "y" ]
then
###############################
# Install NGinx as Rev Proxy #
###############################
echo "***************************************"
echo "* *"
echo "* NGinX is used as a reverse proxy *"
echo "* for the Vector install. *"
echo "* *"
echo "***************************************"
if ! which nginx > /dev/null 2>&1; then
echo ""
echo ""
echo "**** Ok, we will install NGinX"
echo ""
echo ""
sudo apt update
sudo apt install nginx -y
else
echo ""
echo ""
echo "**** NGinX appears to be installed - good!"
fi
###############################
# Enable NGinX as a Service #
###############################
sudo service nginx start
###############################
# Check the NGinX Status #
###############################
sudo service nginx status
sleep 5s
echo ""
echo ""
echo "**** Hopefully you don't see any errors above. If you do"
echo "**** please determine what caused the issue with NGinX starting,"
echo ""
echo ""
sleep 5s
################################
# Install LetsEncrypt Certbot #
################################
if ! which certbot > /dev/null 2>&1;
then
echo ""
echo ""
echo "**** Installing Certbot for LetsEncrypt Now."
sudo add-apt-repository ppa:certbot/certbot -y
sudo apt update
sudo apt install python3-certbot-nginx
else
echo ""
echo ""
echo "**** Certbot appears to already be installed - good!"
fi
################################
# Setup NGinx Reverse Proxy #
################################
echo ""
echo ""
echo "In order for NGinX to work properly, and LetsEncrypt to get certificates for your site,"
echo "you need to provide an FQDN (Fully Qualified Domain Name). This must be a domain you"
echo "own. E.g. vector.my-great-domain.com, or just my-great-domain.com if this is your top"
echo "level server. The donain must have dns to point to this server before continuing."
echo ""
echo ""
echo ""
echo "**** Creating the NGinX configuration file for this site."
echo ""
echo ""
echo "server {" >> /etc/nginx/sites-enabled/${userDomain}.conf
echo " listen 80;" >> /etc/nginx/sites-enabled/${userDomain}.conf
echo " server_name ${userDomain};" >> /etc/nginx/sites-enabled/${userDomain}.conf
echo "" >> /etc/nginx/sites-enabled/${userDomain}.conf
echo " location / {" >> /etc/nginx/sites-enabled/${userDomain}.conf
echo " proxy_pass http://127.0.0.1:5000;" >> /etc/nginx/sites-enabled/${userDomain}.conf
echo " proxy_http_version 1.1;" >> /etc/nginx/sites-enabled/${userDomain}.conf
echo " proxy_set_header Upgrade \$http_upgrade;" >> /etc/nginx/sites-enabled/${userDomain}.conf
echo " proxy_set_header Connection 'upgrade';" >> /etc/nginx/sites-enabled/${userDomain}.conf
echo " proxy_set_header Host \$host;" >> /etc/nginx/sites-enabled/${userDomain}.conf
echo " proxy_cache_bypass \$http_upgrade;" >> /etc/nginx/sites-enabled/${userDomain}.conf
echo " }" >> /etc/nginx/sites-enabled/${userDomain}.conf
echo "}" >> /etc/nginx/sites-enabled/${userDomain}.conf
sleep 10s
echo "**** Let's test our NGinX configuration."
sudo nginx -t
sleep 5s
echo ""
echo ""
echo "**** The above should have given OK and Successful results."
echo ""
echo ""
sleep 2s
echo "**** Relad NGinX Configuration and service"
echo ""
echo ""
sudo service nginx reload
sleep 2s
echo "**** Now we'll get the LetsEncrypt certificate."
echo ""
echo "**** You'll be asked for your email address, and other information during the certificate creation."
echo ""
sleep 4s
sudo certbot --nginx -d $userDomain
echo ""
echo ""
echo "**** Now let's make sure certbot can autorenew."
echo ""
echo ""
sudo certbot renew --dry-run
fi
########################################################################
#############################
# install node js using NVM #
#############################
if [ ! -d ~/.nvm ]
then
echo ""
echo "**** install nvm and node js"
curl -sSL https://raw.githubusercontent.com/creationix/nvm/v0.35.3/install.sh | bash
sleep 3s
echo ""
echo ""
# try to set the install to be used without logging out
echo "source ~/.profile attempt 1"
source ~/.profile
else
echo ""
echo ""
echo "**** NVM appears to be installed - good!"
fi
# now install the proper node version with nvm
echo ""
echo ""
. ~/.nvm/nvm.sh
source ~/.profile
echo "**** "
echo "**** "
echo "**** NOTE: NodeJS for this project is updated from 8.11.3 to 12.16.1"
echo "**** "
echo "**** "
sleep 5s
echo "**** Attempting to install NodeJS 12.16.1 usign NVM"
nvm install 12.16.1
echo ""
echo ""
sleep 2s
# now tell nvm to use the latest installed version
nvm use 12.16.1
echo ""
echo ""
sleep 1s
echo "**** check the node version we installed."
# check the node version
sleep 1s
echo "node version = "
node -v
echo ""
# install forever
if [ ! -d ~/.forever ]
then
echo "**** install forever from npm"
npm i forever -g
else
echo "**** forever appears to be already installed - good."
fi
# install mongodb
if [ ! -d ~/.mongorc.js ]
then
echo "**** install mongodb"
sudo apt install -y mongodb
else
echo ""
echo "**** MongoDB appears to be installed - good."
echo ""
fi
# install nmap
echo ""
if [ ! -f /usr/bin/nmap ]
then
echo "**** install nmap"
sudo apt install -y nmap
else
echo ""
echo "**** nmap appears to be installed - good."
echo ""
fi
echo ""
echo "**** download Vector release from github."
echo ""
sleep 2s
# get the tar file from github
wget https://github.com/bmcgonag/Vector/releases/download/0.5.0/Vector.tar.gz
echo "**** extracting Vector into Vector-Production"
echo ""
# untar the file
mkdir Vector-Production
tar -zxf Vector.tar.gz --directory ~/Vector-Production
echo "**** installing npm dependencies for Vector."
echo ""
# install npm dependencies
cd ./Vector-Production/bundle/programs/server/
npm install --production
cd ..
cd ..
# set env vars
export MONGO_URL="mongodb://127.0.0.1:27017/vector"
export ROOT_URL="http://localhost"
export PORT=5000
# start the server using forever
forever start -l forever.log -o output.log -e error.log main.js
echo ""
echo ""
echo " ********************************************************** "
echo ""
echo ""
echo "If you got any error about not finding node, run the"
echo "following commands to start your server."
echo ""
echo ""
echo "source ~/.profile"
echo ""
echo "nvm install 12.16.1"
echo ""
echo "nvm use 12.16.1"
echo ""
echo "npm i forever -g"
echo ""
echo "then re-run this start script."
echo ""
echo ""
echo " ********************************************************** "
echo ""
echo ""
echo ""