-
Notifications
You must be signed in to change notification settings - Fork 6
/
install.js
114 lines (101 loc) · 3.07 KB
/
install.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
105
106
107
108
109
110
111
112
113
114
/**
* This file is part of Cjdmaid.
*
* Cjdmaid program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
"use strict";
var fs = require("fs");
var when = require("when");
var nodefn = require("when/node/function");
var JSONcomments = require("json-comments-js");
var childProcess = require("child_process");
var util = require(__dirname + "/lib/util");
var config = require(__dirname + "/lib/config");
var commfn = require(__dirname + "/lib/commander/function");
var cjdmaidConf = {
"cjdrouteConf": "Fill this: Path to your cjdroute.conf",
"cjdnsadminConf": "~/.cjdnsadmin",
"passwordLength": 48,
"ownNodeData": {
"name": "Optional: Your nickname",
"email": "Optional: Your email",
"location": "Optional: Your location",
"ip": "Optional: Enter your node external ip adress"
}
};
when(
commfn.call(fs.exists, fs, config.CJDMAID_CONFIG_PATH)
)
.then(function (exists) {
if (exists) {
console.log(config.CJDMAID_CONFIG_PATH + " already exists");
return when(
config.readCustomConf("cjdmaidConf")
)
.then(function (data) {
if (util.isDef(data.ownNodeData)) {
console.log("Now installed");
}
else {
data.ownNodeData = {
"name": data.name,
"email": data.email,
"location": data.location,
"ip": data.ip
};
var pushObject = util.cloneObject(data);
delete pushObject.name;
delete pushObject.email;
delete pushObject.location;
delete pushObject.ip;
return when(
config.writeCustomConf("cjdmaidConf", pushObject)
)
.then(function () {
console.log("Now installed");
});
}
})
.then(function () {
return when.reject();
});
}
cjdmaidConf["/**/"] = config.CONFIGS_COMMENTS.cjdmaidConf;
var writingText = JSONcomments.stringify(cjdmaidConf, null, "\t");
return when(
nodefn.call(fs.writeFile, config.CJDMAID_CONFIG_PATH, writingText)
)
.then(function () {
console.log(config.CJDMAID_CONFIG_PATH + " saved!");
})
.otherwise(function (err) {
if (err) {
console.log("WARNING! " + config.CJDMAID_CONFIG_PATH + " " +
"is not created! Here error: " + err + ". " +
"You need create it by yourself. ");
return when.reject(err);
}
});
})
.then(function() {
var editor = process.env.EDITOR || "nano";
console.log("Editing " + config.CJDMAID_CONFIG_PATH + "...");
var child = childProcess.spawn(editor, [config.CJDMAID_CONFIG_PATH], {
stdio: "inherit"
});
child.on("exit", function (/* code, signal */) {
console.log("User close editor!");
console.log("Now installed");
});
});