|
Bogdan Timofte
authored
3 months ago
|
1
|
#!/bin/bash
|
|
|
2
|
|
|
|
3
|
# autoSMART Uninstaller
|
|
|
4
|
# Version: 1.0
|
|
|
5
|
# Description: Complete removal of autoSMART system to prevent orphaned files
|
|
|
6
|
|
|
|
7
|
set -e
|
|
|
8
|
|
|
|
9
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
10
|
INSTALL_DIR="/opt/autoSMART"
|
|
|
11
|
CONFIG_DIR="/etc/autosmart"
|
|
|
12
|
PVE_CONFIG_DIR="/etc/pve/autoSMART"
|
|
|
13
|
SERVICE_NAME="autosmart"
|
|
|
14
|
LOG_DIR="/var/log/autosmart"
|
|
|
15
|
SYSTEMD_SERVICE="/etc/systemd/system/${SERVICE_NAME}.service"
|
|
|
16
|
|
|
|
17
|
# Colors for output
|
|
|
18
|
RED='\033[0;31m'
|
|
|
19
|
GREEN='\033[0;32m'
|
|
|
20
|
YELLOW='\033[1;33m'
|
|
|
21
|
BLUE='\033[0;34m'
|
|
|
22
|
NC='\033[0m' # No Color
|
|
|
23
|
|
|
|
24
|
log_info() {
|
|
|
25
|
echo -e "${BLUE}[INFO]${NC} $1"
|
|
|
26
|
}
|
|
|
27
|
|
|
|
28
|
log_success() {
|
|
|
29
|
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
|
|
30
|
}
|
|
|
31
|
|
|
|
32
|
log_warning() {
|
|
|
33
|
echo -e "${YELLOW}[WARNING]${NC} $1"
|
|
|
34
|
}
|
|
|
35
|
|
|
|
36
|
log_error() {
|
|
|
37
|
echo -e "${RED}[ERROR]${NC} $1"
|
|
|
38
|
}
|
|
|
39
|
|
|
|
40
|
log_info "🗑️ autoSMART Uninstaller v1.0"
|
|
|
41
|
log_info "==============================="
|
|
|
42
|
|
|
|
43
|
# Check if running as root
|
|
|
44
|
if [[ $EUID -ne 0 ]]; then
|
|
|
45
|
log_error "This script must be run as root (use sudo)"
|
|
|
46
|
exit 1
|
|
|
47
|
fi
|
|
|
48
|
|
|
|
49
|
# Stop and disable systemd service
|
|
|
50
|
if systemctl is-active --quiet "$SERVICE_NAME" 2>/dev/null; then
|
|
|
51
|
log_info "Stopping autoSMART service..."
|
|
|
52
|
systemctl stop "$SERVICE_NAME"
|
|
|
53
|
log_success "Service stopped"
|
|
|
54
|
else
|
|
|
55
|
log_info "Service is not running"
|
|
|
56
|
fi
|
|
|
57
|
|
|
|
58
|
if systemctl is-enabled --quiet "$SERVICE_NAME" 2>/dev/null; then
|
|
|
59
|
log_info "Disabling autoSMART service..."
|
|
|
60
|
systemctl disable "$SERVICE_NAME"
|
|
|
61
|
log_success "Service disabled"
|
|
|
62
|
fi
|
|
|
63
|
|
|
|
64
|
# Remove systemd service file
|
|
|
65
|
if [[ -f "$SYSTEMD_SERVICE" ]]; then
|
|
|
66
|
log_info "Removing systemd service file..."
|
|
|
67
|
rm -f "$SYSTEMD_SERVICE"
|
|
|
68
|
systemctl daemon-reload
|
|
|
69
|
log_success "Service file removed"
|
|
|
70
|
fi
|
|
|
71
|
|
|
|
72
|
# Remove installation directory
|
|
|
73
|
if [[ -d "$INSTALL_DIR" ]]; then
|
|
|
74
|
log_info "Removing installation directory: $INSTALL_DIR"
|
|
|
75
|
rm -rf "$INSTALL_DIR"
|
|
|
76
|
log_success "Installation directory removed"
|
|
|
77
|
else
|
|
|
78
|
log_info "Installation directory does not exist"
|
|
|
79
|
fi
|
|
|
80
|
|
|
|
81
|
# Remove configuration directory
|
|
|
82
|
if [[ -d "$CONFIG_DIR" ]]; then
|
|
|
83
|
log_info "Removing configuration directory: $CONFIG_DIR"
|
|
|
84
|
rm -rf "$CONFIG_DIR"
|
|
|
85
|
log_success "Configuration directory removed"
|
|
|
86
|
else
|
|
|
87
|
log_info "Configuration directory does not exist"
|
|
|
88
|
fi
|
|
|
89
|
|
|
|
90
|
# Remove PVE configuration directory (if exists)
|
|
|
91
|
if [[ -d "$PVE_CONFIG_DIR" ]]; then
|
|
|
92
|
log_info "Removing PVE configuration directory: $PVE_CONFIG_DIR"
|
|
|
93
|
rm -rf "$PVE_CONFIG_DIR"
|
|
|
94
|
log_success "PVE configuration directory removed"
|
|
|
95
|
fi
|
|
|
96
|
|
|
|
97
|
# Remove log directory
|
|
|
98
|
if [[ -d "$LOG_DIR" ]]; then
|
|
|
99
|
log_info "Removing log directory: $LOG_DIR"
|
|
|
100
|
rm -rf "$LOG_DIR"
|
|
|
101
|
log_success "Log directory removed"
|
|
|
102
|
fi
|
|
|
103
|
|
|
|
104
|
# Remove cron jobs (if any)
|
|
|
105
|
if crontab -l 2>/dev/null | grep -q "autosmart"; then
|
|
|
106
|
log_info "Removing autoSMART cron jobs..."
|
|
|
107
|
(crontab -l 2>/dev/null | grep -v "autosmart") | crontab -
|
|
|
108
|
log_success "Cron jobs removed"
|
|
|
109
|
fi
|
|
|
110
|
|
|
|
111
|
# Remove temporary files
|
|
|
112
|
TEMP_FILES=(
|
|
|
113
|
"/tmp/autosmart*"
|
|
|
114
|
"/tmp/smart-*"
|
|
|
115
|
"/var/tmp/autosmart*"
|
|
|
116
|
)
|
|
|
117
|
|
|
|
118
|
for pattern in "${TEMP_FILES[@]}"; do
|
|
|
119
|
if ls $pattern 1> /dev/null 2>&1; then
|
|
|
120
|
log_info "Removing temporary files: $pattern"
|
|
|
121
|
rm -rf $pattern
|
|
|
122
|
fi
|
|
|
123
|
done
|
|
|
124
|
|
|
|
125
|
# Remove user and group (if created specifically for autoSMART)
|
|
|
126
|
if id "autosmart" &>/dev/null; then
|
|
|
127
|
log_warning "Found autosmart user - leaving intact (may be used by database)"
|
|
|
128
|
log_info "To remove user manually: userdel autosmart"
|
|
|
129
|
fi
|
|
|
130
|
|
|
|
131
|
# Clean up any remaining processes
|
|
|
132
|
PROCESSES=$(pgrep -f "autosmart|smart-collector" || true)
|
|
|
133
|
if [[ -n "$PROCESSES" ]]; then
|
|
|
134
|
log_warning "Found running autoSMART processes: $PROCESSES"
|
|
|
135
|
log_info "Terminating processes..."
|
|
|
136
|
pkill -f "autosmart|smart-collector" || true
|
|
|
137
|
sleep 2
|
|
|
138
|
pkill -9 -f "autosmart|smart-collector" || true
|
|
|
139
|
log_success "Processes terminated"
|
|
|
140
|
fi
|
|
|
141
|
|
|
|
142
|
# Remove from PATH modifications (if any)
|
|
|
143
|
PROFILE_FILES=(
|
|
|
144
|
"/etc/profile.d/autosmart.sh"
|
|
|
145
|
"/etc/bash.bashrc.d/autosmart.sh"
|
|
|
146
|
)
|
|
|
147
|
|
|
|
148
|
for file in "${PROFILE_FILES[@]}"; do
|
|
|
149
|
if [[ -f "$file" ]]; then
|
|
|
150
|
log_info "Removing PATH modification: $file"
|
|
|
151
|
rm -f "$file"
|
|
|
152
|
fi
|
|
|
153
|
done
|
|
|
154
|
|
|
|
155
|
# Clean package manager cache related to autoSMART dependencies
|
|
|
156
|
log_info "Cleaning package cache..."
|
|
|
157
|
if command -v apt-get &> /dev/null; then
|
|
|
158
|
apt-get clean >/dev/null 2>&1 || true
|
|
|
159
|
elif command -v yum &> /dev/null; then
|
|
|
160
|
yum clean all >/dev/null 2>&1 || true
|
|
|
161
|
fi
|
|
|
162
|
|
|
|
163
|
# Final verification
|
|
|
164
|
REMAINING_FILES=$(find /etc /opt /var -name "*autosmart*" -o -name "*autoSMART*" 2>/dev/null | head -10)
|
|
|
165
|
if [[ -n "$REMAINING_FILES" ]]; then
|
|
|
166
|
log_warning "Some autoSMART files may still exist:"
|
|
|
167
|
echo "$REMAINING_FILES"
|
|
|
168
|
log_info "These may be database files or manually created configurations"
|
|
|
169
|
fi
|
|
|
170
|
|
|
|
171
|
log_success "✅ autoSMART uninstallation complete!"
|
|
|
172
|
log_info ""
|
|
|
173
|
log_info "📋 Summary of removed components:"
|
|
|
174
|
log_info " • Systemd service: $SERVICE_NAME"
|
|
|
175
|
log_info " • Installation directory: $INSTALL_DIR"
|
|
|
176
|
log_info " • Configuration directory: $CONFIG_DIR"
|
|
|
177
|
log_info " • Log directory: $LOG_DIR"
|
|
|
178
|
log_info " • Temporary files and processes"
|
|
|
179
|
log_info ""
|
|
|
180
|
log_info "💡 Notes:"
|
|
|
181
|
log_info " • Database data is preserved (not removed)"
|
|
|
182
|
log_info " • System packages (Perl, PostgreSQL client) are preserved"
|
|
|
183
|
log_info " • User 'autosmart' is preserved if it exists"
|
|
|
184
|
log_info ""
|
|
|
185
|
log_info "🔄 System is now clean and ready for fresh installation"
|
|
|
186
|
|
|
|
187
|
exit 0
|