lightman-agent 1.0.12 → 1.0.14

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/scripts/setup.ps1 CHANGED
@@ -1,132 +1,116 @@
1
- # LIGHTMAN Agent - Device Setup Script (Windows)
2
- # Generates agent.config.json for this specific device.
3
- #
4
- # Usage (run from agent directory or scripts directory):
5
- # powershell -ExecutionPolicy Bypass -File setup.ps1 -Slug "f-av01" -Server "http://192.168.10.100:3401"
6
- # powershell -ExecutionPolicy Bypass -File setup.ps1 -Slug "f-av01" -Server "http://192.168.10.100:3401" -Timezone "Asia/Kolkata"
7
- #
8
- # This script MUST be run once on every new device installation.
9
- # It clears any cached identity so the device provisions fresh.
10
-
11
- param(
12
- [Parameter(Mandatory=$true)]
13
- [string]$Slug,
14
-
15
- [Parameter(Mandatory=$true)]
16
- [string]$Server,
17
-
18
- [Parameter(Mandatory=$false)]
19
- [string]$Timezone = "Asia/Kolkata",
20
-
21
- [Parameter(Mandatory=$false)]
22
- [string]$InstallDir = $null,
23
-
24
- [Parameter(Mandatory=$false)]
25
- [switch]$ShellMode = $false
26
- )
27
-
28
- $ErrorActionPreference = "Stop"
29
- $ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
30
- $AgentDir = Split-Path -Parent $ScriptDir
31
-
32
- # Default install dir: the agent folder itself (for dev) or passed explicitly
33
- if (-not $InstallDir) {
34
- $InstallDir = $AgentDir
35
- }
36
-
37
- Write-Host ""
38
- Write-Host "=== LIGHTMAN Agent - Device Setup ===" -ForegroundColor Cyan
39
- Write-Host " Slug: $Slug"
40
- Write-Host " Server: $Server"
41
- Write-Host " Install dir: $InstallDir"
42
- Write-Host " Timezone: $Timezone"
43
- Write-Host ""
44
-
45
- function Get-KioskBrowserPath {
46
- $candidates = @(
47
- "C:\Program Files\Google\Chrome\Application\chrome.exe",
48
- "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe",
49
- (Join-Path $env:LOCALAPPDATA "Google\Chrome\Application\chrome.exe"),
50
- "C:\Program Files\Microsoft\Edge\Application\msedge.exe",
51
- "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe",
52
- (Join-Path $env:LOCALAPPDATA "Microsoft\Edge\Application\msedge.exe")
53
- ) | Where-Object { $_ -and (Test-Path $_) }
54
-
55
- if ($candidates.Count -gt 0) {
56
- return $candidates[0]
57
- }
58
-
59
- throw "Neither Google Chrome nor Microsoft Edge was found. Install one of them and re-run setup."
60
- }
61
-
62
- # 1. Clear cached identity (CRITICAL - prevents old device credentials leaking)
63
- $IdentityFile = Join-Path $InstallDir ".lightman-identity.json"
64
- if (Test-Path $IdentityFile) {
65
- Remove-Item $IdentityFile -Force
66
- Write-Host "[OK] Cleared old identity cache (.lightman-identity.json)" -ForegroundColor Green
67
- } else {
68
- Write-Host "[OK] No existing identity cache found (clean install)" -ForegroundColor DarkGray
69
- }
70
-
71
- # 2. Kiosk display URL - always localhost since agent runs the static server locally on port 3403
72
- $KioskUrl = "http://localhost:3403/display/$Slug"
73
-
74
- # 3. Detect browser path
75
- try {
76
- $BrowserPath = Get-KioskBrowserPath
77
- Write-Host "[OK] Using kiosk browser: $BrowserPath" -ForegroundColor Green
78
- } catch {
79
- Write-Host "[ERROR] $($_.Exception.Message)" -ForegroundColor Red
80
- exit 1
81
- }
82
-
83
- $ChromeDataDir = "C:\ProgramData\Lightman\chrome-kiosk"
84
-
85
- # 4. Read template
86
- $TemplatePath = Join-Path $AgentDir "agent.config.template.json"
87
- if (-not (Test-Path $TemplatePath)) {
88
- # If running from install dir (post-install), template should have been copied there
89
- $TemplatePath = Join-Path $InstallDir "agent.config.template.json"
90
- }
91
- if (-not (Test-Path $TemplatePath)) {
92
- Write-Host "[ERROR] Template not found. Expected: $TemplatePath" -ForegroundColor Red
93
- exit 1
94
- }
95
-
96
- $Template = Get-Content $TemplatePath -Raw
97
-
98
- # 5. Replace placeholders
99
- $BrowserEscaped = $BrowserPath -replace '\\', '\\'
100
- $ChromeDirEscaped = $ChromeDataDir -replace '\\', '\\'
101
-
102
- $Config = $Template `
103
- -replace '__SERVER_URL__', $Server `
104
- -replace '__DEVICE_SLUG__', $Slug `
105
- -replace '__KIOSK_URL__', $KioskUrl `
106
- -replace '__BROWSER_PATH__', $BrowserEscaped `
107
- -replace '__CHROME_DATA_DIR__', $ChromeDirEscaped `
108
- -replace 'Asia/Kolkata', $Timezone
109
-
110
- # 6. Inject shellMode into kiosk config if requested
111
- if ($ShellMode) {
112
- # Parse as object, set shellMode, re-serialize (reliable, no regex fragility)
113
- $configObj = $Config | ConvertFrom-Json
114
- $configObj.kiosk | Add-Member -NotePropertyName "shellMode" -NotePropertyValue $true -Force
115
- $Config = $configObj | ConvertTo-Json -Depth 4
116
- Write-Host "[OK] Shell replacement mode enabled in config" -ForegroundColor Magenta
117
- }
118
-
119
- # 7. Write config
120
- $ConfigPath = Join-Path $InstallDir "agent.config.json"
121
- # Write as UTF-8 WITHOUT BOM (BOM breaks JSON parsing in Node.js)
122
- [System.IO.File]::WriteAllText($ConfigPath, $Config, [System.Text.UTF8Encoding]::new($false))
123
-
124
- Write-Host "[OK] Created agent.config.json" -ForegroundColor Green
125
- Write-Host ""
126
- Write-Host " Device slug : $Slug"
127
- Write-Host " Server : $Server"
128
- Write-Host " Kiosk URL : $KioskUrl"
129
- Write-Host ""
130
- Write-Host "Setup complete. Start the agent - it will provision automatically." -ForegroundColor Cyan
131
- Write-Host "(If IP matches, provisioning is instant. Otherwise enter pairing code shown in admin.)" -ForegroundColor DarkGray
132
- Write-Host ""
1
+ # LIGHTMAN Agent - Device Setup Script (Windows)
2
+ # Generates agent.config.json for this specific device.
3
+ #
4
+ # Usage (run from agent directory or scripts directory):
5
+ # powershell -ExecutionPolicy Bypass -File setup.ps1 -Slug "f-av01" -Server "http://192.168.1.100:3401"
6
+ # powershell -ExecutionPolicy Bypass -File setup.ps1 -Slug "f-av01" -Server "http://192.168.1.100:3401" -Timezone "Asia/Kolkata"
7
+ #
8
+ # This script MUST be run once on every new device installation.
9
+ # It clears any cached identity so the device provisions fresh.
10
+
11
+ param(
12
+ [Parameter(Mandatory=$true)]
13
+ [string]$Slug,
14
+
15
+ [Parameter(Mandatory=$true)]
16
+ [string]$Server,
17
+
18
+ [Parameter(Mandatory=$false)]
19
+ [string]$Timezone = "Asia/Kolkata",
20
+
21
+ [Parameter(Mandatory=$false)]
22
+ [string]$InstallDir = $null,
23
+
24
+ [Parameter(Mandatory=$false)]
25
+ [switch]$ShellMode = $false
26
+ )
27
+
28
+ $ErrorActionPreference = "Stop"
29
+ $ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
30
+ $AgentDir = Split-Path -Parent $ScriptDir
31
+
32
+ # Default install dir: the agent folder itself (for dev) or passed explicitly
33
+ if (-not $InstallDir) {
34
+ $InstallDir = $AgentDir
35
+ }
36
+
37
+ Write-Host ""
38
+ Write-Host "=== LIGHTMAN Agent - Device Setup ===" -ForegroundColor Cyan
39
+ Write-Host " Slug: $Slug"
40
+ Write-Host " Server: $Server"
41
+ Write-Host " Install dir: $InstallDir"
42
+ Write-Host " Timezone: $Timezone"
43
+ Write-Host ""
44
+
45
+ # 1. Clear cached identity (CRITICAL - prevents old device credentials leaking)
46
+ $IdentityFile = Join-Path $InstallDir ".lightman-identity.json"
47
+ if (Test-Path $IdentityFile) {
48
+ Remove-Item $IdentityFile -Force
49
+ Write-Host "[OK] Cleared old identity cache (.lightman-identity.json)" -ForegroundColor Green
50
+ } else {
51
+ Write-Host "[OK] No existing identity cache found (clean install)" -ForegroundColor DarkGray
52
+ }
53
+
54
+ # 2. Kiosk display URL - always localhost since agent runs the static server locally on port 3403
55
+ $KioskUrl = "http://localhost:3403/display/$Slug"
56
+
57
+ # 3. Detect browser path
58
+ $BrowserPath = "C:\Program Files\Google\Chrome\Application\chrome.exe"
59
+ if (-not (Test-Path $BrowserPath)) {
60
+ $BrowserPath = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
61
+ }
62
+ if (-not (Test-Path $BrowserPath)) {
63
+ $BrowserPath = "chromium-browser"
64
+ Write-Host "[WARN] Chrome not found - using 'chromium-browser'" -ForegroundColor Yellow
65
+ }
66
+
67
+ $ChromeDataDir = "C:\ProgramData\Lightman\chrome-kiosk"
68
+
69
+ # 4. Read template
70
+ $TemplatePath = Join-Path $AgentDir "agent.config.template.json"
71
+ if (-not (Test-Path $TemplatePath)) {
72
+ # If running from install dir (post-install), template should have been copied there
73
+ $TemplatePath = Join-Path $InstallDir "agent.config.template.json"
74
+ }
75
+ if (-not (Test-Path $TemplatePath)) {
76
+ Write-Host "[ERROR] Template not found. Expected: $TemplatePath" -ForegroundColor Red
77
+ exit 1
78
+ }
79
+
80
+ $Template = Get-Content $TemplatePath -Raw
81
+
82
+ # 5. Replace placeholders
83
+ $BrowserEscaped = $BrowserPath -replace '\\', '\\'
84
+ $ChromeDirEscaped = $ChromeDataDir -replace '\\', '\\'
85
+
86
+ $Config = $Template `
87
+ -replace '__SERVER_URL__', $Server `
88
+ -replace '__DEVICE_SLUG__', $Slug `
89
+ -replace '__KIOSK_URL__', $KioskUrl `
90
+ -replace '__BROWSER_PATH__', $BrowserEscaped `
91
+ -replace '__CHROME_DATA_DIR__', $ChromeDirEscaped `
92
+ -replace 'Asia/Kolkata', $Timezone
93
+
94
+ # 6. Inject shellMode into kiosk config if requested
95
+ if ($ShellMode) {
96
+ # Parse as object, set shellMode, re-serialize (reliable, no regex fragility)
97
+ $configObj = $Config | ConvertFrom-Json
98
+ $configObj.kiosk | Add-Member -NotePropertyName "shellMode" -NotePropertyValue $true -Force
99
+ $Config = $configObj | ConvertTo-Json -Depth 4
100
+ Write-Host "[OK] Shell replacement mode enabled in config" -ForegroundColor Magenta
101
+ }
102
+
103
+ # 7. Write config
104
+ $ConfigPath = Join-Path $InstallDir "agent.config.json"
105
+ # Write as UTF-8 WITHOUT BOM (BOM breaks JSON parsing in Node.js)
106
+ [System.IO.File]::WriteAllText($ConfigPath, $Config, [System.Text.UTF8Encoding]::new($false))
107
+
108
+ Write-Host "[OK] Created agent.config.json" -ForegroundColor Green
109
+ Write-Host ""
110
+ Write-Host " Device slug : $Slug"
111
+ Write-Host " Server : $Server"
112
+ Write-Host " Kiosk URL : $KioskUrl"
113
+ Write-Host ""
114
+ Write-Host "Setup complete. Start the agent - it will provision automatically." -ForegroundColor Cyan
115
+ Write-Host "(If IP matches, provisioning is instant. Otherwise enter pairing code shown in admin.)" -ForegroundColor DarkGray
116
+ Write-Host ""
package/scripts/setup.sh CHANGED
@@ -1,115 +1,115 @@
1
- #!/usr/bin/env bash
2
- # LIGHTMAN Agent — Device Setup Script (Linux / Raspberry Pi)
3
- # Generates agent.config.json for this specific device.
4
- #
5
- # Usage:
6
- # sudo bash setup.sh --slug f-av01 --server http://192.168.10.100:3401
7
- # sudo bash setup.sh --slug f-av01 --server http://192.168.10.100:3401 --timezone Asia/Kolkata --dir /opt/lightman/agent
8
- #
9
- # This script MUST be run once on every new device installation.
10
- # It clears any cached identity so the device provisions fresh.
11
-
12
- set -euo pipefail
13
-
14
- SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
15
- AGENT_DIR="$(dirname "$SCRIPT_DIR")"
16
-
17
- # Defaults
18
- SLUG=""
19
- SERVER=""
20
- TIMEZONE="Asia/Kolkata"
21
- INSTALL_DIR="/opt/lightman/agent"
22
-
23
- # ── Parse arguments ──
24
- while [[ $# -gt 0 ]]; do
25
- case $1 in
26
- --slug) SLUG="$2"; shift 2 ;;
27
- --server) SERVER="$2"; shift 2 ;;
28
- --timezone) TIMEZONE="$2"; shift 2 ;;
29
- --dir) INSTALL_DIR="$2"; shift 2 ;;
30
- -h|--help)
31
- echo "Usage: bash setup.sh --slug SLUG --server http://SERVER:3401 [--timezone TZ] [--dir /path]"
32
- exit 0
33
- ;;
34
- *) echo "Unknown option: $1"; exit 1 ;;
35
- esac
36
- done
37
-
38
- if [[ -z "$SLUG" ]]; then
39
- echo "Error: --slug is required"
40
- echo "Usage: bash setup.sh --slug f-av01 --server http://192.168.10.100:3401"
41
- exit 1
42
- fi
43
-
44
- if [[ -z "$SERVER" ]]; then
45
- echo "Error: --server is required"
46
- echo "Usage: bash setup.sh --slug f-av01 --server http://192.168.10.100:3401"
47
- exit 1
48
- fi
49
-
50
- echo ""
51
- echo "=== LIGHTMAN Agent — Device Setup ==="
52
- echo " Slug: $SLUG"
53
- echo " Server: $SERVER"
54
- echo " Install dir: $INSTALL_DIR"
55
- echo " Timezone: $TIMEZONE"
56
- echo ""
57
-
58
- # ── 1. Clear cached identity (CRITICAL — prevents old device credentials leaking) ──
59
- IDENTITY_FILE="$INSTALL_DIR/.lightman-identity.json"
60
- if [[ -f "$IDENTITY_FILE" ]]; then
61
- rm -f "$IDENTITY_FILE"
62
- echo "[OK] Cleared old identity cache (.lightman-identity.json)"
63
- else
64
- echo "[OK] No existing identity cache found (clean install)"
65
- fi
66
-
67
- # ── 2. Derive kiosk display URL from server URL ──
68
- # Replace port with 3403 (display server)
69
- KIOSK_BASE="$(echo "$SERVER" | sed 's/:[0-9]*$//')"
70
- KIOSK_URL="${KIOSK_BASE}:3403/display/${SLUG}"
71
-
72
- # ── 3. Detect browser ──
73
- BROWSER_PATH="chromium-browser"
74
- if command -v chromium &>/dev/null; then
75
- BROWSER_PATH="chromium"
76
- elif command -v chromium-browser &>/dev/null; then
77
- BROWSER_PATH="chromium-browser"
78
- elif command -v google-chrome &>/dev/null; then
79
- BROWSER_PATH="google-chrome"
80
- fi
81
- CHROME_DATA_DIR="/opt/lightman/chrome-kiosk"
82
-
83
- # ── 4. Find template ──
84
- TEMPLATE="$AGENT_DIR/agent.config.template.json"
85
- if [[ ! -f "$TEMPLATE" ]]; then
86
- # Post-install: template may be in install dir
87
- TEMPLATE="$INSTALL_DIR/agent.config.template.json"
88
- fi
89
- if [[ ! -f "$TEMPLATE" ]]; then
90
- echo "[ERROR] Template not found at $TEMPLATE"
91
- exit 1
92
- fi
93
-
94
- # ── 5. Create install dir if needed ──
95
- mkdir -p "$INSTALL_DIR"
96
-
97
- # ── 6. Replace placeholders and write config ──
98
- sed \
99
- -e "s|__SERVER_URL__|${SERVER}|g" \
100
- -e "s|__DEVICE_SLUG__|${SLUG}|g" \
101
- -e "s|__KIOSK_URL__|${KIOSK_URL}|g" \
102
- -e "s|__BROWSER_PATH__|${BROWSER_PATH}|g" \
103
- -e "s|__CHROME_DATA_DIR__|${CHROME_DATA_DIR}|g" \
104
- -e "s|Asia/Kolkata|${TIMEZONE}|g" \
105
- "$TEMPLATE" > "$INSTALL_DIR/agent.config.json"
106
-
107
- echo "[OK] Created agent.config.json"
108
- echo ""
109
- echo " Device slug : $SLUG"
110
- echo " Server : $SERVER"
111
- echo " Kiosk URL : $KIOSK_URL"
112
- echo ""
113
- echo "Setup complete. Start the agent — it will provision automatically."
114
- echo "(If IP matches, provisioning is instant. Otherwise enter pairing code shown in admin.)"
115
- echo ""
1
+ #!/usr/bin/env bash
2
+ # LIGHTMAN Agent — Device Setup Script (Linux / Raspberry Pi)
3
+ # Generates agent.config.json for this specific device.
4
+ #
5
+ # Usage:
6
+ # sudo bash setup.sh --slug f-av01 --server http://192.168.1.100:3401
7
+ # sudo bash setup.sh --slug f-av01 --server http://192.168.1.100:3401 --timezone Asia/Kolkata --dir /opt/lightman/agent
8
+ #
9
+ # This script MUST be run once on every new device installation.
10
+ # It clears any cached identity so the device provisions fresh.
11
+
12
+ set -euo pipefail
13
+
14
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
15
+ AGENT_DIR="$(dirname "$SCRIPT_DIR")"
16
+
17
+ # Defaults
18
+ SLUG=""
19
+ SERVER=""
20
+ TIMEZONE="Asia/Kolkata"
21
+ INSTALL_DIR="/opt/lightman/agent"
22
+
23
+ # ── Parse arguments ──
24
+ while [[ $# -gt 0 ]]; do
25
+ case $1 in
26
+ --slug) SLUG="$2"; shift 2 ;;
27
+ --server) SERVER="$2"; shift 2 ;;
28
+ --timezone) TIMEZONE="$2"; shift 2 ;;
29
+ --dir) INSTALL_DIR="$2"; shift 2 ;;
30
+ -h|--help)
31
+ echo "Usage: bash setup.sh --slug SLUG --server http://SERVER:3401 [--timezone TZ] [--dir /path]"
32
+ exit 0
33
+ ;;
34
+ *) echo "Unknown option: $1"; exit 1 ;;
35
+ esac
36
+ done
37
+
38
+ if [[ -z "$SLUG" ]]; then
39
+ echo "Error: --slug is required"
40
+ echo "Usage: bash setup.sh --slug f-av01 --server http://192.168.1.100:3401"
41
+ exit 1
42
+ fi
43
+
44
+ if [[ -z "$SERVER" ]]; then
45
+ echo "Error: --server is required"
46
+ echo "Usage: bash setup.sh --slug f-av01 --server http://192.168.1.100:3401"
47
+ exit 1
48
+ fi
49
+
50
+ echo ""
51
+ echo "=== LIGHTMAN Agent — Device Setup ==="
52
+ echo " Slug: $SLUG"
53
+ echo " Server: $SERVER"
54
+ echo " Install dir: $INSTALL_DIR"
55
+ echo " Timezone: $TIMEZONE"
56
+ echo ""
57
+
58
+ # ── 1. Clear cached identity (CRITICAL — prevents old device credentials leaking) ──
59
+ IDENTITY_FILE="$INSTALL_DIR/.lightman-identity.json"
60
+ if [[ -f "$IDENTITY_FILE" ]]; then
61
+ rm -f "$IDENTITY_FILE"
62
+ echo "[OK] Cleared old identity cache (.lightman-identity.json)"
63
+ else
64
+ echo "[OK] No existing identity cache found (clean install)"
65
+ fi
66
+
67
+ # ── 2. Derive kiosk display URL from server URL ──
68
+ # Replace port with 3403 (display server)
69
+ KIOSK_BASE="$(echo "$SERVER" | sed 's/:[0-9]*$//')"
70
+ KIOSK_URL="${KIOSK_BASE}:3403/display/${SLUG}"
71
+
72
+ # ── 3. Detect browser ──
73
+ BROWSER_PATH="chromium-browser"
74
+ if command -v chromium &>/dev/null; then
75
+ BROWSER_PATH="chromium"
76
+ elif command -v chromium-browser &>/dev/null; then
77
+ BROWSER_PATH="chromium-browser"
78
+ elif command -v google-chrome &>/dev/null; then
79
+ BROWSER_PATH="google-chrome"
80
+ fi
81
+ CHROME_DATA_DIR="/opt/lightman/chrome-kiosk"
82
+
83
+ # ── 4. Find template ──
84
+ TEMPLATE="$AGENT_DIR/agent.config.template.json"
85
+ if [[ ! -f "$TEMPLATE" ]]; then
86
+ # Post-install: template may be in install dir
87
+ TEMPLATE="$INSTALL_DIR/agent.config.template.json"
88
+ fi
89
+ if [[ ! -f "$TEMPLATE" ]]; then
90
+ echo "[ERROR] Template not found at $TEMPLATE"
91
+ exit 1
92
+ fi
93
+
94
+ # ── 5. Create install dir if needed ──
95
+ mkdir -p "$INSTALL_DIR"
96
+
97
+ # ── 6. Replace placeholders and write config ──
98
+ sed \
99
+ -e "s|__SERVER_URL__|${SERVER}|g" \
100
+ -e "s|__DEVICE_SLUG__|${SLUG}|g" \
101
+ -e "s|__KIOSK_URL__|${KIOSK_URL}|g" \
102
+ -e "s|__BROWSER_PATH__|${BROWSER_PATH}|g" \
103
+ -e "s|__CHROME_DATA_DIR__|${CHROME_DATA_DIR}|g" \
104
+ -e "s|Asia/Kolkata|${TIMEZONE}|g" \
105
+ "$TEMPLATE" > "$INSTALL_DIR/agent.config.json"
106
+
107
+ echo "[OK] Created agent.config.json"
108
+ echo ""
109
+ echo " Device slug : $SLUG"
110
+ echo " Server : $SERVER"
111
+ echo " Kiosk URL : $KIOSK_URL"
112
+ echo ""
113
+ echo "Setup complete. Start the agent — it will provision automatically."
114
+ echo "(If IP matches, provisioning is instant. Otherwise enter pairing code shown in admin.)"
115
+ echo ""
@@ -1,50 +1,50 @@
1
- #!/usr/bin/env bash
2
- # LIGHTMAN Agent — Linux Uninstaller
3
- # Run as root: sudo bash uninstall-linux.sh
4
- set -euo pipefail
5
-
6
- INSTALL_DIR="/opt/lightman/agent"
7
- LOG_DIR="/var/log/lightman"
8
- SERVICE_NAME="lightman-agent"
9
-
10
- if [[ $EUID -ne 0 ]]; then
11
- echo "Error: This script must be run as root (use sudo)."
12
- exit 1
13
- fi
14
-
15
- echo "=== LIGHTMAN Agent — Linux Uninstaller ==="
16
- echo ""
17
-
18
- # --- Stop and disable service ---
19
- echo "[1/5] Stopping service..."
20
- systemctl stop "$SERVICE_NAME" 2>/dev/null || true
21
- systemctl disable "$SERVICE_NAME" 2>/dev/null || true
22
-
23
- # --- Remove systemd unit ---
24
- echo "[2/5] Removing systemd unit..."
25
- rm -f "/etc/systemd/system/${SERVICE_NAME}.service"
26
- systemctl daemon-reload
27
-
28
- # --- Remove logrotate config ---
29
- echo "[3/5] Removing logrotate config..."
30
- rm -f "/etc/logrotate.d/${SERVICE_NAME}"
31
-
32
- # --- Remove installation directory ---
33
- echo "[4/5] Removing ${INSTALL_DIR}..."
34
- rm -rf "$INSTALL_DIR"
35
-
36
- # --- Remove log directory ---
37
- echo "[5/5] Removing ${LOG_DIR}..."
38
- rm -rf "$LOG_DIR"
39
-
40
- # --- Remove user/group (optional) ---
41
- read -rp "Remove 'lightman' user and group? [y/N]: " REMOVE_USER
42
- if [[ "$REMOVE_USER" =~ ^[Yy]$ ]]; then
43
- userdel lightman 2>/dev/null || true
44
- groupdel lightman 2>/dev/null || true
45
- echo "User and group removed."
46
- fi
47
-
48
- echo ""
49
- echo "=== Uninstallation Complete ==="
50
- echo ""
1
+ #!/usr/bin/env bash
2
+ # LIGHTMAN Agent — Linux Uninstaller
3
+ # Run as root: sudo bash uninstall-linux.sh
4
+ set -euo pipefail
5
+
6
+ INSTALL_DIR="/opt/lightman/agent"
7
+ LOG_DIR="/var/log/lightman"
8
+ SERVICE_NAME="lightman-agent"
9
+
10
+ if [[ $EUID -ne 0 ]]; then
11
+ echo "Error: This script must be run as root (use sudo)."
12
+ exit 1
13
+ fi
14
+
15
+ echo "=== LIGHTMAN Agent — Linux Uninstaller ==="
16
+ echo ""
17
+
18
+ # --- Stop and disable service ---
19
+ echo "[1/5] Stopping service..."
20
+ systemctl stop "$SERVICE_NAME" 2>/dev/null || true
21
+ systemctl disable "$SERVICE_NAME" 2>/dev/null || true
22
+
23
+ # --- Remove systemd unit ---
24
+ echo "[2/5] Removing systemd unit..."
25
+ rm -f "/etc/systemd/system/${SERVICE_NAME}.service"
26
+ systemctl daemon-reload
27
+
28
+ # --- Remove logrotate config ---
29
+ echo "[3/5] Removing logrotate config..."
30
+ rm -f "/etc/logrotate.d/${SERVICE_NAME}"
31
+
32
+ # --- Remove installation directory ---
33
+ echo "[4/5] Removing ${INSTALL_DIR}..."
34
+ rm -rf "$INSTALL_DIR"
35
+
36
+ # --- Remove log directory ---
37
+ echo "[5/5] Removing ${LOG_DIR}..."
38
+ rm -rf "$LOG_DIR"
39
+
40
+ # --- Remove user/group (optional) ---
41
+ read -rp "Remove 'lightman' user and group? [y/N]: " REMOVE_USER
42
+ if [[ "$REMOVE_USER" =~ ^[Yy]$ ]]; then
43
+ userdel lightman 2>/dev/null || true
44
+ groupdel lightman 2>/dev/null || true
45
+ echo "User and group removed."
46
+ fi
47
+
48
+ echo ""
49
+ echo "=== Uninstallation Complete ==="
50
+ echo ""