feat: add unistall script

This commit is contained in:
2026-08-28 22:00:34 +02:00
parent c3a266e7a5
commit 45051a1576
3 changed files with 105 additions and 0 deletions
+9
View File
@@ -29,6 +29,15 @@ The installer asks for the agent ID, API connection, and Redis URL. It installs
Configuration is stored in `/opt/crawler/.env`. Every machine must have a unique `BASANGO_CRAWLER_AGENT_ID`.
To completely uninstall an agent, including its configuration and local SQLite data:
```bash
curl -fsSL https://raw.githubusercontent.com/bernard-ng/basango-crawler/refs/heads/main/deploy/uninstall.sh \
| sudo bash
```
The uninstaller asks for confirmation before removing the worker service, crawler files, local state, and installer-created system account. Pass `--yes` when running it unattended.
### Worker
```bash
+11
View File
@@ -33,6 +33,17 @@ You can also omit the argument and answer the URL prompt, or set `BASANGO_CRAWLE
- installs, enables, and starts only the worker service;
- keeps the previous binary at `/opt/crawler/crawler.previous` when an update changes it.
## Uninstall
To remove an agent completely, including its configuration and local SQLite data:
```bash
curl -fsSL https://raw.githubusercontent.com/bernard-ng/basango-crawler/refs/heads/main/deploy/uninstall.sh \
| sudo bash
```
From a local checkout, run `sudo ./deploy/uninstall.sh`. The script stops and disables the worker, removes its systemd unit, `/opt/crawler`, `/var/lib/crawler`, and the installer-created `basango` system account and group. It asks for confirmation first; pass `--yes` for unattended removal.
Pushing a `v*` Git tag runs the release workflow, which publishes native `aarch64` (Raspberry Pi) and `x86_64` Linux archives to the GitHub release.
Each agent ID prefixes its discovery, article, and delivery queue names, so multiple Pis can safely share Redis. The worker consumes all three concurrently and reconciles SQLite delivery records after a restart. The installer does not schedule crawls. Run `crawler schedule` yourself or configure cron later with the sources and cadence assigned to that device.
+85
View File
@@ -0,0 +1,85 @@
#!/usr/bin/env bash
set -Eeuo pipefail
INSTALL_DIR=/opt/crawler
STATE_DIR=/var/lib/crawler
SERVICE_USER=basango
SERVICE_NAME=basango-crawler-worker.service
WORKER_UNIT="/etc/systemd/system/${SERVICE_NAME}"
die() {
printf 'error: %s\n' "$*" >&2
exit 1
}
require_command() {
command -v "$1" >/dev/null 2>&1 || die "required command not found: $1"
}
confirm_removal() {
local answer=
printf 'This will permanently remove the Basango crawler, its configuration, and all local agent data.\n' >&2
read -r -p 'Continue? [y/N] ' answer </dev/tty || die "cannot read confirmation from /dev/tty (use --yes for unattended removal)"
[[ $answer == [yY] || $answer == [yY][eE][sS] ]] || {
printf 'Uninstall cancelled.\n'
exit 0
}
}
remove_service_account() {
local passwd_entry home shell
passwd_entry=$(getent passwd "$SERVICE_USER" || true)
if [[ -n $passwd_entry ]]; then
IFS=: read -r _ _ _ _ _ home shell <<<"$passwd_entry"
if [[ $home != "$STATE_DIR" || $shell != /usr/sbin/nologin ]]; then
printf 'Keeping user %s because it does not match the account created by the installer.\n' "$SERVICE_USER" >&2
return
fi
userdel "$SERVICE_USER"
fi
if getent group "$SERVICE_USER" >/dev/null 2>&1; then
if ! groupdel "$SERVICE_USER"; then
printf 'Keeping group %s because it is still in use.\n' "$SERVICE_USER" >&2
fi
fi
}
assume_yes=false
case ${1:-} in
--yes|-y)
assume_yes=true
;;
'')
;;
*)
die "usage: $0 [--yes]"
;;
esac
[[ $# -le 1 ]] || die "usage: $0 [--yes]"
[[ ${EUID} -eq 0 ]] || die "run this uninstaller as root (for example: sudo ./deploy/uninstall.sh)"
[[ $(uname -s) == Linux ]] || die "this uninstaller supports Linux/systemd hosts"
require_command systemctl
require_command getent
require_command userdel
require_command groupdel
require_command rm
if [[ $assume_yes != true ]]; then
confirm_removal
fi
printf 'Stopping and disabling the crawler worker...\n'
systemctl disable --now "$SERVICE_NAME" >/dev/null 2>&1 || true
rm -f -- "$WORKER_UNIT"
systemctl daemon-reload
systemctl reset-failed "$SERVICE_NAME" >/dev/null 2>&1 || true
printf 'Removing crawler files and local agent data...\n'
rm -rf -- "$INSTALL_DIR" "$STATE_DIR"
printf 'Removing the crawler service account...\n'
remove_service_account
printf 'Basango crawler uninstalled.\n'