lightman-agent 1.0.20 → 1.0.22

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/bin/cms-agent.js CHANGED
@@ -8,27 +8,30 @@ import { spawnSync } from 'child_process';
8
8
  import { createInterface } from 'readline/promises';
9
9
  import { stdin as input, stdout as output, cwd, platform, exit } from 'process';
10
10
 
11
- const DEFAULT_SERVER = 'http://192.168.10.100:3401';
12
- const INSTALL_CONFIG_PATH = 'C:\\Program Files\\Lightman\\Agent\\agent.config.json';
13
-
14
- function printUsage() {
15
- console.log(`
16
- cms-agent <command> [options]
17
-
18
- Commands:
19
- install Prompt slug and server IP, install agent with ShellReplace, reboot
20
- setup Alias of install
21
- update Reinstall/update using installed config, reboot
22
-
23
- Options:
24
- --slug <value> Device slug (example: C-AV01)
25
- --server <url> Server URL or IP (example: 192.168.10.100 or http://192.168.10.100:3401)
26
- --timezone <tz> Timezone override (default: Asia/Kolkata)
27
- --pair-timeout <s> Wait time for pairing in seconds (default: 900, 0 = no timeout)
28
- --no-restart Skip reboot after successful install/update
29
- -h, --help Show help
30
- `);
31
- }
11
+ const DEFAULT_SERVER = 'http://192.168.10.100:3401';
12
+ const INSTALL_CONFIG_PATH = 'C:\\Program Files\\Lightman\\Agent\\agent.config.json';
13
+ const INSTALL_PACKAGE_PATH = 'C:\\Program Files\\Lightman\\Agent\\package.json';
14
+
15
+ function printUsage() {
16
+ console.log(`
17
+ cms-agent <command> [options]
18
+
19
+ Commands:
20
+ install Prompt slug and server IP, install agent with ShellReplace, reboot
21
+ setup Alias of install
22
+ update Reinstall/update using installed config, reboot
23
+ version Show CLI package version and installed agent version
24
+
25
+ Options:
26
+ --slug <value> Device slug (example: C-AV01)
27
+ --server <url> Server URL or IP (example: 192.168.10.100 or http://192.168.10.100:3401)
28
+ --timezone <tz> Timezone override (default: Asia/Kolkata)
29
+ --pair-timeout <s> Wait time for pairing in seconds (default: 900, 0 = no timeout)
30
+ --no-restart Skip reboot after successful install/update
31
+ -v, --version Show version
32
+ -h, --help Show help
33
+ `);
34
+ }
32
35
 
33
36
  function parseArgs(argv) {
34
37
  const args = {};
@@ -177,25 +180,51 @@ async function promptServer(defaultServer) {
177
180
  }
178
181
  }
179
182
 
