-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathconfigureInstall.js
78 lines (60 loc) · 2.78 KB
/
configureInstall.js
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
var fs = require('fs')
const crypto = require("crypto");
var path = "/opt/redbox-portal";
var environment = "development";
var apiKey = "/opt/redbox-portal";
var url = "http://localhost";
var redboxLocation = "/opt/redbox";
var asked = [];
process.stdin.resume();
process.stdin.setEncoding('utf8');
console.log("What is the directory path of the application? Default:" + path);
asked.push("path");
process.stdin.on('data', function(text) {
if (asked.length == 5) {
redboxLocation = text.trim() == '' ? redboxLocation : text.trim();
fs.readFile('support/ecosystem.template', 'utf8', function(err, data) {
console.log("Generating ecosystem.json for PM2 service");
if (err) {
return console.log(err);
}
var result = data.replace(/#APIKEY#/g, apiKey);
var result = result.replace(/#ENVIRONMENT#/g, environment);
var result = result.replace(/#URL#/g, url);
var result = result.replace(/#PATH#/g, path);
fs.writeFile('ecosystem.json', result, 'utf8', function(err) {
if (err) return console.log(err);
fs.readFile('support/redboxApiKeys.template', 'utf8', function(err, data) {
var result = data.replace(/#APIKEY#/g, apiKey);
console.log("Generating apiKeys.json for the ReDBox Storage Service");
if (err) return console.log(err);
fs.writeFile(`${redboxLocation}/data/security/apiKeys.json`, result, 'utf8', function(err) {
if (err) return console.log(err);
console.log("Configuration generation complete");
process.exit();
});
});
});
});
}
if (asked.length == 4) {
url = text.trim() == '' ? url : text.trim();
console.log("What is the path of the ReDBox Storage service will be access from? Default: " + redboxLocation);
asked.push("environment");
}
if (asked.length == 3) {
apiKey = text.trim() == '' ? crypto.randomBytes(16).toString("hex") : text.trim();
console.log("What is the url the application will be access from? Default: " + url);
asked.push("environment");
}
if (asked.length == 2) {
environment = text.trim() == '' ? environment : text.trim();
console.log("What is the API KEY you'd like to use? Press enter to auto-generate one");
asked.push("environment");
}
if (asked.length == 1) {
path = text.trim() == '' ? path : text.trim();
console.log("What is the environment you'd like to use? Default: " + environment);
asked.push("environment");
}
});