-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuninstall.sh
More file actions
172 lines (154 loc) · 6.19 KB
/
Copy pathuninstall.sh
File metadata and controls
172 lines (154 loc) · 6.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/usr/bin/env bash
# FamilyGram — remove the Docker Compose stack installed by deploy/install.sh
#
# Usage (on the install host):
# sudo bash /opt/familygram/deploy/uninstall.sh
# sudo bash /opt/familygram/deploy/uninstall.sh --yes
# sudo bash /opt/familygram/deploy/uninstall.sh --keep-data --keep-repo
# sudo bash /opt/familygram/deploy/uninstall.sh --install-dir /opt/familygram --remove-images --yes
#
# From a fresh download (main branch):
# curl -fsSL https://raw.githubusercontent.com/CyberoniOntoni/familygram/main/deploy/uninstall.sh -o uninstall.sh
# sudo bash uninstall.sh --install-dir /opt/familygram --yes
#
# Options:
# --install-dir PATH default /opt/familygram
# --yes, -y skip confirmation prompt
# --keep-data keep docker/compose/data, .env, and .env backups
# --keep-repo keep the git clone; only stop containers (and remove data unless --keep-data)
# --remove-images remove local web image + FamilyGram GHCR server images on this host
# --help show help
set -euo pipefail
INSTALL_DIR="${INSTALL_DIR:-/opt/familygram}"
COMPOSE_DIR="${INSTALL_DIR}/docker/compose"
COMPOSE_FILE="${COMPOSE_DIR}/docker-compose.yml"
ASSUME_YES=false
KEEP_DATA=false
KEEP_REPO=false
REMOVE_IMAGES=false
usage() {
sed -n '2,22p' "$0" | sed 's/^# \{0,1\}//'
exit 0
}
while [[ $# -gt 0 ]]; do
case "$1" in
--install-dir) INSTALL_DIR="${2:-}"; COMPOSE_DIR="${INSTALL_DIR}/docker/compose"; COMPOSE_FILE="${COMPOSE_DIR}/docker-compose.yml"; shift 2 ;;
--yes|-y) ASSUME_YES=true; shift ;;
--keep-data) KEEP_DATA=true; shift ;;
--keep-repo) KEEP_REPO=true; shift ;;
--remove-images) REMOVE_IMAGES=true; shift ;;
--help|-h) usage ;;
*) echo "Unknown option: $1" >&2; usage ;;
esac
done
if [[ "$(id -u)" -ne 0 ]]; then
echo "Run as root (sudo)." >&2
exit 1
fi
if [[ ! -f "${COMPOSE_FILE}" ]]; then
echo "No FamilyGram install found at ${INSTALL_DIR} (missing ${COMPOSE_FILE})." >&2
exit 1
fi
# Optional metadata written by install.sh (ENABLE_WEB / ENABLE_BOT, etc.)
load_install_config() {
local summary="${INSTALL_DIR}/deploy/last-install-config.txt"
if [[ -f "${summary}" ]]; then
# shellcheck disable=SC1090
# shellcheck source=/dev/null
source "${summary}" 2>/dev/null || true
fi
# Defaults match install.sh (web on; bot only if configured)
ENABLE_WEB="${ENABLE_WEB:-yes}"
ENABLE_BOT="${ENABLE_BOT:-no}"
}
# Always include web+bot+rtmp profiles so profiled services never remain running
# even if last-install-config is missing or stale.
compose_down() {
cd "${COMPOSE_DIR}" || {
echo "ERROR: cannot cd to ${COMPOSE_DIR}" >&2
return 1
}
if command -v docker >/dev/null 2>&1 && docker compose version >/dev/null 2>&1; then
echo " docker compose down (profiles: web,bot,rtmp + default)"
COMPOSE_PROFILES=web,bot,rtmp docker compose down --remove-orphans 2>/dev/null || true
# Second pass without profiles (core services only) if the first path failed partially
docker compose down --remove-orphans 2>/dev/null || true
fi
}
remove_stack_images() {
if ! command -v docker >/dev/null 2>&1; then
return 0
fi
echo "==> Removing FamilyGram Docker images on this host..."
docker image rm -f familygram/familygram-web:local 2>/dev/null || true
# Images published by FamilyGram-Server CI (layer 228 / :latest and any local tags)
local img
while IFS= read -r img; do
[[ -n "${img}" ]] || continue
echo " rm ${img}"
docker image rm -f "${img}" 2>/dev/null || true
done < <(docker images --format '{{.Repository}}:{{.Tag}}' 2>/dev/null \
| grep -E '^ghcr\.io/cyberoniontoni/familygram-server/' || true)
# Legacy tags (if any remain from older deploys)
while IFS= read -r img; do
[[ -n "${img}" ]] || continue
echo " rm ${img}"
docker image rm -f "${img}" 2>/dev/null || true
done < <(docker images --format '{{.Repository}}:{{.Tag}}' 2>/dev/null \
| grep -E 'familygram-server.*(layer228|:latest)' || true)
}
load_install_config
echo "FamilyGram uninstall"
echo " Install dir: ${INSTALL_DIR}"
echo " Compose: ${COMPOSE_DIR}"
echo " Install meta: ENABLE_WEB=${ENABLE_WEB} ENABLE_BOT=${ENABLE_BOT}"
echo " Keep data: ${KEEP_DATA}"
echo " Keep repo: ${KEEP_REPO}"
echo " Remove imgs: ${REMOVE_IMAGES}"
echo ""
if [[ "${ASSUME_YES}" != "true" ]]; then
if [[ -t 0 ]] || [[ -r /dev/tty ]]; then
read -r -p "This stops all FamilyGram containers and removes stack data. Continue? [y/N] " reply </dev/tty 2>/dev/null \
|| read -r -p "This stops all FamilyGram containers and removes stack data. Continue? [y/N] " reply
else
echo "Non-interactive stdin: pass --yes to confirm." >&2
exit 1
fi
[[ "${reply}" =~ ^[Yy]$ ]] || { echo "Aborted."; exit 0; }
fi
if command -v docker >/dev/null 2>&1 && docker compose version >/dev/null 2>&1; then
echo "==> Stopping containers..."
compose_down
else
echo "==> Docker not available — skipping compose down"
fi
if [[ "${KEEP_DATA}" != "true" ]]; then
echo "==> Removing stack data and config..."
rm -rf "${COMPOSE_DIR}/data"
rm -f "${COMPOSE_DIR}/docker-compose.override.yml"
rm -f "${COMPOSE_DIR}/.env"
# Installer / verify-installer backups
rm -f "${COMPOSE_DIR}/.env.bak."* 2>/dev/null || true
rm -f "${COMPOSE_DIR}/.env.verify.bak" 2>/dev/null || true
rm -f "${INSTALL_DIR}/deploy/last-install-config.txt" 2>/dev/null || true
fi
if [[ "${REMOVE_IMAGES}" == "true" ]]; then
remove_stack_images
fi
if [[ "${KEEP_REPO}" != "true" ]]; then
echo "==> Removing install directory ${INSTALL_DIR}..."
# If we are running from inside INSTALL_DIR, leave the script's parent deletion to the end
if [[ "$(pwd -P 2>/dev/null || pwd)" == "${INSTALL_DIR}"* ]]; then
cd /
fi
rm -rf "${INSTALL_DIR}"
else
echo "==> Kept ${INSTALL_DIR} (git clone and deploy scripts remain)."
fi
echo ""
echo "Done. FamilyGram stack removed."
echo "Manual cleanup (if used):"
echo " • Nginx Proxy Manager proxy host for your web domain (and passkey domain → :30443)"
echo " • UFW rules for MTProto / TURN / web ports opened by the installer"
echo " • DNS records and router port forwards (20443–20644, 5348, TURN relay UDP)"
echo " • Docker itself and Node/nvm are left installed for other workloads"