180
- function resolveInstallScript() {
181
- const here = dirname(fileURLToPath(import.meta.url));
182
- const packaged = resolve(here, '../scripts/install-windows.ps1');
183
- const localRepo = resolve(cwd(), 'scripts/install-windows.ps1');
184
- if (existsSync(packaged)) return packaged;
185
- if (existsSync(localRepo)) return localRepo;
186
- throw new Error('install-windows.ps1 not found. Expected in package scripts/ or current folder scripts/.');
187
- }
188
-
189
- function installUsingPowerShell({ scriptPath, slug, server, timezone, pairingTimeoutSeconds, noRestart }) {
190
- console.log(`powershell -ExecutionPolicy Bypass -File scripts\\install-windows.ps1 -Slug "${slug}" -Server "${server}" -ShellReplace`);
191
- const args = ['-ExecutionPolicy', 'Bypass', '-File', scriptPath, '-Slug', slug, '-Server', server, '-ShellReplace'];
192
- if (timezone) {
193
- args.push('-Timezone', timezone);
194
- }
195
- if (Number.isInteger(pairingTimeoutSeconds) && pairingTimeoutSeconds >= 0) {
196
- args.push('-PairingTimeoutSeconds', String(pairingTimeoutSeconds));
197
- }
198
- runOrFail('powershell.exe', args);
183
+ function resolveInstallScript() {
184
+ const here = dirname(fileURLToPath(import.meta.url));
185
+ const packaged = resolve(here, '../scripts/install-windows.ps1');
186
+ const localRepo = resolve(cwd(), 'scripts/install-windows.ps1');
187
+ if (existsSync(packaged)) return packaged;
188
+ if (existsSync(localRepo)) return localRepo;
189
+ throw new Error('install-windows.ps1 not found. Expected in package scripts/ or current folder scripts/.');
190
+ }
191
+
192
+ function scriptSupportsPairingTimeout(scriptPath) {
193
+ try {
194
+ const script = readFileSync(scriptPath, 'utf8');
195
+ return script.includes('PairingTimeoutSeconds');
196
+ } catch {
197
+ return false;
198
+ }
199
+ }
200
+
201
+ function runVersion() {
202
+ const here = dirname(fileURLToPath(import.meta.url));
203
+ const bundledPkg = safeReadJson(resolve(here, '../package.json')) || {};
204
+ const installedPkg = safeReadJson(INSTALL_PACKAGE_PATH) || {};
205
+
206
+ const cliVersion = typeof bundledPkg.version === 'string' ? bundledPkg.version : 'unknown';
207
+ const installedVersion = typeof installedPkg.version === 'string' ? installedPkg.version : 'not-installed';
208
+
209
+ console.log(`lightman-agent cli: ${cliVersion}`);
210
+ console.log(`lightman-agent installed: ${installedVersion}`);
211
+ console.log(`node: ${process.version}`);
212
+ }
213
+
214
+ function installUsingPowerShell({ scriptPath, slug, server, timezone, pairingTimeoutSeconds, noRestart }) {
215
+ console.log(`powershell -ExecutionPolicy Bypass -File scripts\\install-windows.ps1 -Slug "${slug}" -Server "${server}" -ShellReplace`);
216
+ const args = ['-ExecutionPolicy', 'Bypass', '-File', scriptPath, '-Slug', slug, '-Server', server, '-ShellReplace'];
217
+ if (timezone) {
218
+ args.push('-Timezone', timezone);
219
+ }
220
+ if (
221
+ Number.isInteger(pairingTimeoutSeconds)
222
+ && pairingTimeoutSeconds >= 0
223
+ && scriptSupportsPairingTimeout(scriptPath)
224
+ ) {
225
+ args.push('-PairingTimeoutSeconds', String(pairingTimeoutSeconds));
226
+ }
227
+ runOrFail('powershell.exe', args);
199
228
 
200
229
  if (!noRestart) {
201
230
  console.log('Installation completed. Rebooting now...');
@@ -262,19 +291,24 @@ async function runUpdate(opts) {
262
291
  installUsingPowerShell({ scriptPath, slug, server, timezone, pairingTimeoutSeconds, noRestart });
263
292
  }
264
293
 
265
- async function main() {
266
- const [, , commandRaw, ...rest] = process.argv;
267
- const command = commandRaw || '';
268
- const opts = parseArgs(rest);
269
-
270
- if (!command || opts.help || command === 'help' || command === '--help' || command === '-h') {
271
- printUsage();
272
- return;
273
- }
274
-
275
- if (command === 'install' || command === 'setup') {
276
- await runInstall(opts);
277
- return;
294
+ async function main() {
295
+ const [, , commandRaw, ...rest] = process.argv;
296
+ const command = commandRaw || '';
297
+ const opts = parseArgs(rest);
298
+
299
+ if (!command || opts.help || command === 'help' || command === '--help' || command === '-h') {
300
+ printUsage();
301
+ return;
302
+ }
303
+
304
+ if (command === 'version' || command === '--version' || command === '-v') {
305
+ runVersion();
306
+ return;
307
+ }
308
+
309
+ if (command === 'install' || command === 'setup') {
310
+ await runInstall(opts);
311
+ return;
278
312
  }
279
313
  if (command === 'update') {
280
314
  await runUpdate(opts);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lightman-agent",
3
- "version": "1.0.20",
3
+ "version": "1.0.22",
4
4
  "description": "LIGHTMAN Agent - System-level daemon for museum display machines",
5
5
  "private": false,
6
6
  "type": "module",
@@ -9,13 +9,14 @@
9
9
  # powershell -ExecutionPolicy Bypass -File install-windows.ps1 -Slug "F-AV01" -Server "http://..." -ShellReplace
10
10
  #Requires -RunAsAdministrator
11
11
 
12
- param(
13
- [Parameter(Mandatory=$true)] [string]$Slug,
14
- [Parameter(Mandatory=$true)] [string]$Server,
15
- [string]$Timezone = "Asia/Kolkata",
16
- [string]$Username = "",
17
- [switch]$ShellReplace = $false
18
- )
12
+ param(
13
+ [Parameter(Mandatory=$true)] [string]$Slug,
14
+ [Parameter(Mandatory=$true)] [string]$Server,
15
+ [string]$Timezone = "Asia/Kolkata",
16
+ [string]$Username = "",
17
+ [switch]$ShellReplace = $false,
18
+ [int]$PairingTimeoutSeconds = 900
19
+ )
19
20
 
20
21
  $ErrorActionPreference = "Stop"
21
22
 
@@ -25,11 +26,35 @@ $ChromeData = "C:\ProgramData\Lightman\chrome-kiosk"
25
26
  $NssmDir = "C:\ProgramData\Lightman\nssm"
26
27
  $NssmExe = "$NssmDir\nssm.exe"
27
28
  $ServiceName = "LightmanAgent"
28
- $GuardianTask = "LIGHTMAN Guardian"
29
- $KioskTask = "LIGHTMAN Kiosk Browser"
30
- $AgentTask = "LIGHTMAN Agent"
31
- $ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
32
- $AgentDir = Split-Path -Parent $ScriptDir
29
+ $GuardianTask = "LIGHTMAN Guardian"
30
+ $KioskTask = "LIGHTMAN Kiosk Browser"
31
+ $AgentTask = "LIGHTMAN Agent"
32
+ $ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
33
+ $AgentDir = Split-Path -Parent $ScriptDir
34
+
35
+ function Ensure-PathContains {
36
+ param(
37
+ [Parameter(Mandatory=$true)][ValidateSet('Machine','User')] [string]$Scope,
38
+ [Parameter(Mandatory=$true)] [string]$Entry
39
+ )
40
+ $current = [System.Environment]::GetEnvironmentVariable("Path", $Scope)
41
+ if (-not $current) { $current = "" }
42
+ $parts = $current -split ';' | Where-Object { $_ -and $_.Trim() -ne "" }
43
+ $normalizedEntry = $Entry.TrimEnd('\')
44
+ $exists = $false
45
+ foreach ($p in $parts) {
46
+ if ($p.TrimEnd('\') -ieq $normalizedEntry) {
47
+ $exists = $true
48
+ break
49
+ }
50
+ }
51
+ if (-not $exists) {
52
+ $newPath = if ($current -and $current.Trim() -ne "") { "$current;$Entry" } else { $Entry }
53
+ [System.Environment]::SetEnvironmentVariable("Path", $newPath, $Scope)
54
+ return $true
55
+ }
56
+ return $false
57
+ }
33
58
 
34
59
  if (-not $Username) { $Username = $env:USERNAME }
35
60
 
@@ -91,9 +116,9 @@ Write-Host ""
91
116
  # PART 1: BUILD & INSTALL
92
117
  # ============================================================
93
118
 
94
- # --- 1. Node.js ---
95
- Write-Host "[1/19] Checking Node.js..." -ForegroundColor Yellow
96
- try {
119
+ # --- 1. Node.js ---
120
+ Write-Host "[1/19] Checking Node.js..." -ForegroundColor Yellow
121
+ try {
97
122
  $nodeVersion = (node -v) -replace 'v', ''
98
123
  if ([int]($nodeVersion.Split('.')[0]) -lt 20) { throw "old" }
99
124
  Write-Host " Found Node.js v$nodeVersion"
@@ -106,7 +131,19 @@ try {
106
131
  $env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
107
132
  if (-not (Get-Command node -ErrorAction SilentlyContinue)) { Write-Host " FATAL: Node.js install failed!" -ForegroundColor Red; exit 1 }
108
133
  Write-Host " Node.js installed" -ForegroundColor Green
109
- }
134
+ }
135
+
136
+ # Always ensure Node path remains available after kiosk conversion
137
+ $nodePath = (Get-Command node).Source
138
+ $nodeDir = Split-Path -Parent $nodePath
139
+ $addedMachine = Ensure-PathContains -Scope "Machine" -Entry $nodeDir
140
+ $addedUser = Ensure-PathContains -Scope "User" -Entry $nodeDir
141
+ $env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
142
+ if ($addedMachine -or $addedUser) {
143
+ Write-Host " Ensured Node.js path in PATH: $nodeDir" -ForegroundColor Green
144
+ } else {
145
+ Write-Host " Node.js path already present in PATH"
146
+ }
110
147
 
111
148
  # --- 2. Build ---
112
149
  Write-Host "[2/19] Building agent..." -ForegroundColor Yellow