lightman-agent 1.0.7 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/agent.config.json +22 -0
- package/bin/cms-agent.js +53 -4
- package/package.json +2 -1
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"serverUrl": "http://192.168.10.100:3401",
|
|
3
|
+
"deviceSlug": "a-av03",
|
|
4
|
+
"healthIntervalMs": 60000,
|
|
5
|
+
"logLevel": "debug",
|
|
6
|
+
"logFile": "agent.log",
|
|
7
|
+
"identityFile": ".lightman-identity.json",
|
|
8
|
+
"kiosk": {
|
|
9
|
+
"browserPath": "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe",
|
|
10
|
+
"defaultUrl": "http://localhost:3403/display/a-av03",
|
|
11
|
+
"extraArgs": ["--start-fullscreen", "--disable-translate", "--disable-extensions", "--user-data-dir=C:\\ProgramData\\Lightman\\chrome-kiosk"],
|
|
12
|
+
"pollIntervalMs": 10000,
|
|
13
|
+
"maxCrashesInWindow": 10,
|
|
14
|
+
"crashWindowMs": 300000
|
|
15
|
+
},
|
|
16
|
+
"powerSchedule": {
|
|
17
|
+
"shutdownCron": "0 19 * * *",
|
|
18
|
+
"startupCron": "0 8 * * *",
|
|
19
|
+
"timezone": "Asia/Kolkata",
|
|
20
|
+
"shutdownWarningSeconds": 60
|
|
21
|
+
}
|
|
22
|
+
}
|
package/bin/cms-agent.js
CHANGED
|
@@ -16,13 +16,13 @@ function printUsage() {
|
|
|
16
16
|
cms-agent <command> [options]
|
|
17
17
|
|
|
18
18
|
Commands:
|
|
19
|
-
install Prompt slug, install agent with ShellReplace, reboot
|
|
19
|
+
install Prompt slug and server IP, install agent with ShellReplace, reboot
|
|
20
20
|
setup Alias of install
|
|
21
21
|
update Reinstall/update using installed config, reboot
|
|
22
22
|
|
|
23
23
|
Options:
|
|
24
24
|
--slug <value> Device slug (example: C-AV01)
|
|
25
|
-
--server <url> Server URL (example: http://192.168.1.100:3401)
|
|
25
|
+
--server <url> Server URL or IP (example: 192.168.1.100 or http://192.168.1.100:3401)
|
|
26
26
|
--timezone <tz> Timezone override (default: Asia/Kolkata)
|
|
27
27
|
--pair-timeout <s> Wait time for pairing in seconds (default: 900, 0 = no timeout)
|
|
28
28
|
--no-restart Skip reboot after successful install/update
|
|
@@ -79,6 +79,33 @@ function isValidSlug(slug) {
|
|
|
79
79
|
return /^[A-Za-z0-9][A-Za-z0-9-]{0,62}$/.test(slug);
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
+
function normalizeServer(server) {
|
|
83
|
+
const value = (server || '').trim();
|
|
84
|
+
if (!value) {
|
|
85
|
+
return '';
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const hasProtocol = /^[a-z]+:\/\//i.test(value);
|
|
89
|
+
const candidate = hasProtocol ? value : `http://${value}`;
|
|
90
|
+
|
|
91
|
+
let parsed;
|
|
92
|
+
try {
|
|
93
|
+
parsed = new URL(candidate);
|
|
94
|
+
} catch {
|
|
95
|
+
throw new Error('Invalid server IP/URL. Use an IP like 192.168.1.100 or a URL like http://192.168.1.100:3401.');
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (!parsed.port) {
|
|
99
|
+
parsed.port = '3401';
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (parsed.pathname === '/') {
|
|
103
|
+
parsed.pathname = '';
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return parsed.toString().replace(/\/$/, '');
|
|
107
|
+
}
|
|
108
|
+
|
|
82
109
|
function collectMacAddresses() {
|
|
83
110
|
const nets = networkInterfaces();
|
|
84
111
|
const macs = new Set();
|
|
@@ -129,6 +156,27 @@ async function promptSlug(defaultSlug) {
|
|
|
129
156
|
}
|
|
130
157
|
}
|
|
131
158
|
|
|
159
|
+
async function promptServer(defaultServer) {
|
|
160
|
+
const rl = createInterface({ input, output });
|
|
161
|
+
try {
|
|
162
|
+
while (true) {
|
|
163
|
+
const prompt = defaultServer
|
|
164
|
+
? `Enter server IP or URL [${defaultServer}]: `
|
|
165
|
+
: 'Enter server IP or URL (example 192.168.1.100 or http://192.168.1.100:3401): ';
|
|
166
|
+
const answer = (await rl.question(prompt)).trim();
|
|
167
|
+
const server = answer || defaultServer || '';
|
|
168
|
+
|
|
169
|
+
try {
|
|
170
|
+
return normalizeServer(server);
|
|
171
|
+
} catch (error) {
|
|
172
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
} finally {
|
|
176
|
+
rl.close();
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
132
180
|
function resolveInstallScript() {
|
|
133
181
|
const here = dirname(fileURLToPath(import.meta.url));
|
|
134
182
|
const packaged = resolve(here, '../scripts/install-windows.ps1');
|
|
@@ -166,7 +214,7 @@ async function runInstall(opts) {
|
|
|
166
214
|
const localConfig = safeReadJson(resolve(cwd(), 'agent.config.json')) || {};
|
|
167
215
|
const installedConfig = safeReadJson(INSTALL_CONFIG_PATH) || {};
|
|
168
216
|
const defaultSlug = opts.slug || localConfig.deviceSlug || installedConfig.deviceSlug || '';
|
|
169
|
-
const
|
|
217
|
+
const defaultServer = localConfig.serverUrl || installedConfig.serverUrl || DEFAULT_SERVER;
|
|
170
218
|
const timezone = opts.timezone || localConfig?.powerSchedule?.timezone || installedConfig?.powerSchedule?.timezone || 'Asia/Kolkata';
|
|
171
219
|
const pairingTimeoutSeconds = Number.isFinite(Number(opts.pairTimeout)) ? Number.parseInt(String(opts.pairTimeout), 10) : 900;
|
|
172
220
|
const noRestart = Boolean(opts.noRestart);
|
|
@@ -183,6 +231,7 @@ async function runInstall(opts) {
|
|
|
183
231
|
console.log('');
|
|
184
232
|
|
|
185
233
|
const slug = opts.slug || await promptSlug(defaultSlug);
|
|
234
|
+
const server = opts.server ? normalizeServer(opts.server) : await promptServer(defaultServer);
|
|
186
235
|
const scriptPath = resolveInstallScript();
|
|
187
236
|
|
|
188
237
|
console.log(`Installing with slug=${slug}, server=${server}, shellReplace=true`);
|
|
@@ -199,7 +248,7 @@ async function runUpdate(opts) {
|
|
|
199
248
|
|
|
200
249
|
const installedConfig = safeReadJson(INSTALL_CONFIG_PATH) || {};
|
|
201
250
|
const slug = opts.slug || installedConfig.deviceSlug;
|
|
202
|
-
const server = opts.server || DEFAULT_SERVER;
|
|
251
|
+
const server = normalizeServer(opts.server || installedConfig.serverUrl || DEFAULT_SERVER);
|
|
203
252
|
const timezone = opts.timezone || installedConfig?.powerSchedule?.timezone || 'Asia/Kolkata';
|
|
204
253
|
const pairingTimeoutSeconds = Number.isFinite(Number(opts.pairTimeout)) ? Number.parseInt(String(opts.pairTimeout), 10) : 900;
|
|
205
254
|
const noRestart = Boolean(opts.noRestart);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lightman-agent",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"description": "LIGHTMAN Agent - System-level daemon for museum display machines",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"src/commands/",
|
|
18
18
|
"src/lib/",
|
|
19
19
|
"src/services/",
|
|
20
|
+
"agent.config.json",
|
|
20
21
|
"agent.config.template.json",
|
|
21
22
|
"package-lock.json",
|
|
22
23
|
"tsconfig.json"
|