From 0a54a3229ae4640e0141c3a160012fe6513ab85b Mon Sep 17 00:00:00 2001 From: cyph3rasi Date: Sat, 7 Mar 2026 17:16:25 -0800 Subject: [PATCH] Add Docker uninstall script --- README.md | 5 ++ docker/README.md | 10 ++++ docker/uninstall.sh | 113 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 128 insertions(+) create mode 100644 docker/uninstall.sh diff --git a/README.md b/README.md index 5eb59d7..eda3ae2 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,11 @@ Database migrations run automatically on startup and during updates. docker compose pull && docker compose up -d ``` +**Full uninstall:** +```bash +curl -fsSL https://synapsis.social/uninstall.sh | bash +``` + For detailed Docker setup, see [docker/README.md](docker/README.md). --- diff --git a/docker/README.md b/docker/README.md index dfc6b20..8b1e8cc 100644 --- a/docker/README.md +++ b/docker/README.md @@ -56,6 +56,16 @@ cd /opt/synapsis docker compose pull && docker compose up -d ``` +## ๐Ÿ—‘๏ธ Full Uninstall + +To remove Synapsis completely from a host and start over: + +```bash +curl -fsSL https://synapsis.social/uninstall.sh | bash +``` + +The uninstaller destroys the Synapsis containers, volumes, network, cached Synapsis images, and `/opt/synapsis`. It requires typing `DELETE` unless you set `FORCE=1`. + --- ## ๐Ÿ› ๏ธ Common Commands diff --git a/docker/uninstall.sh b/docker/uninstall.sh new file mode 100644 index 0000000..94da94b --- /dev/null +++ b/docker/uninstall.sh @@ -0,0 +1,113 @@ +#!/bin/sh + +set -eu + +INSTALL_DIR="${1:-${INSTALL_DIR:-/opt/synapsis}}" +PROJECT_NAME="${PROJECT_NAME:-synapsis}" +IMAGE_REPO="${IMAGE_REPO:-ghcr.io/gnosyslabs/synapsis}" + +require_command() { + if ! command -v "$1" >/dev/null 2>&1; then + echo "โŒ Required command not found: $1" >&2 + exit 1 + fi +} + +confirm_uninstall() { + if [ "${FORCE:-0}" = "1" ] || [ "${YES:-0}" = "1" ]; then + return + fi + + echo "========================================" + echo " Synapsis Docker Uninstaller" + echo "========================================" + echo " Install dir: ${INSTALL_DIR}" + echo " Project name: ${PROJECT_NAME}" + echo "" + echo "This will permanently remove:" + echo " - Synapsis containers" + echo " - Synapsis Docker volumes and network" + echo " - Synapsis images pulled from GHCR/local cache" + echo " - ${INSTALL_DIR}" + echo "" + printf "Type DELETE to continue: " + read -r confirmation + + if [ "$confirmation" != "DELETE" ]; then + echo "Aborted." + exit 1 + fi +} + +cleanup_with_compose() { + if [ -f "${INSTALL_DIR}/docker-compose.yml" ]; then + echo "๐Ÿงน Stopping Synapsis compose stack" + if [ -f "${INSTALL_DIR}/.env" ]; then + docker compose --env-file "${INSTALL_DIR}/.env" -f "${INSTALL_DIR}/docker-compose.yml" down --volumes --remove-orphans || true + else + docker compose -f "${INSTALL_DIR}/docker-compose.yml" down --volumes --remove-orphans || true + fi + fi +} + +cleanup_named_resources() { + for container in synapsis-caddy synapsis-app synapsis-db; do + if docker ps -aq --filter "name=^${container}$" | grep -q .; then + echo "๐Ÿ—‘๏ธ Removing container ${container}" + docker rm -f "${container}" >/dev/null 2>&1 || true + fi + done + + for volume in \ + synapsis_postgres_data \ + synapsis_uploads_data \ + synapsis_port_data \ + synapsis_caddy_data \ + synapsis_caddy_config + do + if docker volume inspect "${volume}" >/dev/null 2>&1; then + echo "๐Ÿ—‘๏ธ Removing volume ${volume}" + docker volume rm -f "${volume}" >/dev/null 2>&1 || true + fi + done + + if docker network inspect synapsis_synapsis-network >/dev/null 2>&1; then + echo "๐Ÿ—‘๏ธ Removing network synapsis_synapsis-network" + docker network rm synapsis_synapsis-network >/dev/null 2>&1 || true + fi +} + +cleanup_images() { + docker images --format '{{.Repository}}:{{.Tag}}' | while IFS= read -r image; do + case "$image" in + "${IMAGE_REPO}:"*|synapsis:*) + echo "๐Ÿ—‘๏ธ Removing image ${image}" + docker rmi -f "$image" >/dev/null 2>&1 || true + ;; + esac + done +} + +remove_install_dir() { + if [ -d "${INSTALL_DIR}" ]; then + echo "๐Ÿ—‘๏ธ Removing ${INSTALL_DIR}" + rm -rf "${INSTALL_DIR}" + fi +} + +require_command docker +require_command rm + +if [ "$(id -u)" -ne 0 ]; then + echo "โŒ Run this uninstaller as root or with sudo." >&2 + exit 1 +fi + +confirm_uninstall +cleanup_with_compose +cleanup_named_resources +cleanup_images +remove_install_dir + +echo "" +echo "โœ… Synapsis has been removed from this host."