Source mirror · commit 369512f · 2026-10-26 · MIT · canonical repo: gitlab.com/jiapunk/upgrade-airlock
git clone https://upgrade-airlock.pages.dev/source/upgrade-airlock.git
upgrade-airlock / scripts / sepolia / systemd / uninstall.sh
scripts/sepolia/systemd/uninstall.sh38 lines · 2138 bytes
1#!/usr/bin/env bash
2# Stop, disable and remove the Upgrade Airlock user units installed by install.sh (current user only, no sudo).
3#
4# scripts/sepolia/systemd/uninstall.sh # keeps the env file and the state dir (logs)
5# scripts/sepolia/systemd/uninstall.sh --purge # also removes the env file; the state dir is only printed
6# DRY_RUN=1 scripts/sepolia/systemd/uninstall.sh # print what it would do
7set -euo pipefail
8UNITS=(airlock-listener.service airlock-sweep.timer airlock-sweep.service)
9UNIT_DIR=${SYSTEMD_USER_DIR:-${XDG_CONFIG_HOME:-$HOME/.config}/systemd/user}
10ENV_FILE=${ENV_FILE:-${XDG_CONFIG_HOME:-$HOME/.config}/upgrade-airlock/airlock.env}
11PURGE=
12for a in "$@"; do
13 case "$a" in
14 --purge) PURGE=1 ;;
15 -h | --help) sed -n '2,6p' "$0"; exit 0 ;;
16 *) echo "error: unknown option $a" >&2; exit 2 ;;
17 esac
18done
19run() { if [ -n "${DRY_RUN:-}" ]; then echo "+ $*"; else "$@"; fi; }
20[ "$(id -u)" != 0 ] || { echo "error: run this as the user that installed the units, not as root" >&2; exit 1; }
21
22STATE=
23if [ -f "$ENV_FILE" ]; then STATE=$(sed -n 's/^AIRLOCK_STATE=//p' "$ENV_FILE" | tail -n1); fi
24if command -v systemctl >/dev/null && { [ -n "${DRY_RUN:-}" ] || systemctl --user show-environment >/dev/null 2>&1; }; then
25 run systemctl --user disable --now airlock-listener.service airlock-sweep.timer || true
26 run systemctl --user stop airlock-sweep.service || true
27fi
28for u in "${UNITS[@]}"; do
29 if [ -f "$UNIT_DIR/$u" ]; then run rm -f "$UNIT_DIR/$u"; [ -n "${DRY_RUN:-}" ] || echo "removed $UNIT_DIR/$u"; fi
30done
31if command -v systemctl >/dev/null && { [ -n "${DRY_RUN:-}" ] || systemctl --user show-environment >/dev/null 2>&1; }; then
32 run systemctl --user daemon-reload
33 run systemctl --user reset-failed airlock-listener.service airlock-sweep.service 2>/dev/null || true
34fi
35if [ -n "$PURGE" ] && [ -f "$ENV_FILE" ]; then run rm -f "$ENV_FILE"; [ -n "${DRY_RUN:-}" ] || echo "removed $ENV_FILE"; fi
36[ -z "$PURGE" ] && [ -f "$ENV_FILE" ] && echo "kept $ENV_FILE (--purge removes it)"
37[ -n "$STATE" ] && echo "kept the state dir $STATE (logs; delete it yourself when no longer needed)"
38exit 0