Added support for macOS and KDialog.
Bryan Roe committed
Aug 3, 2020 at 10:51 UTC
1d04791d90e5b7580c26f9e36764a3bfd2bd3f0f
1 file changed
+110
-37
agents/meshinstall-linux.js
+110
-37
@@ -24,34 +24,116 @@ var msh = {};
24
var s = null;
25
try { s = require('service-manager').manager.getService('meshagent'); } catch (e) { }
26
27
-var buttons = ["Connect", "Cancel"];
28
-if (s) {
29
- buttons.unshift("Uninstall");
30
- buttons.unshift("Update");
31
-} else {
32
- buttons.unshift("Install");
27
+function _install()
28
+{
29
+ var mstr = require('fs').createWriteStream(process.execPath + '.msh', { flags: 'wb' });
30
+ mstr.write('MeshName=' + msh.MeshName + '\n');
31
+ mstr.write('MeshType=' + msh.MeshType + '\n');
32
+ mstr.write('MeshID=' + msh.MeshID + '\n');
33
+ mstr.write('ServerID=' + msh.ServerID + '\n');
34
+ mstr.write('MeshServer=' + msh.MeshServer + '\n');
35
+ mstr.end();
36
+
37
+ global._child = require('child_process').execFile(process.execPath,
38
+ [process.execPath.split('/').pop(), '-fullinstall', '--no-embedded=1', '--copy-msh=1']);
39
+
40
+ global._child.stdout.on('data', function (c) { process.stdout.write(c.toString()); });
41
+ global._child.stderr.on('data', function (c) { process.stdout.write(c.toString()); });
42
+ global._child.waitExit();
43
+}
44
+function _uninstall()
45
+{
46
+ global._child = require('child_process').execFile(process.execPath,
47
+ [process.execPath.split('/').pop(), '-fulluninstall', '--no-embedded=1']);
48
+
49
+ global._child.stdout.on('data', function (c) { process.stdout.write(c.toString()); });
50
+ global._child.stderr.on('data', function (c) { process.stdout.write(c.toString()); });
51
+ global._child.waitExit();
52
}
53
35
-if ((require('message-box').zenity == null) || (!require('message-box').zenity.extra)) {
36
- console.log('\n' + "This installer cannot run on this system.");
37
- console.log("Try installing/updating Zenity, and run again." + '\n');
38
- process.exit();
54
+var s = null;
55
+try { s = require('service-manager').manager.getService('meshagent'); } catch (e) { }
56
+var buttons = ['Cancel'];
57
+
58
+if (msh.InstallFlags == null)
59
+{
60
+ msh.InstallFlags = 3;
61
+}
62
+else
63
+{
64
+ msh.InstallFlags = parseInt(msh.InstallFlags.toString());
65
}
66
41
-if (!s) {
67
+
68
+if ((msh.InstallFlags & 1) == 1) { buttons.unshift("Connect"); }
69
+if ((msh.InstallFlags & 2) == 2)
70
+{
71
+ if (s)
72
+ {
73
+ if (process.platform == 'darwin' || require('message-box').kdialog)
74
+ {
75
+ buttons.unshift("Setup");
76
+ }
77
+ else
78
+ {
79
+ buttons.unshift("Uninstall");
80
+ buttons.unshift("Update");
81
+ }
82
+ }
83
+ else
84
+ {
85
+ buttons.unshift("Install");
86
+ }
87
+}
88
+
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();
96
+ }
97
+}
98
+
99
+if (!s)
100
+{
101
msg = "Agent: " + "NOT INSTALLED" + '\n';
43
-} else {
102
+} else
103
+{
104
msg = "Agent: " + (s.isRunning() ? "RUNNING" : "NOT RUNNING") + '\n';
105
}
106
+
107
msg += ("Device Group: " + msh.MeshName + '\n');
108
msg += ("Server URL: " + msh.MeshServer + '\n');
109
110
var p = require('message-box').create("MeshCentral Agent Setup", msg, 99999, buttons);
50
-p.then(function (v) {
51
- switch (v) {
111
+p.then(function (v)
112
+{
113
+ switch (v)
114
+ {
115
case "Cancel":
116
process.exit();
117
break;
118
+ case "Setup":
119
+ var d = require('message-box').create("MeshCentral Agent", msg, 99999, ["Update", "Uninstall", "Cancel"]);
120
+ d.then(function (v)
121
+ {
122
+ switch (v)
123
+ {
124
+ case "Update":
125
+ case "Install":
126
+ _install();
127
+ break;
128
+ case "Uninstall":
129
+ _uninstall();
130
+ break;
131
+ default:
132
+ break;
133
+ }
134
+ process.exit();
135
+ }).catch(function (v) { process.exit(); });
136
+ break;
137
case "Connect":
138
global._child = require('child_process').execFile(process.execPath,
139
[process.execPath.split('/').pop(), '--no-embedded=1', '--disableUpdate=1',
@@ -68,34 +150,24 @@ p.then(function (v) {
150
msg = ("Device Group: " + msh.MeshName + '\n');
151
msg += ("Server URL: " + msh.MeshServer + '\n');
152
153
+ if (process.platform != 'darwin')
154
+ {
155
+ if (!require('message-box').zenity && require('message-box').kdialog)
156
+ {
157
+ msg += ('\n'+"Press OK to Disconnect");
158
+ }
159
+ }
160
+
161
var d = require('message-box').create("MeshCentral Agent", msg, 99999, ["Disconnect"]);
162
d.then(function (v) { process.exit(); }).catch(function (v) { process.exit(); });
163
break;
164
case "Uninstall":
75
- global._child = require('child_process').execFile(process.execPath,
76
- [process.execPath.split('/').pop(), '-fulluninstall', '--no-embedded=1']);
77
-
78
- global._child.stdout.on('data', function (c) { process.stdout.write(c.toString()); });
79
- global._child.stderr.on('data', function (c) { process.stdout.write(c.toString()); });
80
- global._child.waitExit();
165
+ _uninstall();
166
process.exit();
167
break;
168
case "Install":
169
case "Update":
85
- var mstr = require('fs').createWriteStream(process.execPath + '.msh', { flags: 'wb' });
86
- mstr.write('MeshName=' + msh.MeshName + '\n');
87
- mstr.write('MeshType=' + msh.MeshType + '\n');
88
- mstr.write('MeshID=' + msh.MeshID + '\n');
89
- mstr.write('ServerID=' + msh.ServerID + '\n');
90
- mstr.write('MeshServer=' + msh.MeshServer + '\n');
91
- mstr.end();
92
-
93
- global._child = require('child_process').execFile(process.execPath,
94
- [process.execPath.split('/').pop(), '-fullinstall', '--no-embedded=1', '--copy-msh=1']);
95
-
96
- global._child.stdout.on('data', function (c) { process.stdout.write(c.toString()); });
97
- global._child.stderr.on('data', function (c) { process.stdout.write(c.toString()); });
98
- global._child.waitExit();
170
+ _install();
171
process.exit();
172
break;
173
default:
@@ -103,7 +175,8 @@ p.then(function (v) {
175
process.exit();
176
break;
177
}
106
-}).catch(function (e) {
178
+}).catch(function (e)
179
+{
180
+ console.log(e);
181
process.exit();
108
-});
109
-
182
+});
\ No newline at end of file