-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.sh
executable file
·330 lines (295 loc) · 9.53 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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
#! /usr/bin/env bash
## author: João Paulo <[email protected], [email protected]>
## Este script instala all-in-one o GenieACS com NGINX como reverse proxy e HTTPS para o módulo UI. Ele é um compilado da doc oficial https://docs.genieacs.com/en/latest/ e de outros sites como https://blog.remontti.com.br/. Não garanto que está pronto para usar em produção, mas dá pra brincar! :)
## Os módulos foram configurados para responder somente em localhost e por causa do reverse proxy as "portas-padrão", trocadas para responderem no NGINX.
## GenieACS UI: 127.0.0.1:3000
## GenieACS CWMP: 127.0.0.1:3001
## GenieACS NBI: 127.0.0.1:3002
## GenieACS UI: 127.0.0.1:3003
## O script foi testado no seguinte ambiente:
## - mongodb 5.0
## - Debian 11 (bullseye)
## - Proxmox 6.3-2, cpu=host
## - NodeJS 18.x LTS
set -xe
MONGODB_VERSION="5.0"
GENIEACS_VERSION="1.2.9"
export SSL_COUNTRY_NAME="BR"
export SSL_PROVINCE_NAME="PARA"
export SSL_LOCALITY_NAME="ANANINDEUA"
export SSL_ORGANIZATION_NAME="BUNEK LTDA"
export SSL_ORGANIZATION_UNIT="Centro de Cachorragens - (iNHOC)"
export SSL_COMMON_NAME="tr069.bunek.local"
export SSL_EMAIL_ADDRESS="[email protected]"
function install_pre_reqs() {
apt update && sudo apt install -y \
dirmngr \
gnupg \
apt-transport-https \
ca-certificates \
curl \
software-properties-common \
lolcat &>/dev/null # véri importante
}
function install_nodeLTS() {
if [[ ! "$(command -v node)" ]]; then
curl -fsSL https://deb.nodesource.com/setup_lts.x | bash -
apt update && apt install -y nodejs
fi
}
function install_mongodb() {
if [[ ! "$(command -v mongo)" ]]; then
curl -fsSL https://pgp.mongodb.com/server-$MONGODB_VERSION.pub | \
gpg --dearmour | \
tee /etc/apt/trusted.gpg.d/mongodb-org-$MONGODB_VERSION.gpg >/dev/null
echo "deb [signed-by=/etc/apt/trusted.gpg.d/mongodb-org-$MONGODB_VERSION.gpg] http://repo.mongodb.org/apt/debian bullseye/mongodb-org/5.0 main" | tee /etc/apt/sources.list.d/mongodb-org-$MONGODB_VERSION.list >/dev/null
apt update && apt install -y mongodb-org
systemctl enable --now mongod
systemctl status mongod --no-pager | /usr/games/lolcat
sleep 5
mongo --eval 'db.runCommand({ connectionStatus: 1 })' | /usr/games/lolcat
fi
}
function install_genieacs() {
npm install -g genieacs@$GENIEACS_VERSION
useradd --system --no-create-home --user-group genieacs || true
mkdir -p /opt/genieacs
mkdir -p /opt/genieacs/ext
cat << EOF > /opt/genieacs/genieacs-ui.env
NODE_OPTIONS="--enable-source-maps UV_THREADPOOL_SIZE=12 max_old_space_size=4096"
GENIEACS_UI_INTERFACE=127.0.0.1
GENIEACS_UI_PORT=3000
GENIEACS_UI_ACCESS_LOG_FILE=/var/log/genieacs/genieacs-ui-access.log
GENIEACS_DEBUG_FILE=/var/log/genieacs/genieacs-debug.yaml
GENIEACS_EXT_DIR=/opt/genieacs/ext
GENIEACS_EXT_TIMEOUT=15000
GENIEACS_MAX_COMMIT_ITERATIONS=1000
GENIEACS_MAX_CONCURRENT_REQUESTS=2000
#GENIEACS_MAX_DEPTH=32
EOF
node -e "console.log(\"GENIEACS_UI_JWT_SECRET=\" + require('crypto').randomBytes(128).toString('hex'))" >> /opt/genieacs/genieacs-ui.env
cat << EOF > /opt/genieacs/genieacs-cwmp.env
NODE_OPTIONS="--enable-source-maps UV_THREADPOOL_SIZE=12 max_old_space_size=4096"
GENIEACS_CWMP_INTERFACE=127.0.0.1
GENIEACS_CWMP_PORT=3001
GENIEACS_CWMP_ACCESS_LOG_FILE=/var/log/genieacs/genieacs-cwmp-access.log
GENIEACS_DEBUG_FILE=/var/log/genieacs/genieacs-debug.yaml
GENIEACS_EXT_DIR=/opt/genieacs/ext
GENIEACS_EXT_TIMEOUT=15000
GENIEACS_MAX_COMMIT_ITERATIONS=1000
GENIEACS_MAX_CONCURRENT_REQUESTS=2000
#GENIEACS_MAX_DEPTH=32
EOF
cat << EOF > /opt/genieacs/genieacs-nbi.env
NODE_OPTIONS="--enable-source-maps UV_THREADPOOL_SIZE=12 max_old_space_size=4096"
GENIEACS_NBI_INTERFACE=127.0.0.1
GENIEACS_NBI_PORT=3002
GENIEACS_NBI_ACCESS_LOG_FILE=/var/log/genieacs/genieacs-nbi-access.log
GENIEACS_DEBUG_FILE=/var/log/genieacs/genieacs-debug.yaml
GENIEACS_EXT_DIR=/opt/genieacs/ext
GENIEACS_EXT_TIMEOUT=15000
GENIEACS_MAX_COMMIT_ITERATIONS=1000
GENIEACS_MAX_CONCURRENT_REQUESTS=2000
#GENIEACS_MAX_DEPTH=32
EOF
cat << EOF > /opt/genieacs/genieacs-fs.env
NODE_OPTIONS="--enable-source-maps UV_THREADPOOL_SIZE=12 max_old_space_size=4096"
GENIEACS_FS_INTERFACE=127.0.0.1
GENIEACS_FS_PORT=3003
GENIEACS_FS_ACCESS_LOG_FILE=/var/log/genieacs/genieacs-fs-access.log
GENIEACS_DEBUG_FILE=/var/log/genieacs/genieacs-debug.yaml
GENIEACS_EXT_DIR=/opt/genieacs/ext
GENIEACS_EXT_TIMEOUT=15000
GENIEACS_MAX_COMMIT_ITERATIONS=1000
GENIEACS_MAX_CONCURRENT_REQUESTS=2000
#GENIEACS_MAX_DEPTH=32
EOF
chown -R genieacs. /opt/genieacs
chmod 600 /opt/genieacs/genieacs-ui.env
chmod 600 /opt/genieacs/genieacs-cwmp.env
chmod 600 /opt/genieacs/genieacs-nbi.env
chmod 600 /opt/genieacs/genieacs-fs.env
mkdir -p /var/log/genieacs
chown genieacs. /var/log/genieacs
}
# create systemd unit files
function create_unit_files() {
## UI
cat << EOF > /etc/systemd/system/genieacs-ui.service
[Unit]
Description=GenieACS UI
After=network.target
[Service]
User=genieacs
EnvironmentFile=/opt/genieacs/genieacs-ui.env
ExecStart=/usr/bin/genieacs-ui
[Install]
WantedBy=default.target
EOF
## CWMP
cat << EOF > /etc/systemd/system/genieacs-cwmp.service
[Unit]
Description=GenieACS CWMP
After=network.target
[Service]
User=genieacs
EnvironmentFile=/opt/genieacs/genieacs-cwmp.env
ExecStart=/usr/bin/genieacs-cwmp
[Install]
WantedBy=default.target
EOF
## NBI
cat << EOF > /etc/systemd/system/genieacs-nbi.service
[Unit]
Description=GenieACS NBI
After=network.target
[Service]
User=genieacs
EnvironmentFile=/opt/genieacs/genieacs-nbi.env
ExecStart=/usr/bin/genieacs-nbi
[Install]
WantedBy=default.target
EOF
## FS
cat << EOF > /etc/systemd/system/genieacs-fs.service
[Unit]
Description=GenieACS FS
After=network.target
[Service]
User=genieacs
EnvironmentFile=/opt/genieacs/genieacs-fs.env
ExecStart=/usr/bin/genieacs-fs
[Install]
WantedBy=default.target
EOF
}
function config_log_rotation() {
cat << EOF > /etc/logrotate.d/genieacs
/var/log/genieacs/*.log /var/log/genieacs/*.yaml {
daily
rotate 30
compress
delaycompress
dateext
}
EOF
}
function restart_services() {
echo "Finishing GenieACS install...."
systemctl daemon-reload
systemctl enable genieacs-{cwmp,fs,ui,nbi}
sleep 2
systemctl start genieacs-{cwmp,fs,ui,nbi}
sleep 2
# systemctl enable nginx
sleep 2
systemctl restart nginx
sleep 2
systemctl status nginx --no-pager | /usr/games/lolcat
systemctl status genieacs-{cwmp,fs,ui,nbi} --no-pager | /usr/games/lolcat
}
function install_nginx() {
apt install -y nginx
openssl req \
-new \
-newkey rsa:4096 \
-days 365 \
-nodes \
-x509 \
-subj "/C=$SSL_COUNTRY_NAME/ST=$SSL_PROVINCE_NAME/L=$SSL_LOCALITY_NAME/O=$SSL_ORGANIZATION_NAME/OU=$SSL_ORGANIZATION_UNIT/CN=$SSL_COMMON_NAME" \
-keyout /etc/ssl/private/genieacs-ui.key \
-out /etc/ssl/certs/genieacs-ui.crt
rm -f /etc/nginx/sites-available/default
rm -f /etc/nginx/sites-enabled/default
cat << EOF > /etc/nginx/sites-available/genieacs
# redirect UI to https
server {
listen 80;
# listen [::]:80;
server_name \$host;
return 301 https://\$host\$request_uri;
}
# UI https
server {
listen 443 ssl;
server_name \$host;
ssl_certificate /etc/ssl/certs/genieacs-ui.crt;
ssl_certificate_key /etc/ssl/private/genieacs-ui.key;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
# proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
# proxy_set_header X-Forwarded-Proto \$scheme;
# proxy_read_timeout 3600;
# proxy_pass_request_headers on;
# para subir firmware maior que 1MB na UI do GenieACS
client_max_body_size 100M;
}
}
# CWMP
server {
listen 7547;
listen [::]:7547;
server_name \$host;
location / {
proxy_pass http://127.0.0.1:3001;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
# proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
# proxy_set_header X-Forwarded-Proto \$scheme;
# proxy_read_timeout 3600;
# proxy_pass_request_headers on;
}
}
# NBI
server {
listen 7557;
listen [::]:7557;
server_name \$host;
location / {
proxy_pass http://127.0.0.1:3002;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
# proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
# proxy_set_header X-Forwarded-Proto \$scheme;
# proxy_read_timeout 3600;
# proxy_pass_request_headers on;
}
}
# FS
server {
listen 7567;
listen [::]:7567;
server_name \$host;
location / {
proxy_pass http://127.0.0.1:3003;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
# proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
# proxy_set_header X-Forwarded-Proto \$scheme;
# proxy_read_timeout 3600;
# proxy_pass_request_headers on;
}
}
EOF
ln -fs /etc/nginx/sites-available/genieacs /etc/nginx/sites-enabled/genieacs
}
install_pre_reqs
install_nodeLTS
install_mongodb
install_genieacs
create_unit_files
config_log_rotation
install_nginx
restart_services
IPv4=$(ip -4 addr | grep -i inet | grep "scope global" | awk '{print $2}' | cut -d'/' -f1)
echo "#### GenieACS UI access: https://$IPv4 ####" | /usr/games/lolcat
unset SSL_COUNTRY_NAME
unset SSL_PROVINCE_NAME
unset SSL_LOCALITY_NAME
unset SSL_ORGANIZATION_NAME
unset SSL_ORGANIZATION_UNIT
unset SSL_COMMON_NAME
unset SSL_EMAIL_ADDRESS
unset IPv4