{
  "uid": "cogitave.learn.install-the-massar-agent.remove-the-agent",
  "kind": "moduleUnit",
  "href": "/modules/install-the-massar-agent/remove-the-agent/",
  "title": "Remove the agent cleanly",
  "summary": "",
  "type": null,
  "products": [],
  "roles": [],
  "levels": [],
  "subjects": [],
  "headings": [
    "Linux: sudo ./uninstall.sh",
    "Windows: Settings &gt; Apps, or uninstall.ps1 directly",
    "The release proves its own install path",
    "What removal does - and does not - erase"
  ],
  "source": "Each installer ships a matching uninstaller that undoes what it did. This unit covers what each one removes, in what order, and - just as importantly - what a clean removal does not touch.\n\n## Linux: `sudo ./uninstall.sh`\n\nWhen `install.sh` finishes, it tells you exactly how to undo it: `sudo ./uninstall.sh`. The uninstaller ships next to the installer in `install/`.\n\n```bash\nsudo ./install/uninstall.sh\n```\n\nIn order, it:\n\n1. Requires root.\n2. Disables and stops `massar-agent.service` if it's registered - `systemctl disable --now`, tolerating a unit that's already gone.\n3. Deletes the unit file at `/etc/systemd/system/massar-agent.service` and reloads systemd.\n4. Removes the binary at `/usr/local/bin/massar-agent`.\n5. Removes `/etc/massar` entirely, including `agent.env` and the device's token with it.\n\nThe script is idempotent: it guards the service lookup and uses `rm -f` / `rm -rf`, so running it twice, or on a machine that was never fully installed, does not error. It prints `[OK] Massar agent removed.` when it's done.\n\n## Windows: Settings > Apps, or `uninstall.ps1` directly\n\nFrom the OS's own uninstall surface:\n\n**Settings > Apps > Installed apps > Cogitave Massar > Uninstall**\n\n- which runs the copy of `uninstall.ps1` the installer staged, via the `UninstallString` it registered. Or run it yourself, as Administrator:\n\n```powershell\n.\\install\\uninstall.ps1\n```\n\nIn order, it:\n\n1. Requires Administrator.\n2. Stops the service with `Stop-Service -Force` if it isn't already stopped, then deletes the registration with `sc.exe delete`.\n3. Removes the **Settings > Apps registry entry before the files** - deliberately, so a partially completed removal can never leave a listed app whose uninstaller has already been deleted out from under it.\n4. Deletes everything under the install directory except the script currently running, then hands off to a detached, hidden PowerShell process that sleeps two seconds and deletes the directory itself once the original process has exited - a script cannot delete the folder it's executing from while it's still running.\n\nIt prints `[OK] Massar agent removed.` when done. Removal is best-effort and idempotent (`-ErrorAction SilentlyContinue` throughout), so re-running it on an already-clean machine is safe.\n\n## The release proves its own install path\n\nCogitave's release pipeline gates each release on a clean-room install of the freshly built artifact. The `verify-install` job in `release-artifacts.yml` runs `install.sh --verify` to confirm the preflight passes, then downloads the just-built `massar-agent-linux-x86_64` and its `.sha256` straight from the release, checksum-verifies the binary, marks it executable, and asserts it runs. The workflow's own comment states the intent:\n\n> Clean-room: run the installer against the freshly published Linux artifact and assert the binary lands + reports its version (mirrors namzu's consumer gate).\n\nA release isn't trusted until its own install path has been exercised against a real, freshly built artifact - not just built and uploaded. The job proves the install and download path; it does not run the uninstaller. Each installer still ships a matching `uninstall.sh` / `uninstall.ps1` alongside it, and on Windows the installer also wires that script into Settings > Apps.\n\n## What removal does - and does not - erase\n\nRemoval deletes what lives **on the device**: the binary, the config (and the token inside it), the service registration, and, on Windows, the Settings entry. It does not, and structurally cannot, touch anything on the Diyar side. Every session an operator ran against this device while the agent was active was authorized by Diyar RBAC and recorded there - that history is Diyar's record of what happened, not a local log the agent keeps, so uninstalling the agent has no effect on it. If you need session history removed as well as the device, that's a Diyar-side data question, not something either uninstaller is positioned to answer.\n",
  "partOf": "cogitave.learn.install-the-massar-agent",
  "durationInMinutes": 6,
  "quiz": null
}