Updated Linux interactive installer.
Ylian Saint-Hilaire committed
Sep 10, 2020 at 15:18 UTC
7311b2374347948961902b280189374751b53500
2 files changed
+148
-122
MeshCentralServer.njsproj
+1
@@ -24,6 +24,7 @@
24
<Compile Include="agents\meshcmd.min.js" />
25
<Compile Include="agents\meshcore.js" />
26
<Compile Include="agents\meshcore.min.js" />
27
+ <Compile Include="agents\meshinstall-linux.js" />
28
<Compile Include="agents\modules_meshcmd\amt-ider.js" />
29
<Compile Include="agents\modules_meshcmd\amt-lme.js" />
30
<Compile Include="agents\modules_meshcmd\amt-mei.js" />
agents/meshinstall-linux.js
+147
-122
@@ -14,12 +14,10 @@ See the License for the specific language governing permissions and
14
limitations under the License.
15
*/
16
17
-var msh = {};
18
-var s = null;
17
+var s = null, msh = {}, buttons = ['Cancel'], skip = false;
18
try { s = require('service-manager').manager.getService('meshagent'); } catch (e) { }
19
21
-function _install()
22
-{
20
+function _install(parms) {
21
var mstr = require('fs').createWriteStream(process.execPath + '.msh', { flags: 'wb' });
22
mstr.write('MeshName=' + msh.MeshName + '\n');
23
mstr.write('MeshType=' + msh.MeshType + '\n');
@@ -27,160 +25,187 @@ function _install()
25
mstr.write('ServerID=' + msh.ServerID + '\n');
26
mstr.write('MeshServer=' + msh.MeshServer + '\n');
27
mstr.end();
30
-
31
- global._child = require('child_process').execFile(process.execPath,
32
- [process.execPath.split('/').pop(), '-fullinstall', '--no-embedded=1', '--copy-msh=1']);
33
-
28
+
29
+ if (parms == null) { parms = []; }
30
+ parms.unshift('--copy-msh=1');
31
+ parms.unshift('--no-embedded=1');
32
+ parms.unshift('-fullinstall');
33
+ parms.unshift(process.execPath.split('/').pop());
34
+
35
+ global._child = require('child_process').execFile(process.execPath, parms);
36
global._child.stdout.on('data', function (c) { process.stdout.write(c.toString()); });
37
global._child.stderr.on('data', function (c) { process.stdout.write(c.toString()); });
38
global._child.waitExit();
39
}
38
-function _uninstall()
39
-{
40
- global._child = require('child_process').execFile(process.execPath,
41
- [process.execPath.split('/').pop(), '-fulluninstall', '--no-embedded=1']);
40
41
+function _uninstall() {
42
+ global._child = require('child_process').execFile(process.execPath,
43
+ [process.execPath.split('/').pop(), '-fulluninstall', '--no-embedded=1']);
44
+
45
global._child.stdout.on('data', function (c) { process.stdout.write(c.toString()); });
46
global._child.stderr.on('data', function (c) { process.stdout.write(c.toString()); });
47
global._child.waitExit();
48
}
49
48
-var s = null;
49
-try { s = require('service-manager').manager.getService('meshagent'); } catch (e) { }
50
-var buttons = ['Cancel'];
51
-
52
-if (msh.InstallFlags == null)
53
-{
50
+if (msh.InstallFlags == null) {
51
msh.InstallFlags = 3;
55
-}
56
-else
57
-{
52
+} else {
53
msh.InstallFlags = parseInt(msh.InstallFlags.toString());
54
}
55
61
-
62
-if ((msh.InstallFlags & 1) == 1) { buttons.unshift("Connect"); }
63
-if ((msh.InstallFlags & 2) == 2)
64
-{
65
- if (!require('user-sessions').isRoot())
66
- {
56
+if ((msh.InstallFlags & 1) == 1) { buttons.unshift('Connect'); }
57
+if ((msh.InstallFlags & 2) == 2) {
58
+ if (!require('user-sessions').isRoot()) {
59
console.log('\n' + "Elevated permissions is required to install/uninstall the agent.");
60
console.log("Please try again with sudo.");
61
process.exit();
62
}
71
- if (s)
72
- {
73
- if (process.platform == 'darwin' || require('message-box').kdialog)
74
- {
63
+ if (s) {
64
+ if (process.platform == 'darwin' || require('message-box').kdialog) {
65
buttons.unshift("Setup");
76
- }
77
- else
78
- {
66
+ } else {
67
buttons.unshift("Uninstall");
68
buttons.unshift("Update");
69
}
82
- }
83
- else
84
- {
70
+ } else {
71
buttons.unshift("Install");
72
}
73
}
74
89
-if (process.platform != 'darwin')
90
-{
91
- if (!require('message-box').kdialog && (require('message-box').zenity == null || (!require('message-box').zenity.extra)))
92
- {
93
- console.log('\n' + "This installer cannot run on this system.");
94
- console.log("Try installing/updating Zenity, and run again." + '\n');
95
- process.exit();
75
+if (process.platform != 'darwin') {
76
+ if (!require('message-box').kdialog && (require('message-box').zenity == null || (!require('message-box').zenity.extra))) {
77
+ if (process.argv.includes('-install') || process.argv.includes('-update')) {
78
+ var p = [];
79
+ for (var i = 0; i < process.argv.length; ++i) {
80
+ if (process.argv[i].startsWith('--installPath=')) {
81
+ p.push('--installPath="' + process.argv[i].split('=').pop() + '"');
82
+ }
83
+ }
84
+ _install(p);
85
+ process.exit();
86
+ }
87
+ else if (process.argv.includes('-uninstall')) {
88
+ _uninstall();
89
+ process.exit();
90
+ }
91
+ else if (process.argv.includes('-connect')) {
92
+ global._child = require('child_process').execFile(process.execPath,
93
+ [process.execPath.split('/').pop(), '--no-embedded=1', '--disableUpdate=1',
94
+ '--MeshName="' + msh.MeshName + '"', '--MeshType="' + msh.MeshType + '"',
95
+ '--MeshID="' + msh.MeshID + '"',
96
+ '--ServerID="' + msh.ServerID + '"',
97
+ '--MeshServer="' + msh.MeshServer + '"',
98
+ '--AgentCapabilities="0x00000020"']);
99
+
100
+ global._child.stdout.on('data', function (c) { });
101
+ global._child.stderr.on('data', function (c) { });
102
+ global._child.on('exit', function (code) { process.exit(code); });
103
+
104
+ console.log("\nConnecting to: " + msh.MeshServer);
105
+ console.log("Device Group: " + msh.MeshName);
106
+ console.log('\nPress Ctrl-c to exit\n');
107
+ skip = true;
108
+ } else {
109
+ console.log('\n' + "The graphical version of this installer cannot run on this system.");
110
+ console.log("Try installing/updating Zenity, and run again." + '\n');
111
+ console.log("You can also run the text version from the command line with the following command(s): ");
112
+ if ((msh.InstallFlags & 1) == 1) {
113
+ console.log('./' + process.execPath.split('/').pop() + ' -connect');
114
+ }
115
+ if ((msh.InstallFlags & 2) == 2) {
116
+ if (s) {
117
+ console.log('./' + process.execPath.split('/').pop() + ' -update');
118
+ console.log('./' + process.execPath.split('/').pop() + ' -uninstall');
119
+ }
120
+ else {
121
+ console.log('./' + process.execPath.split('/').pop() + ' -install');
122
+ console.log('./' + process.execPath.split('/').pop() + ' -install --installPath="/alternate/path"');
123
+ }
124
+ }
125
+ console.log('');
126
+ process.exit();
127
+ }
128
}
129
}
98
-else
99
-{
130
+else {
131
if (!require('user-sessions').isRoot()) { console.log('\n' + "This utility requires elevated permissions. Please try again with sudo."); process.exit(); }
132
}
133
103
-if (!s)
104
-{
105
- msg = "Agent: " + "NOT INSTALLED" + '\n';
106
-} else
107
-{
108
- msg = "Agent: " + (s.isRunning() ? "RUNNING" : "NOT RUNNING") + '\n';
109
-}
110
-
111
-msg += ("Device Group: " + msh.MeshName + '\n');
112
-msg += ("Server URL: " + msh.MeshServer + '\n');
134
114
-var p = require('message-box').create("MeshCentral Agent Setup", msg, 99999, buttons);
115
-p.then(function (v)
116
-{
117
- switch (v)
118
- {
119
- case "Cancel":
120
- process.exit();
121
- break;
122
- case "Setup":
123
- var d = require('message-box').create("MeshCentral Agent", msg, 99999, ["Update", "Uninstall", "Cancel"]);
124
- d.then(function (v)
125
- {
126
- switch (v)
127
- {
128
- case "Update":
129
- case "Install":
130
- _install();
131
- break;
132
- case "Uninstall":
133
- _uninstall();
134
- break;
135
- default:
136
- break;
137
- }
135
+if (!skip) {
136
+ if (!s) {
137
+ msg = "Agent: " + "NOT INSTALLED" + '\n';
138
+ } else {
139
+ msg = "Agent: " + (s.isRunning() ? "RUNNING" : "NOT RUNNING") + '\n';
140
+ }
141
+
142
+ msg += ("Device Group: " + msh.MeshName + '\n');
143
+ msg += ("Server URL: " + msh.MeshServer + '\n');
144
+
145
+ var p = require('message-box').create("MeshCentral Agent Setup", msg, 99999, buttons);
146
+ p.then(function (v) {
147
+ switch (v) {
148
+ case "Cancel":
149
process.exit();
139
- }).catch(function (v) { process.exit(); });
140
- break;
141
- case "Connect":
142
- global._child = require('child_process').execFile(process.execPath,
143
- [process.execPath.split('/').pop(), '--no-embedded=1', '--disableUpdate=1',
150
+ break;
151
+ case 'Setup':
152
+ var d = require('message-box').create("MeshCentral Agent", msg, 99999, ['Update', 'Uninstall', 'Cancel']);
153
+ d.then(function (v) {
154
+ switch (v) {
155
+ case 'Update':
156
+ case 'Install':
157
+ _install();
158
+ break;
159
+ case 'Uninstall':
160
+ _uninstall();
161
+ break;
162
+ default:
163
+ break;
164
+ }
165
+ process.exit();
166
+ }).catch(function (v) { process.exit(); });
167
+ break;
168
+ case "Connect":
169
+ global._child = require('child_process').execFile(process.execPath,
170
+ [process.execPath.split('/').pop(), '--no-embedded=1', '--disableUpdate=1',
171
'--MeshName="' + msh.MeshName + '"', '--MeshType="' + msh.MeshType + '"',
172
'--MeshID="' + msh.MeshID + '"',
173
'--ServerID="' + msh.ServerID + '"',
174
'--MeshServer="' + msh.MeshServer + '"',
175
'--AgentCapabilities="0x00000020"']);
149
-
150
- global._child.stdout.on('data', function (c) { });
151
- global._child.stderr.on('data', function (c) { });
152
- global._child.on('exit', function (code) { process.exit(code); });
153
-
154
- msg = ("Device Group: " + msh.MeshName + '\n');
155
- msg += ("Server URL: " + msh.MeshServer + '\n');
156
-
157
- if (process.platform != 'darwin')
158
- {
159
- if (!require('message-box').zenity && require('message-box').kdialog)
160
- {
161
- msg += ('\n'+"Press OK to Disconnect");
176
+
177
+ global._child.stdout.on('data', function (c) { });
178
+ global._child.stderr.on('data', function (c) { });
179
+ global._child.on('exit', function (code) { process.exit(code); });
180
+
181
+ msg = ("Device Group: " + msh.MeshName + '\n');
182
+ msg += ("Server URL: " + msh.MeshServer + '\n');
183
+
184
+ if (process.platform != 'darwin') {
185
+ if (!require('message-box').zenity && require('message-box').kdialog) {
186
+ msg += ('\nPress OK to Disconnect');
187
+ }
188
}
163
- }
164
-
165
- var d = require('message-box').create("MeshCentral Agent", msg, 99999, ["Disconnect"]);
166
- d.then(function (v) { process.exit(); }).catch(function (v) { process.exit(); });
167
- break;
168
- case "Uninstall":
169
- _uninstall();
170
- process.exit();
171
- break;
172
- case "Install":
173
- case "Update":
174
- _install();
175
- process.exit();
176
- break;
177
- default:
178
- console.log(v);
179
- process.exit();
180
- break;
181
- }
182
-}).catch(function (e)
183
-{
184
- console.log(e);
185
- process.exit();
186
-});
\ No newline at end of file
189
+
190
+ var d = require('message-box').create("MeshCentral Agent", msg, 99999, ['Disconnect']);
191
+ d.then(function (v) { process.exit(); }).catch(function (v) { process.exit(); });
192
+ break;
193
+ case "Uninstall":
194
+ _uninstall();
195
+ process.exit();
196
+ break;
197
+ case "Install":
198
+ case "Update":
199
+ _install();
200
+ process.exit();
201
+ break;
202
+ default:
203
+ console.log(v);
204
+ process.exit();
205
+ break;
206
+ }
207
+ }).catch(function (e) {
208
+ console.log(e);
209
+ process.exit();
210
+ });
211
+}
\ No newline at end of file