Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion .github/workflows/test-scripts.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Test Detection Scripts
name: Test Scripts

on:
push:
Expand All @@ -14,15 +14,38 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4

- name: Run detection script
run: |
chmod +x detect-openclaw.sh
./detect-openclaw.sh

- name: Run removal script
run: |
chmod +x remove-openclaw.sh
./remove-openclaw.sh

- name: Install bats-core
run: |
git clone --depth 1 https://github.com/bats-core/bats-core.git /tmp/bats-core
sudo /tmp/bats-core/install.sh /usr/local

- name: Run removal tests
run: bats tests/remove-openclaw.bats

test-windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4

- name: Run detection script
run: .\detect-openclaw.ps1
shell: powershell

- name: Run removal script
run: .\remove-openclaw.ps1
shell: powershell

- name: Run removal tests
run: Invoke-Pester -Path tests\remove-openclaw.Tests.ps1 -Output Detailed -CI
shell: powershell
86 changes: 80 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ Also check out:

---

# OpenClaw Detection Scripts - TL;DR
# OpenClaw Detection & Removal Scripts - TL;DR

Detection scripts for MDM deployment to identify OpenClaw installations on managed devices.
Detection scripts for MDM deployment to identify OpenClaw installations on managed devices, plus removal scripts to uninstall them.

## What It Detects

Expand All @@ -47,39 +47,88 @@ Detection scripts for MDM deployment to identify OpenClaw installations on manag

## Usage

### macOS/Linux
### Detection

#### macOS/Linux

```bash
curl -sL https://raw.githubusercontent.com/knostic/openclaw-detect/refs/heads/main/detect-openclaw.sh | bash
```

### Windows (PowerShell)
#### Windows (PowerShell)

```powershell
iwr -useb https://raw.githubusercontent.com/knostic/openclaw-detect/refs/heads/main/detect-openclaw.ps1 | iex
```

### Without curl
#### Without curl

Copy [`detect-openclaw.sh`](detect-openclaw.sh) (macOS/Linux) or [`detect-openclaw.ps1`](detect-openclaw.ps1) (Windows) and run directly.

### Removal

#### macOS/Linux

```bash
curl -sL https://raw.githubusercontent.com/knostic/openclaw-detect/refs/heads/main/remove-openclaw.sh | sudo bash
```

#### Windows (PowerShell, as Administrator)

```powershell
iwr -useb https://raw.githubusercontent.com/knostic/openclaw-detect/refs/heads/main/remove-openclaw.ps1 | iex
```

#### Without curl

Copy [`remove-openclaw.sh`](remove-openclaw.sh) (macOS/Linux) or [`remove-openclaw.ps1`](remove-openclaw.ps1) (Windows) and run directly.

### Run as root/admin

Running with elevated privileges scans all user directories:
Running with elevated privileges scans and acts on all user directories:

```bash
# Detection
curl -sL https://raw.githubusercontent.com/knostic/openclaw-detect/refs/heads/main/detect-openclaw.sh | sudo bash

# Removal
curl -sL https://raw.githubusercontent.com/knostic/openclaw-detect/refs/heads/main/remove-openclaw.sh | sudo bash
```

## What It Removes

The removal scripts perform a phased cleanup in this order:

1. **Stop services** — launchd (macOS), systemd (Linux), scheduled tasks (Windows)
2. **Kill gateway processes** — on default and configured ports
3. **Docker** — stop/remove containers and images matching `openclaw`
4. **Package managers** — brew, npm, volta (macOS/Linux); scoop, npm, winget (Windows)
5. **CLI binaries** — global and per-user install locations
6. **macOS app bundle** — `/Applications/OpenClaw.app`
7. **State directories** — `~/.openclaw` (or profile variant) unless `OPENCLAW_KEEP_DATA=1`
8. **WSL** (Windows only) — openclaw binary inside WSL

### Removal Exit Codes

| Exit Code | Meaning | MDM Status |
|-----------|---------|------------|
| 0 | All removed (or nothing to remove) | Success (clean) |
| 1 | Partial removal (some items failed) | Error (investigate) |
| 2 | Script error | Error (investigate) |

## Environment Variables

| Variable | Default | Description |
|----------|---------|-------------|
| `OPENCLAW_PROFILE` | (none) | Profile name for multi-instance setups |
| `OPENCLAW_GATEWAY_PORT` | 18789 | Gateway port to check |
| `OPENCLAW_KEEP_DATA` | 0 | Set to `1` to preserve state directories during removal |
| `OPENCLAW_DRY_RUN` | 0 | Set to `1` to log removal actions without performing them |

## Example Output

### Detection

```
summary: installed-and-running
platform: darwin
Expand All @@ -94,6 +143,31 @@ docker-container: not-found
docker-image: not-found
```

### Removal

```
result: all-removed
platform: darwin
removed: launchd service gui/501/bot.molt.gateway
removed: kill gateway process pid=12345 on port 18789
removed: brew uninstall openclaw
removed: binary /usr/local/bin/openclaw
removed: macOS app bundle /Applications/OpenClaw.app
removed: state-dir /Users/alice/.openclaw
```

### Removal (dry run)

```
result: nothing-to-remove
platform: darwin
mode: dry-run
dry-run: launchd service gui/501/bot.molt.gateway
dry-run: brew uninstall openclaw
dry-run: binary /usr/local/bin/openclaw
dry-run: state-dir /Users/alice/.openclaw
```

---

## MDM Integration
Expand Down
Loading