@drumee/setup-infra 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +661 -0
- package/README.md +3 -0
- package/configs/etc/cron.d/drumee +6 -0
- package/configs/etc/postfix/master.cf +137 -0
- package/congigure/init/acme +69 -0
- package/congigure/init/mail +16 -0
- package/congigure/init/named +27 -0
- package/congigure/menu/menu -tmp +144 -0
- package/congigure/menu/menu-install +147 -0
- package/congigure/menu/menu-reinstall +15 -0
- package/congigure/prepare +10 -0
- package/congigure/preset/jitsi +9 -0
- package/congigure/setup-infra +58 -0
- package/congigure/setup-schemas +57 -0
- package/congigure/start +29 -0
- package/congigure/utils/configure +56 -0
- package/congigure/utils/dependencies +90 -0
- package/congigure/utils/jitsi +122 -0
- package/congigure/utils/misc +77 -0
- package/congigure/utils/prompt.sh +35 -0
- package/congigure/utils/setup-versions +7 -0
- package/index.js +572 -0
- package/package.json +30 -0
- package/template.js +453 -0
- package/templates/env/application.json.tpl +0 -0
- package/templates/env/logrotate.tpl +7 -0
- package/templates/etc/bind/named.conf.local +13 -0
- package/templates/etc/bind/named.conf.log +105 -0
- package/templates/etc/bind/named.conf.options +33 -0
- package/templates/etc/dkimkeys/dkim.key +1 -0
- package/templates/etc/drumee/conf.d/conference.json.tpl +9 -0
- package/templates/etc/drumee/conf.d/drumee.json.tpl +7 -0
- package/templates/etc/drumee/conf.d/exchange.json.tpl +4 -0
- package/templates/etc/drumee/conf.d/myDrumee.json.tpl +16 -0
- package/templates/etc/drumee/credential/db.json.tpl +6 -0
- package/templates/etc/drumee/credential/email.json.tpl +12 -0
- package/templates/etc/drumee/credential/ovh/dns.json.tpl +6 -0
- package/templates/etc/drumee/credential/ovh/dns.sh.tpl +7 -0
- package/templates/etc/drumee/credential/redis.json.tpl +6 -0
- package/templates/etc/drumee/credential/sms.json.tpl +6 -0
- package/templates/etc/drumee/dnsapi.sh.tpl +28 -0
- package/templates/etc/drumee/drumee.sh.tpl +43 -0
- package/templates/etc/drumee/env.json +29 -0
- package/templates/etc/drumee/infrastructure/internals/accel.conf.tpl +47 -0
- package/templates/etc/drumee/infrastructure/mfs.conf.tpl +16 -0
- package/templates/etc/drumee/infrastructure/platform.json.tpl +16 -0
- package/templates/etc/drumee/infrastructure/routes/main.conf.tpl +143 -0
- package/templates/etc/drumee/infrastructure/servers/tt.conf +199 -0
- package/templates/etc/drumee/ssl/main.conf.tpl +10 -0
- package/templates/etc/jitsi/jicofo/config +2 -0
- package/templates/etc/jitsi/jicofo/defaults/jicofo.conf +225 -0
- package/templates/etc/jitsi/jicofo/defaults/logging.properties +15 -0
- package/templates/etc/jitsi/jicofo/jicofo.conf.tpl +46 -0
- package/templates/etc/jitsi/jicofo/logging.properties.tpl +12 -0
- package/templates/etc/jitsi/meet.conf.tpl +131 -0
- package/templates/etc/jitsi/ssl.conf.tpl +25 -0
- package/templates/etc/jitsi/videobridge/config +2 -0
- package/templates/etc/jitsi/videobridge/defaults/jvb.conf +129 -0
- package/templates/etc/jitsi/videobridge/defaults/logging.properties +12 -0
- package/templates/etc/jitsi/videobridge/jvb.conf +67 -0
- package/templates/etc/jitsi/videobridge/logging.properties.tpl +12 -0
- package/templates/etc/jitsi/web/config.js.tpl +208 -0
- package/templates/etc/jitsi/web/defaults/default +26 -0
- package/templates/etc/jitsi/web/defaults/ffdhe2048.txt +8 -0
- package/templates/etc/jitsi/web/defaults/interface_config.js +273 -0
- package/templates/etc/jitsi/web/defaults/meet.conf +193 -0
- package/templates/etc/jitsi/web/defaults/nginx.conf +73 -0
- package/templates/etc/jitsi/web/defaults/settings-config.js +480 -0
- package/templates/etc/jitsi/web/defaults/ssl.conf +28 -0
- package/templates/etc/jitsi/web/defaults/system-config.js +60 -0
- package/templates/etc/jitsi/web/interface_config.js +273 -0
- package/templates/etc/mail/dkim.key +1 -0
- package/templates/etc/mailname +1 -0
- package/templates/etc/mysql/mariadb.conf.d/50-server.cnf +120 -0
- package/templates/etc/nginx/modules-enabled/90-turn-relay.conf +27 -0
- package/templates/etc/nginx/modules-enabled/90-turn-relay.conf.tpl +27 -0
- package/templates/etc/nginx/nginx.conf +65 -0
- package/templates/etc/nginx/sites-enabled/drumee.conf.tpl +33 -0
- package/templates/etc/nginx/sites-enabled/jitsi.conf.tpl +28 -0
- package/templates/etc/nginx/sites-enabled/turnrelay.conf.tpl +9 -0
- package/templates/etc/opendkim/KeyTable +1 -0
- package/templates/etc/postfix/main.cf +76 -0
- package/templates/etc/postfix/mysql-virtual-alias-maps.cf +5 -0
- package/templates/etc/postfix/mysql-virtual-mailbox-domains.cf +5 -0
- package/templates/etc/postfix/mysql-virtual-mailbox-maps.cf +5 -0
- package/templates/etc/prosody/conf.d/vhost.cfg.lua.tpl +162 -0
- package/templates/etc/prosody/defaults/conf.d/jitsi-meet.cfg.lua +406 -0
- package/templates/etc/prosody/defaults/credentials.sh +10 -0
- package/templates/etc/prosody/defaults/prosody.cfg.lua +225 -0
- package/templates/etc/prosody/defaults/saslauthd.conf +30 -0
- package/templates/etc/prosody/prosody.cfg.lua.tpl +203 -0
- package/templates/etc/turnserver.conf.tpl +46 -0
- package/templates/index.js +102 -0
- package/templates/schema/utils/configs.init.sql.tpl +20 -0
- package/templates/schema/utils/configs.update.sql.tpl +19 -0
- package/templates/server/ecosystem.config.js.tpl +8 -0
- package/templates/var/lib/bind/domain.tpl +70 -0
package/index.js
ADDED
|
@@ -0,0 +1,572 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const Template = require("./templates");
|
|
4
|
+
const { writeFileSync } = require(`jsonfile`);
|
|
5
|
+
const { join, dirname } = require("path");
|
|
6
|
+
const { isString } = require("lodash");
|
|
7
|
+
const { exit } = process;
|
|
8
|
+
const { sysEnv, uniqueId } = require("@drumee/server-essentials");
|
|
9
|
+
const { totalmem } = require('os');
|
|
10
|
+
const ARGV = require('minimist')(process.argv.slice(2));
|
|
11
|
+
const {
|
|
12
|
+
existsSync, close, writeSync, openSync, readFileSync, mkdirSync
|
|
13
|
+
} = require("fs");
|
|
14
|
+
|
|
15
|
+
const JSON_OPT = { spaces: 2, EOL: "\r\n" };
|
|
16
|
+
|
|
17
|
+
const {
|
|
18
|
+
ACME_DIR,
|
|
19
|
+
ACME_EMAIL_ACCOUNT,
|
|
20
|
+
ADMIN_EMAIL,
|
|
21
|
+
DB_BACKUP,
|
|
22
|
+
DRUMEE_DB_DIR,
|
|
23
|
+
DRUMEE_DESCRIPTION,
|
|
24
|
+
DRUMEE_DOMAIN_NAME,
|
|
25
|
+
FORCE_INSTALL,
|
|
26
|
+
MAIL_USER,
|
|
27
|
+
MAX_BODY_SIZE,
|
|
28
|
+
NSUPDATE_KEY,
|
|
29
|
+
PUBLIC_IP4,
|
|
30
|
+
PUBLIC_IP6,
|
|
31
|
+
BACKUP_LOCATION,
|
|
32
|
+
} = process.env;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
*
|
|
36
|
+
* @param {*} l
|
|
37
|
+
* @returns
|
|
38
|
+
*/
|
|
39
|
+
function randomString(l = 16) {
|
|
40
|
+
let crypto = require("crypto");
|
|
41
|
+
return crypto
|
|
42
|
+
.randomBytes(16)
|
|
43
|
+
.toString("base64")
|
|
44
|
+
.replace(/[\+\/=]+/g, "");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
*
|
|
49
|
+
* @param {*} data
|
|
50
|
+
* @returns
|
|
51
|
+
*/
|
|
52
|
+
function copyFields(data, keys) {
|
|
53
|
+
let r = {};
|
|
54
|
+
for (let key of keys) {
|
|
55
|
+
if (data[key] !== null) {
|
|
56
|
+
r[key] = data[key];
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return r;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
*
|
|
64
|
+
* @param {*} data
|
|
65
|
+
* @returns
|
|
66
|
+
*/
|
|
67
|
+
function factory(data) {
|
|
68
|
+
let route = "main";
|
|
69
|
+
let mode = "dist";
|
|
70
|
+
let base = `${data.server_dir}/${mode}/${route}/`;
|
|
71
|
+
return {
|
|
72
|
+
name: "factory",
|
|
73
|
+
script: `./index.js`,
|
|
74
|
+
autorestart: false,
|
|
75
|
+
cwd: `${base}/offline/factory`,
|
|
76
|
+
env: copyFields(data, [
|
|
77
|
+
"domain_name",
|
|
78
|
+
"domain_desc",
|
|
79
|
+
"data_dir",
|
|
80
|
+
"system_user",
|
|
81
|
+
"system_group",
|
|
82
|
+
"drumee_root",
|
|
83
|
+
"cache_dir",
|
|
84
|
+
"acme_dir",
|
|
85
|
+
"acme_dns",
|
|
86
|
+
"acme_email_account",
|
|
87
|
+
"static_dir",
|
|
88
|
+
"runtime_dir",
|
|
89
|
+
"credential_dir",
|
|
90
|
+
]),
|
|
91
|
+
dependencies: [`pm2-logrotate`],
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
*
|
|
97
|
+
* @param {*} data
|
|
98
|
+
* @returns
|
|
99
|
+
*/
|
|
100
|
+
function worker(data, instances = 1, exec_mode = 'fork_mode') {
|
|
101
|
+
let {
|
|
102
|
+
script,
|
|
103
|
+
pushPort,
|
|
104
|
+
route,
|
|
105
|
+
restPort,
|
|
106
|
+
name,
|
|
107
|
+
server_dir,
|
|
108
|
+
runtime_dir,
|
|
109
|
+
mode,
|
|
110
|
+
} = data;
|
|
111
|
+
if (!server_dir) server_dir = join(runtime_dir, 'server');
|
|
112
|
+
let base = `${server_dir}/${mode}/${route}`;
|
|
113
|
+
return {
|
|
114
|
+
name,
|
|
115
|
+
script,
|
|
116
|
+
cwd: base,
|
|
117
|
+
args: `--pushPort=${pushPort} --restPort=${restPort}`,
|
|
118
|
+
route,
|
|
119
|
+
env: {
|
|
120
|
+
cwd: base,
|
|
121
|
+
route,
|
|
122
|
+
server_home: base,
|
|
123
|
+
},
|
|
124
|
+
dependencies: [`pm2-logrotate`],
|
|
125
|
+
exec_mode,
|
|
126
|
+
instances
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/***
|
|
131
|
+
*
|
|
132
|
+
*/
|
|
133
|
+
function writeTemplates(data, targets) {
|
|
134
|
+
if (ARGV.readonly || ARGV.noCheck) {
|
|
135
|
+
console.log("Readonly", targets, data);
|
|
136
|
+
return
|
|
137
|
+
}
|
|
138
|
+
for (let target of targets) {
|
|
139
|
+
if (isString(target)) {
|
|
140
|
+
Template.write(data, target, target);
|
|
141
|
+
} else {
|
|
142
|
+
let { out, tpl } = target;
|
|
143
|
+
Template.write(data, out, tpl);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
*
|
|
150
|
+
*/
|
|
151
|
+
function writeEcoSystem(data) {
|
|
152
|
+
const ports = {
|
|
153
|
+
pushPort: 23000,
|
|
154
|
+
restPort: 24000,
|
|
155
|
+
mode: "dist",
|
|
156
|
+
route: "main",
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
let main = worker({
|
|
160
|
+
...data,
|
|
161
|
+
...ports,
|
|
162
|
+
name: "main",
|
|
163
|
+
script: "./index.js",
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
let instances = 4;
|
|
167
|
+
if ((totalmem() / (1024 * 1024 * 1024)) < 2) {
|
|
168
|
+
instances = 2;
|
|
169
|
+
} else if ((totalmem() / (1024 * 1024 * 1024) < 6)) {
|
|
170
|
+
instances = 3;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
let main_service = worker({
|
|
174
|
+
...data,
|
|
175
|
+
...ports,
|
|
176
|
+
name: "main/service",
|
|
177
|
+
script: "./service.js"
|
|
178
|
+
}, instances, 'cluster_mode');
|
|
179
|
+
|
|
180
|
+
let f = factory(data);
|
|
181
|
+
let routes = [main, main_service, f];
|
|
182
|
+
let ecosystem = "/etc/drumee/infrastructure/ecosystem.json";
|
|
183
|
+
if (ARGV.readonly) {
|
|
184
|
+
console.log("Readonly", ecosystem, routes);
|
|
185
|
+
return
|
|
186
|
+
}
|
|
187
|
+
writeFileSync(ecosystem, routes, JSON_OPT);
|
|
188
|
+
let targets = [
|
|
189
|
+
{
|
|
190
|
+
out: `${data.server_dir}/ecosystem.config.js`,
|
|
191
|
+
tpl: "server/ecosystem.config.js",
|
|
192
|
+
},
|
|
193
|
+
];
|
|
194
|
+
writeTemplates({ ecosystem, chroot: Template.chroot }, targets);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function getSocketPath() {
|
|
198
|
+
const { exec } = require("shelljs");
|
|
199
|
+
let socketPath = "/var/run/mysqld/mysqld.sock";
|
|
200
|
+
try {
|
|
201
|
+
socketPath = exec(`mariadb_config --socket`, {
|
|
202
|
+
silent: true,
|
|
203
|
+
}).stdout;
|
|
204
|
+
if (socketPath) {
|
|
205
|
+
socketPath = socketPath.trim();
|
|
206
|
+
}
|
|
207
|
+
} finally {
|
|
208
|
+
}
|
|
209
|
+
return socketPath;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function makeData(opt) {
|
|
213
|
+
let data = sysEnv();
|
|
214
|
+
|
|
215
|
+
data.chroot = Template.chroot();
|
|
216
|
+
data.acme_store = join(data.certs_dir, `${data.domain_name}_ecc`);
|
|
217
|
+
data.ca_server = data.ca_server || data.acme_ssl;
|
|
218
|
+
if (data.own_ssl && data.certs_dir) {
|
|
219
|
+
data.own_certs_dir = data.certs_dir;
|
|
220
|
+
}
|
|
221
|
+
for (let row of opt) {
|
|
222
|
+
let [key, value, fallback] = row;
|
|
223
|
+
if (!data[key]) {
|
|
224
|
+
if (/.+\+$/.test(value)) {
|
|
225
|
+
value = value.replace(/\+$/, data[key]);
|
|
226
|
+
}
|
|
227
|
+
data[key] = value || fallback;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return data;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
*
|
|
234
|
+
*/
|
|
235
|
+
function getSysConfigs() {
|
|
236
|
+
let { domain_name } = sysEnv();
|
|
237
|
+
if (existsSync('/etc/drumee/drumee.sh') && !FORCE_INSTALL) {
|
|
238
|
+
console.log(
|
|
239
|
+
`There is already a domain name configured on this server (${domain_name})\n`, `Use FORCE_INSTALL=yes to override`);
|
|
240
|
+
exit(0)
|
|
241
|
+
}
|
|
242
|
+
domain_name = domain_name || ARGV.domain || DRUMEE_DOMAIN_NAME;
|
|
243
|
+
if (!domain_name) {
|
|
244
|
+
console.log("There no domain name defined for the installation");
|
|
245
|
+
exit(0)
|
|
246
|
+
}
|
|
247
|
+
const opt = [
|
|
248
|
+
["acme_dir", ACME_DIR, '/usr/share/acme'],
|
|
249
|
+
["jitsi_domain", `jit.+`],
|
|
250
|
+
["domain_name", domain_name],
|
|
251
|
+
["nsupdate_key", NSUPDATE_KEY, '/etc/bind/keys/update.key'],
|
|
252
|
+
["domain_desc", DRUMEE_DESCRIPTION, 'My Drumee Box'],
|
|
253
|
+
["admin_email", ADMIN_EMAIL, ''],
|
|
254
|
+
["acme_email_account", ACME_EMAIL_ACCOUNT, ADMIN_EMAIL],
|
|
255
|
+
["public_ip4", PUBLIC_IP4, ''],
|
|
256
|
+
["public_ip6", PUBLIC_IP6, ''],
|
|
257
|
+
["backup_location", BACKUP_LOCATION, ''],
|
|
258
|
+
["db_backup", DB_BACKUP, ''],
|
|
259
|
+
["db_dir", DRUMEE_DB_DIR, '/srv/db'],
|
|
260
|
+
["max_body_size", MAX_BODY_SIZE, '10G'],
|
|
261
|
+
]
|
|
262
|
+
let data = makeData(opt)
|
|
263
|
+
let d = new Date().toISOString();
|
|
264
|
+
let [day, hour] = d.split('T')
|
|
265
|
+
day = day.replace(/\-/g, '');
|
|
266
|
+
hour = hour.split(':')[0];
|
|
267
|
+
data.serial = `${day}${hour}`;
|
|
268
|
+
|
|
269
|
+
let args = { ...data };
|
|
270
|
+
let keys = ["myConf", "chroot", "date"];
|
|
271
|
+
|
|
272
|
+
for (let key of keys) {
|
|
273
|
+
delete args[key];
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
if (ARGV.readonly) {
|
|
277
|
+
return args;
|
|
278
|
+
}
|
|
279
|
+
args.socketPath = getSocketPath();
|
|
280
|
+
console.log("Writing main conf into drumee.json");
|
|
281
|
+
writeFileSync(
|
|
282
|
+
Template.chroot("etc/drumee/drumee.json"), args, JSON_OPT
|
|
283
|
+
);
|
|
284
|
+
return args;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
*
|
|
289
|
+
* @param {*} data
|
|
290
|
+
*/
|
|
291
|
+
function writeCredentials(file, data) {
|
|
292
|
+
let target = Template.chroot(`etc/drumee/credential/${file}.json`);
|
|
293
|
+
console.log(`Writing credentials into ${target}`);
|
|
294
|
+
writeFileSync(target, data, JSON_OPT);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
*
|
|
299
|
+
*/
|
|
300
|
+
function errorHandler(err) {
|
|
301
|
+
console.error("Caught error", err);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
*
|
|
306
|
+
* @param {*} data
|
|
307
|
+
*/
|
|
308
|
+
function copyConfigs(items) {
|
|
309
|
+
for (let item of items) {
|
|
310
|
+
let p = join(__dirname, 'configs', item);
|
|
311
|
+
console.log(`Copying ${item}`)
|
|
312
|
+
let dname = dirname(p);
|
|
313
|
+
mkdirSync(dname, { recursive: true });
|
|
314
|
+
let content = readFileSync(p);
|
|
315
|
+
let str = String(content).toString();
|
|
316
|
+
//Buffer.from(content, "utf8");
|
|
317
|
+
let dest = Template.chroot(item);
|
|
318
|
+
let fd = openSync(dest, "w+");
|
|
319
|
+
writeSync(fd, str);
|
|
320
|
+
close(fd, errorHandler);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
*
|
|
326
|
+
* @param {*} data
|
|
327
|
+
*/
|
|
328
|
+
function getDkim(file) {
|
|
329
|
+
let p = Template.chroot(file);
|
|
330
|
+
let content = readFileSync(p);
|
|
331
|
+
let str = Buffer.from(content, "utf8");
|
|
332
|
+
let v = `v=DKIM1; k=rsa; p=${str.toString()}`;
|
|
333
|
+
let r = [];
|
|
334
|
+
let start = 0;
|
|
335
|
+
let end = 80;
|
|
336
|
+
let t = v.slice(start, end);;
|
|
337
|
+
|
|
338
|
+
while (t.length) {
|
|
339
|
+
t = v.slice(start, end);
|
|
340
|
+
if (t.length) {
|
|
341
|
+
r.push(`"${t}"`)
|
|
342
|
+
}
|
|
343
|
+
start = end;
|
|
344
|
+
end = end + 80;
|
|
345
|
+
}
|
|
346
|
+
return r.join('\n');
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
*
|
|
352
|
+
*/
|
|
353
|
+
function writeInfraConf(data) {
|
|
354
|
+
writeEcoSystem(data);
|
|
355
|
+
const etc = 'etc';
|
|
356
|
+
const nginx = join(etc, 'nginx');
|
|
357
|
+
const drumee = join(etc, 'drumee');
|
|
358
|
+
const bind = join(etc, 'bind',);
|
|
359
|
+
const postfix = join(etc, 'postfix',);
|
|
360
|
+
const mariadb = join(etc, 'mysql', 'mariadb.conf.d');
|
|
361
|
+
const infra = join(drumee, 'infrastructure');
|
|
362
|
+
const { domain } = data;
|
|
363
|
+
const dkim = join(etc, 'opendkim', 'keys', domain, 'dkim.txt');
|
|
364
|
+
let targets = [
|
|
365
|
+
|
|
366
|
+
// Nginx
|
|
367
|
+
`${nginx}/sites-enabled/drumee.conf`,
|
|
368
|
+
|
|
369
|
+
// Drumee
|
|
370
|
+
`${drumee}/ssl/main.conf`,
|
|
371
|
+
`${drumee}/drumee.sh`,
|
|
372
|
+
`${drumee}/conf.d/conference.json`,
|
|
373
|
+
`${drumee}/conf.d/drumee.json`,
|
|
374
|
+
`${drumee}/conf.d/exchange.json`,
|
|
375
|
+
`${drumee}/conf.d/myDrumee.json`,
|
|
376
|
+
`${drumee}/conf.d/conference.json`,
|
|
377
|
+
`${drumee}/conf.d/drumee.json`,
|
|
378
|
+
`${drumee}/conf.d/myDrumee.json`,
|
|
379
|
+
|
|
380
|
+
`${infra}/mfs.conf`,
|
|
381
|
+
`${infra}/routes/main.conf`,
|
|
382
|
+
`${infra}/internals/accel.conf`,
|
|
383
|
+
{
|
|
384
|
+
tpl: `var/lib/bind/domain.tpl`,
|
|
385
|
+
out: `var/lib/bind/${domain}`
|
|
386
|
+
},
|
|
387
|
+
`${bind}/named.conf.local`,
|
|
388
|
+
`${bind}/named.conf.log`,
|
|
389
|
+
`${bind}/named.conf.options`,
|
|
390
|
+
`${postfix}/main.cf`,
|
|
391
|
+
`${postfix}/mysql-virtual-alias-maps.cf`,
|
|
392
|
+
`${postfix}/mysql-virtual-mailbox-domains.cf`,
|
|
393
|
+
`${postfix}/mysql-virtual-mailbox-maps.cf`,
|
|
394
|
+
`${etc}/dkimkeys/dkim.key`,
|
|
395
|
+
`${etc}/mail/dkim.key`,
|
|
396
|
+
`${etc}/mailname`,
|
|
397
|
+
`${etc}/opendkim/KeyTable`,
|
|
398
|
+
`${mariadb}/50-server.cnf`,
|
|
399
|
+
];
|
|
400
|
+
|
|
401
|
+
data.dkim_key = getDkim(dkim);
|
|
402
|
+
data.mail_user = MAIL_USER || 'postfix';
|
|
403
|
+
data.mail_password = uniqueId();
|
|
404
|
+
data.smptd_cache_db = "btree:$";
|
|
405
|
+
data.endpoint = 'main';
|
|
406
|
+
writeTemplates(data, targets);
|
|
407
|
+
|
|
408
|
+
writeCredentials("postfix", {
|
|
409
|
+
host: 'localhost',
|
|
410
|
+
user: data.mail_user,
|
|
411
|
+
password: data.mail_password,
|
|
412
|
+
})
|
|
413
|
+
|
|
414
|
+
writeCredentials("db", {
|
|
415
|
+
password: uniqueId(),
|
|
416
|
+
user: "drumee-app",
|
|
417
|
+
host: "localhost",
|
|
418
|
+
})
|
|
419
|
+
|
|
420
|
+
writeCredentials("email", {
|
|
421
|
+
host: `localhost`,
|
|
422
|
+
port: 587,
|
|
423
|
+
secure: false,
|
|
424
|
+
auth: {
|
|
425
|
+
user: `butler@${domain}`,
|
|
426
|
+
pass: uniqueId()
|
|
427
|
+
},
|
|
428
|
+
tls: {
|
|
429
|
+
rejectUnauthorized: false
|
|
430
|
+
}
|
|
431
|
+
})
|
|
432
|
+
|
|
433
|
+
copyConfigs(['etc/postfix/master.cf', 'etc/cron.d/drumee'])
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
*
|
|
438
|
+
*/
|
|
439
|
+
function writeJitsiConf(data) {
|
|
440
|
+
const etc = 'etc';
|
|
441
|
+
const jitsi = join(etc, 'jitsi');
|
|
442
|
+
const nginx = join(etc, 'nginx');
|
|
443
|
+
const prosody = join(etc, 'prosody');
|
|
444
|
+
const drumee = join(etc, 'drumee');
|
|
445
|
+
let targets = [
|
|
446
|
+
// Jicofo
|
|
447
|
+
`${jitsi}/jicofo/config`,
|
|
448
|
+
`${jitsi}/jicofo/jicofo.conf`,
|
|
449
|
+
`${jitsi}/jicofo/logging.properties`,
|
|
450
|
+
|
|
451
|
+
// Jitsi Video Bridge
|
|
452
|
+
`${jitsi}/videobridge/config`,
|
|
453
|
+
`${jitsi}/videobridge/jvb.conf`,
|
|
454
|
+
`${jitsi}/videobridge/logging.properties`,
|
|
455
|
+
|
|
456
|
+
// Jitsi meet
|
|
457
|
+
`${jitsi}/ssl.conf`,
|
|
458
|
+
`${jitsi}/meet.conf`,
|
|
459
|
+
`${jitsi}/web/config.js`,
|
|
460
|
+
`${jitsi}/web/interface_config.js`,
|
|
461
|
+
`${jitsi}/web/defaults/ffdhe2048.txt`,
|
|
462
|
+
|
|
463
|
+
// Nginx
|
|
464
|
+
`${nginx}/sites-enabled/jitsi.conf`,
|
|
465
|
+
`${nginx}/modules-enabled/90-turn-relay.conf`,
|
|
466
|
+
//`${nginx}/sites-enabled/turnrelay.conf`,
|
|
467
|
+
|
|
468
|
+
// Prosody
|
|
469
|
+
`${prosody}/prosody.cfg.lua`,
|
|
470
|
+
`${prosody}/defaults/credentials.sh`,
|
|
471
|
+
{
|
|
472
|
+
out: `${prosody}/conf.d/${data.jitsi_domain}.cfg.lua`,
|
|
473
|
+
tpl: `${prosody}/conf.d/vhost.cfg.lua`
|
|
474
|
+
},
|
|
475
|
+
// `${prosody}/migrator.cfg.lua`,
|
|
476
|
+
|
|
477
|
+
// Turnserver
|
|
478
|
+
`${etc}/turnserver.conf`,
|
|
479
|
+
|
|
480
|
+
`${drumee}/conf.d/conference.json`,
|
|
481
|
+
];
|
|
482
|
+
writeTemplates(data, targets);
|
|
483
|
+
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
*
|
|
488
|
+
*/
|
|
489
|
+
function makeConfData(data) {
|
|
490
|
+
data = {
|
|
491
|
+
...data,
|
|
492
|
+
turn_sercret: randomString(),
|
|
493
|
+
prosody_plugins: "/usr/share/jitsi-meet/prosody-plugins/",
|
|
494
|
+
xmpp_password: randomString(),
|
|
495
|
+
public_port: 9090,
|
|
496
|
+
ice_port: 10000,
|
|
497
|
+
jicofo_password: randomString(),
|
|
498
|
+
jvb_password: randomString(),
|
|
499
|
+
app_id: randomString(),
|
|
500
|
+
app_password: randomString(),
|
|
501
|
+
ui_base: join(data.ui_base, 'dist', 'main'),
|
|
502
|
+
location: '/-/',
|
|
503
|
+
pushPort: 23000,
|
|
504
|
+
restPort: 24000,
|
|
505
|
+
};
|
|
506
|
+
if (!data.export_dir) data.export_dir = null;
|
|
507
|
+
if (!data.import_dir) data.import_dir = null;
|
|
508
|
+
if (!data.local_address) {
|
|
509
|
+
data.local_address = data.public_address || "127.0.0.1";
|
|
510
|
+
}
|
|
511
|
+
return data
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
*
|
|
516
|
+
*/
|
|
517
|
+
function privateIp() {
|
|
518
|
+
return new Promise(async (res, rej) => {
|
|
519
|
+
import("private-ip").then(module => { res(module.default) });
|
|
520
|
+
})
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
*
|
|
525
|
+
* @returns
|
|
526
|
+
*/
|
|
527
|
+
function configure() {
|
|
528
|
+
return new Promise(async (res, rej) => {
|
|
529
|
+
let data = getSysConfigs();
|
|
530
|
+
data.chroot = Template.chroot();
|
|
531
|
+
const isPrivate = await privateIp();
|
|
532
|
+
let os = require("os");
|
|
533
|
+
let interfaces = os.networkInterfaces();
|
|
534
|
+
let public_address;
|
|
535
|
+
for (let name in interfaces) {
|
|
536
|
+
for (let dev of interfaces[name]) {
|
|
537
|
+
if (dev.family == 'IPv4') {
|
|
538
|
+
if (isPrivate(dev.address)) {
|
|
539
|
+
data.local_address = dev.address;
|
|
540
|
+
break;
|
|
541
|
+
}
|
|
542
|
+
if (!dev.internal) {
|
|
543
|
+
public_address = dev.address;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
if (data.local_address) break;
|
|
548
|
+
}
|
|
549
|
+
data = makeConfData(data);
|
|
550
|
+
let func = [];
|
|
551
|
+
if (!ARGV.infra && !ARGV.jitsi) {
|
|
552
|
+
func = [writeInfraConf, writeJitsiConf];
|
|
553
|
+
} else {
|
|
554
|
+
if (ARGV.infra) func.push(writeInfraConf)
|
|
555
|
+
if (ARGV.jitsi) func.push(writeJitsiConf)
|
|
556
|
+
}
|
|
557
|
+
func.map(function (f) {
|
|
558
|
+
f(data);
|
|
559
|
+
})
|
|
560
|
+
res();
|
|
561
|
+
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
configure()
|
|
566
|
+
.then(() => {
|
|
567
|
+
exit(0);
|
|
568
|
+
})
|
|
569
|
+
.catch((e) => {
|
|
570
|
+
console.error("Failed to setup Drumee infra", e);
|
|
571
|
+
exit(0);
|
|
572
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@drumee/setup-infra",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Drumee Infrastructure Setup Utilities",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"configure": "./index.js",
|
|
8
|
+
"release": "git push && npm publish --access public && npm version patch"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git@github.com:drumee/setup-infra.git"
|
|
13
|
+
},
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/drumee/setup-infra/issues"
|
|
16
|
+
},
|
|
17
|
+
"author": "Somanos Sar <somanos@drumee.com>",
|
|
18
|
+
"license": "git",
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@drumee/server-essentials": "^1.0.4",
|
|
21
|
+
"crypto": "^1.0.1",
|
|
22
|
+
"jsonfile": "^5.0.0",
|
|
23
|
+
"lodash": "^4.17.21",
|
|
24
|
+
"minimist": "^1.2.8",
|
|
25
|
+
"ovh": "^2.0.3",
|
|
26
|
+
"private-ip": "^3.0.1",
|
|
27
|
+
"shelljs": "^0.8.5",
|
|
28
|
+
"uniqid": "^5.4.0"
|
|
29
|
+
}
|
|
30
|
+
}
|