-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuninstall.sh
More file actions
executable file
·181 lines (162 loc) · 9.01 KB
/
Copy pathuninstall.sh
File metadata and controls
executable file
·181 lines (162 loc) · 9.01 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
173
174
175
176
177
178
179
180
181
#!/bin/bash
# ═══════════════════════════════════════════════════════════════
# SECUR-EU Platform — Uninstall Script
# ═══════════════════════════════════════════════════════════════
#
# Usage:
# sudo ./uninstall.sh
#
# By default removes: systemd units, all Docker containers/volumes,
# platform processes, sudoers entry, and the platform directory.
#
# Optional flags:
# --remove-docker Also remove Docker Engine and Docker Compose
# --remove-java Also remove Temurin JDK
# --keep-dir Keep the platform directory (files on disk)
# ═══════════════════════════════════════════════════════════════
set -euo pipefail
INSTALL_DIR="$(cd "$(dirname "$0")" && pwd)"
BACKEND_DIR="$INSTALL_DIR/backend"
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
info() { echo -e "${GREEN}[INFO]${NC} $1"; }
warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
step() { echo -e "\n${GREEN}───${NC} $1"; }
REMOVE_DOCKER=0
REMOVE_JAVA=0
REMOVE_IMAGES=0
KEEP_DIR=0
for arg in "$@"; do
case "$arg" in
--remove-docker) REMOVE_DOCKER=1 ;;
--remove-java) REMOVE_JAVA=1 ;;
--remove-images) REMOVE_IMAGES=1 ;;
--keep-dir) KEEP_DIR=1 ;;
*) echo "Unknown option: $arg"; exit 1 ;;
esac
done
if [ "$EUID" -ne 0 ]; then
echo -e "${RED}[ERROR]${NC} Please run as root: sudo ./uninstall.sh"
exit 1
fi
REAL_USER="${SUDO_USER:-$USER}"
echo ""
echo "═══════════════════════════════════════════════════════════"
echo " SECUR-EU Platform Uninstaller"
echo "═══════════════════════════════════════════════════════════"
echo " Install dir : $INSTALL_DIR"
echo " User : $REAL_USER"
echo " Remove images: $([ $REMOVE_IMAGES -eq 1 ] && echo yes || echo no)"
echo " Remove Docker: $([ $REMOVE_DOCKER -eq 1 ] && echo yes || echo no)"
echo " Remove Java : $([ $REMOVE_JAVA -eq 1 ] && echo yes || echo no)"
echo " Keep dir : $([ $KEEP_DIR -eq 1 ] && echo yes || echo no)"
echo "═══════════════════════════════════════════════════════════"
echo ""
read -r -p "This will permanently destroy all platform data. Continue? [y/N] " confirm
[[ "$confirm" =~ ^[Yy]$ ]] || { echo "Aborted."; exit 0; }
# ─────────────────────────────────────────────
# 1. Systemd services and timer
# ─────────────────────────────────────────────
step "Stopping and removing systemd units..."
for unit in secureu-backend secureu-frontend secureu-cleanup.timer secureu-cleanup; do
systemctl stop "$unit" 2>/dev/null && info "Stopped $unit" || true
systemctl disable "$unit" 2>/dev/null || true
done
rm -f /etc/systemd/system/secureu-backend.service \
/etc/systemd/system/secureu-frontend.service \
/etc/systemd/system/secureu-cleanup.service \
/etc/systemd/system/secureu-cleanup.timer
systemctl daemon-reload
info "Systemd units removed"
# ─────────────────────────────────────────────
# 2. Running processes
# ─────────────────────────────────────────────
step "Killing platform processes..."
pkill -f "data-traffic-monitoring.*\.jar" 2>/dev/null && info "DTM stopped" || true
pkill -f "anomaly-detection.*\.jar" 2>/dev/null && info "AD stopped" || true
pkill -f "$BACKEND_DIR/pentest/bin/server" 2>/dev/null && info "Pentest server stopped" || true
# ─────────────────────────────────────────────
# 3. Docker compose stacks (containers + volumes)
# ─────────────────────────────────────────────
step "Tearing down Docker compose stacks..."
for compose_file in \
"$BACKEND_DIR/pentest/docker_compose.yaml" \
"$BACKEND_DIR/sslchecker/docker-compose.yml" \
"$BACKEND_DIR/vsp/docker-compose.yml" \
"$BACKEND_DIR/darkweb/docker-compose.yml" \
"$BACKEND_DIR/redflags/docker-compose.yml" \
"$BACKEND_DIR/seuxdr/docker-compose.yml" \
"$BACKEND_DIR/sqs/docker-compose.yml" \
"$BACKEND_DIR/dtmad/monitoring/docker-compose.yml"
do
if [ -f "$compose_file" ]; then
docker compose -f "$compose_file" down -v --remove-orphans 2>/dev/null \
&& info "Down: $(basename "$(dirname "$compose_file")")" || true
fi
done
# ─────────────────────────────────────────────
# 4. Infrastructure containers (started via docker run)
# ─────────────────────────────────────────────
step "Removing infrastructure containers..."
for container in kafka-dtm zookeeper-dtm sphinx-postgres; do
docker stop "$container" 2>/dev/null || true
docker rm -v "$container" 2>/dev/null && info "Removed $container" || true
done
# ─────────────────────────────────────────────
# 5. Docker images (opt-in)
# ─────────────────────────────────────────────
if [ "$REMOVE_IMAGES" -eq 1 ]; then
step "Pruning Docker images..."
docker image prune -a -f 2>/dev/null && info "Docker images pruned" || true
fi
# ─────────────────────────────────────────────
# 6. Sudoers entry
# ─────────────────────────────────────────────
step "Removing sudoers entry..."
if [ -f "/etc/sudoers.d/$REAL_USER" ]; then
rm -f "/etc/sudoers.d/$REAL_USER"
info "Removed /etc/sudoers.d/$REAL_USER"
else
warn "No sudoers entry found for $REAL_USER — skipping"
fi
# ─────────────────────────────────────────────
# 7. Platform directory
# ─────────────────────────────────────────────
if [ "$KEEP_DIR" -eq 0 ]; then
step "Removing platform directory..."
# Run from parent so we're not deleting our cwd
PARENT="$(dirname "$INSTALL_DIR")"
BASENAME="$(basename "$INSTALL_DIR")"
cd "$PARENT"
rm -rf "$BASENAME"
info "Removed $INSTALL_DIR"
else
info "Keeping platform directory (--keep-dir)"
fi
# ─────────────────────────────────────────────
# 8. Optional: remove Docker Engine
# ─────────────────────────────────────────────
if [ "$REMOVE_DOCKER" -eq 1 ]; then
step "Removing Docker Engine..."
apt-get remove -y docker-ce docker-ce-cli containerd.io docker-compose-plugin 2>/dev/null || true
rm -f /etc/apt/sources.list.d/docker.list /etc/apt/keyrings/docker.asc
apt-get autoremove -y 2>/dev/null || true
info "Docker removed"
fi
# ─────────────────────────────────────────────
# 9. Optional: remove Temurin JDK
# ─────────────────────────────────────────────
if [ "$REMOVE_JAVA" -eq 1 ]; then
step "Removing Temurin JDK..."
apt-get remove -y "temurin-*-jdk" 2>/dev/null || true
rm -f /etc/apt/sources.list.d/adoptium.list /etc/apt/keyrings/adoptium.gpg
apt-get autoremove -y 2>/dev/null || true
info "Java removed"
fi
echo ""
echo "═══════════════════════════════════════════════════════════"
echo -e " ${GREEN}SECUR-EU Platform uninstalled successfully${NC}"
echo "═══════════════════════════════════════════════════════════"
echo ""