This repository has been archived by the owner on Jan 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreateConfig.js
68 lines (60 loc) · 2.14 KB
/
createConfig.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
const readline = require('readline')
const fileSystem = require('fs')
const path = require('path')
var configData = {
'localeName': 'en',
'port': 90,
'accessProtection': true,
'accessLogin': 'admin',
'accessPassword': 'admin'
}
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
})
rl.question(`Localization(${configData['localeName']}): `, (answer) => {
addToConfig('localeName', answer)
rl.question(`Port(${configData['port']}): `, (answer) => {
addToConfig('port', answer)
rl.question(`Enable access protection?(${configData['accessProtection']}): `, (answer) => {
addToConfig('accessProtection', answer == 'true')
if (configData.accessProtection == true) {
rl.question(`Access login(${configData['accessLogin']}): `, (answer) => {
addToConfig('accessLogin', answer)
rl.question(`Access password(${configData['accessPassword']}): `, (answer) => {
addToConfig('accessPassword', answer)
createConfig()
initService()
rl.close()
})
})
} else {
createConfig()
initService()
rl.close()
}
})
})
})
function addToConfig(paramName, value) {
if (value) {configData[paramName] = value}
}
function initService() {
let serviceUrl = path.join(__dirname, 'webadmin.service')
let scriptUrl = path.join(__dirname, 'webadmin.js')
fileSystem.writeFile(serviceUrl, `[Unit]\nDescription=webadmin-daemon\nAfter=network-online.target\n\n[Service]\nExecStart=/usr/bin/node ${scriptUrl}\n\n[Install]\nWantedBy=multi-user.target`, (error) => {
if (error) {
console.log(error)
}
})
}
function createConfig() {
let configUrl = path.join(__dirname, 'config.json')
fileSystem.writeFile(configUrl, JSON.stringify(configData), (error) => {
if (error) {
console.log(error)
} else {
console.log("Config file created.")
}
})
}