-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.js
104 lines (90 loc) · 2.93 KB
/
setup.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
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
const prompt = require("prompt-sync")({ sigint: true });
const fs = require("fs-extra");
let config = require("./config/configExample.json");
let passportKeys = require("./config/passportKeysExample.json");
fs.ensureDirSync("./db/");
if (process.argv[2] == "--headless") {
// saving defaults
fs.copySync("./config/configExample.json", "./config/config.json");
fs.copySync(
"./config/passportKeysExample.json",
"./config/passportKeys.json"
);
process.exit(0);
}
console.log("Hello!");
console.log("Starting setup...");
config.self_hosted =
prompt(
"Use Auto-generated TLS? (will require ports 80 and 443) (y/N): ",
"n"
).toLowerCase() == "y";
if (config.self_hosted) {
console.log("Showing additional TLS options:");
config.tls.email = prompt("Enter Letsencrypt email (your email): ");
config.tls.tos =
prompt(
"Do you agree with the LetsEncrypt TOS? (Y/n): ",
"y"
).toLowerCase() == "y";
if (!config.tls.tos) {
config.self_hosted = false;
console.log("Reverting LetsEncrypt setup...");
} else {
let current = 0;
while (true) {
config.tls.domains[current] = prompt(
"Please enter domain " + (current + 1) + " (ENTER to cancel): "
);
if (config.tls.domains[current] == "") {
config.tls.domains.splice(current, 1);
break;
} else {
current++;
}
}
}
}
if (!config.self_hosted) {
config.port = ~~prompt("Enter port (7777): ", config.port);
config.secure_override =
~~prompt(
"Will you use an external HTTPS/TLS provider proxy? Secure cookies will be enabled, if yes (y/N): ",
"n"
).toLowerCase() == "y";
}
if (
prompt(
"Do you want to set up Google and Twitter API keys? (Y/n): ",
"Y"
).toLowerCase() == "y"
) {
console.log(
"An external url is required for Google and Twitter auth to function."
);
config.url = prompt(
"Enter your website url: (http://example.com): ",
config.url
);
console.log("Showing additional API KEY information:");
console.log(
"Go to https://console.developers.google.com and create a new project. Then, create credentials for 'OAuth client ID'."
);
passportKeys.GOOGLE_ID = prompt("Paste the Client ID here:");
passportKeys.GOOGLE_SECRET = prompt("Paste the Client secret here:");
console.log("Great!");
console.log(
"Now, go to https://developer.twitter.com/en/apps and create a new twitter app. Navigate to Consumer API keys."
);
passportKeys.TWITTER_KEY = prompt("Paste the API key here:");
passportKeys.TWITTER_SECRET = prompt("Paste the API secret key here:");
console.log("Passport keys configured.");
}
console.log("Setup done. Generating session secret and exiting...");
config.session_secret = [...Array(30)]
.map(i => (~~(Math.random() * 36)).toString(36))
.join("");
// writing and exitting
fs.writeJsonSync("./config/config.json", config);
fs.writeJsonSync("./config/passportKeys.json", passportKeys);
process.exit(0);