This repository has been archived by the owner on May 26, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
/
settings.js
106 lines (89 loc) · 3.85 KB
/
settings.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
var fs = require('fs'),
logger = require(__dirname+'/logger.js');
var settings = {};
try {
var settingsJson = fs.readFileSync(__dirname+"/datastore/io-settings.json");
settings = JSON.parse(settingsJson.toString());
logger.verbose("ccu.io settings found");
if (!settings.uid) {
logger.verbose("ccu.io creating uid");
settings.uid = Math.floor((Math.random()*4294967296)).toString(16)+Math.floor((Math.random()*4294967296)).toString(16)+Math.floor((Math.random()*4294967296)).toString(16)+Math.floor((Math.random()*4294967296)).toString(16);
fs.writeFileSync(__dirname+"/datastore/io-settings.json", JSON.stringify(settings));
}
} catch (e) {
logger.info("ccu.io creating datastore/io-settings.json");
var settingsJson = fs.readFileSync(__dirname+"/settings-dist.json");
settings = JSON.parse(settingsJson.toString());
settings.unconfigured = true;
logger.verbose("ccu.io creating uid");
settings.uid = Math.floor((Math.random()*4294967296)).toString(16)+Math.floor((Math.random()*4294967296)).toString(16)+Math.floor((Math.random()*4294967296)).toString(16)+Math.floor((Math.random()*4294967296)).toString(16);
fs.writeFileSync(__dirname+"/datastore/io-settings.json", JSON.stringify(settings));
}
settings.updateSelfRunning = false;
settings.binrpc.inits = [];
if (settings.binrpc.rfdEnabled) {
settings.binrpc.inits.push({
id: settings.binrpc.rfdId,
port: settings.binrpc.rfdPort
});
}
if (settings.binrpc.hs485dEnabled) {
settings.binrpc.inits.push({
id: settings.binrpc.hs485dId,
port: settings.binrpc.hs485dPort
});
}
if (settings.binrpc.cuxdEnabled) {
settings.binrpc.inits.push({
id: settings.binrpc.cuxdId,
port: settings.binrpc.cuxdPort
});
}
settings.binrpc.checkEvents.testTrigger = {
"io_rf": settings.binrpc.checkEvents.rfd,
"io_wired": settings.binrpc.checkEvents.hs485d
}
if (!settings.httpEnabled) {
delete settings.ioListenPort;
}
if (!settings.httpsEnabled) {
delete settings.ioListenPortSsl;
}
settings.adapters = {};
// Find Adapters
var adapters = fs.readdirSync(__dirname+"/adapter");
for (var i = 0; i < adapters.length; i++) {
if (adapters[i] == ".DS_Store" || adapters[i].match(/^skeleton/)) {
continue;
}
var adapterSettings = {},
settingsJson;
try {
settingsJson = fs.readFileSync(__dirname+"/datastore/adapter-"+adapters[i]+".json");
adapterSettings = JSON.parse(settingsJson.toString());
if (!adapterSettings) {
try {
settingsJson = fs.readFileSync(__dirname+"/adapter/"+adapters[i]+"/settings.json");
var adapterSettings = JSON.parse(settingsJson.toString());
fs.writeFileSync(__dirname+"/datastore/adapter-"+adapters[i]+".json", JSON.stringify(adapterSettings));
logger.info("ccu.io creating datastore/adapter-"+adapters[i]+".json");
} catch (ee) {
logger.error("ccu.io no settings.json found for "+adapters[i]);
}
} else {
logger.verbose("ccu.io settings.json found for "+adapters[i]);
}
} catch (e) {
try {
settingsJson = fs.readFileSync(__dirname+"/adapter/"+adapters[i]+"/settings.json");
var adapterSettings = JSON.parse(settingsJson.toString());
fs.writeFileSync(__dirname+"/datastore/adapter-"+adapters[i]+".json", JSON.stringify(adapterSettings));
logger.info("ccu.io creating datastore/adapter-"+adapters[i]+".json");
} catch (ee) {
logger.error("ccu.io no settings.json found for "+adapters[i]);
}
}
settings.adapters[adapters[i]] = adapterSettings;
}
//console.log(JSON.stringify(settings, null, " "));
module.exports = settings;