|
Bogdan Timofte
authored
3 months ago
|
1
|
#!/bin/bash
|
|
|
2
|
|
|
|
3
|
# AutoNAS Uninstall Script
|
|
|
4
|
# This script is installed on each cluster node for version-specific removal
|
|
|
5
|
# Executed by deploy.sh or can be run directly on node: /usr/local/lib/autonas/autonas-uninstall.sh
|
|
|
6
|
|
|
|
7
|
# Global configuration
|
|
|
8
|
LOG_TAG="autonas-uninstall"
|
|
|
9
|
|
|
|
10
|
set -e # Exit on any error
|
|
|
11
|
|
|
|
12
|
# Check for force flag for silent cleanup
|
|
|
13
|
FORCE_MODE=false
|
|
|
14
|
if [ "$1" = "--force" ]; then
|
|
|
15
|
FORCE_MODE=true
|
|
|
16
|
fi
|
|
|
17
|
|
|
|
18
|
# Helper function for conditional logging
|
|
|
19
|
log_message() {
|
|
|
20
|
if [ "$FORCE_MODE" = false ]; then
|
|
|
21
|
echo "$1"
|
|
|
22
|
fi
|
|
|
23
|
}
|
|
|
24
|
|
|
|
25
|
CONFIG_DIR="/etc/pve/autonas"
|
|
|
26
|
SCRIPT_NAME="autonas-disk-handler.sh"
|
|
|
27
|
WRAPPER_NAME="autonas-udev-wrapper.sh"
|
|
|
28
|
BOOT_SCAN_SCRIPT="autonas-boot-scan.sh"
|
|
|
29
|
CAMERA_IMPORT_SCRIPT="autonas-media-importer.sh"
|
|
|
30
|
INTERFACE_HANDLER_SCRIPT="autonas-network-handler.sh"
|
|
|
31
|
UNIFIED_SCRIPT="autonas.sh"
|
|
|
32
|
UDEV_RULES="99-autonas-disk.rules"
|
|
|
33
|
SYSTEMD_SERVICE="autonas-attach@.service"
|
|
|
34
|
MAIN_SERVICE="autonas.service"
|
|
|
35
|
BOOT_SCAN_SERVICE="autonas-boot-scan.service"
|
|
|
36
|
|
|
|
37
|
if [ "$FORCE_MODE" = false ]; then
|
|
|
38
|
echo "=== AutoNAS Uninstall Script ==="
|
|
|
39
|
echo ""
|
|
|
40
|
fi
|
|
|
41
|
|
|
|
42
|
# Check if running as root
|
|
|
43
|
if [ "$EUID" -ne 0 ]; then
|
|
|
44
|
if [ "$FORCE_MODE" = false ]; then
|
|
|
45
|
echo "❌ This script must be run as root (use sudo)"
|
|
|
46
|
fi
|
|
|
47
|
exit 1
|
|
|
48
|
fi
|
|
|
49
|
|
|
|
50
|
log_message "🗑️ Uninstalling AutoNAS..."
|
|
|
51
|
log_message ""
|
|
|
52
|
|
|
|
53
|
# Remove scripts
|
|
|
54
|
log_message "Removing AutoNAS scripts..."
|
|
|
55
|
if [ -f "/usr/local/bin/$SCRIPT_NAME" ]; then
|
|
|
56
|
rm "/usr/local/bin/$SCRIPT_NAME"
|
|
|
57
|
log_message "✓ Manager script removed"
|
|
|
58
|
fi
|
|
|
59
|
|
|
|
60
|
if [ -f "/usr/local/bin/$WRAPPER_NAME" ]; then
|
|
|
61
|
rm "/usr/local/bin/$WRAPPER_NAME"
|
|
|
62
|
log_message "✓ Wrapper script removed"
|
|
|
63
|
fi
|
|
|
64
|
|
|
|
65
|
if [ -f "/usr/local/bin/$BOOT_SCAN_SCRIPT" ]; then
|
|
|
66
|
rm "/usr/local/bin/$BOOT_SCAN_SCRIPT"
|
|
|
67
|
log_message "✓ Boot scan script removed"
|
|
|
68
|
fi
|
|
|
69
|
|
|
|
70
|
if [ -f "/usr/local/bin/$CAMERA_IMPORT_SCRIPT" ]; then
|
|
|
71
|
rm "/usr/local/bin/$CAMERA_IMPORT_SCRIPT"
|
|
|
72
|
log_message "✓ Camera import script removed"
|
|
|
73
|
fi
|
|
|
74
|
|
|
|
75
|
if [ -f "/usr/local/bin/$INTERFACE_HANDLER_SCRIPT" ]; then
|
|
|
76
|
rm "/usr/local/bin/$INTERFACE_HANDLER_SCRIPT"
|
|
|
77
|
log_message "✓ Interface handler script removed"
|
|
|
78
|
fi
|
|
|
79
|
|
|
|
80
|
if [ -f "/usr/local/bin/$UNIFIED_SCRIPT" ]; then
|
|
|
81
|
rm "/usr/local/bin/$UNIFIED_SCRIPT"
|
|
|
82
|
log_message "✓ Unified AutoNAS script removed"
|
|
|
83
|
fi
|
|
|
84
|
|
|
|
85
|
# Remove symlink
|
|
|
86
|
if [ -L "/usr/local/bin/autonas" ]; then
|
|
|
87
|
rm "/usr/local/bin/autonas"
|
|
|
88
|
log_message "✓ AutoNAS symlink removed"
|
|
|
89
|
fi
|
|
|
90
|
|
|
|
91
|
# Remove internal scripts directory
|
|
|
92
|
if [ -d "/usr/local/lib/autonas" ]; then
|
|
|
93
|
rm -rf "/usr/local/lib/autonas"
|
|
|
94
|
log_message "✓ AutoNAS internal scripts directory removed"
|
|
|
95
|
fi
|
|
|
96
|
|
|
|
97
|
# Aggressive cleanup for orphaned files from previous versions
|
|
|
98
|
log_message "Cleaning up orphaned files from previous versions..."
|
|
|
99
|
for orphan_file in "autonas-interface-debug.sh" "autonas-test-interface-stability.sh"; do
|
|
|
100
|
if [ -f "/usr/local/bin/$orphan_file" ]; then
|
|
|
101
|
rm "/usr/local/bin/$orphan_file"
|
|
|
102
|
log_message "✓ Orphaned file removed: $orphan_file"
|
|
|
103
|
fi
|
|
|
104
|
done
|
|
|
105
|
|
|
|
106
|
# Remove udev rules
|
|
|
107
|
log_message "Removing udev rules..."
|
|
|
108
|
if [ -f "/etc/udev/rules.d/$UDEV_RULES" ]; then
|
|
|
109
|
rm "/etc/udev/rules.d/$UDEV_RULES"
|
|
|
110
|
udevadm control --reload-rules
|
|
|
111
|
log_message "✓ Udev rules removed"
|
|
|
112
|
fi
|
|
|
113
|
|
|
|
114
|
# Remove systemd service
|
|
|
115
|
log_message "Removing systemd service..."
|
|
|
116
|
if [ -f "/etc/systemd/system/$SYSTEMD_SERVICE" ]; then
|
|
|
117
|
systemctl stop autonas-attach@*.service 2>/dev/null || true
|
|
|
118
|
systemctl disable autonas-attach@*.service 2>/dev/null || true
|
|
|
119
|
rm "/etc/systemd/system/$SYSTEMD_SERVICE"
|
|
|
120
|
systemctl daemon-reload
|
|
|
121
|
log_message "✓ Systemd service removed"
|
|
|
122
|
fi
|
|
|
123
|
|
|
|
124
|
# Remove main service
|
|
|
125
|
log_message "Removing main AutoNAS service..."
|
|
|
126
|
if [ -f "/etc/systemd/system/$MAIN_SERVICE" ]; then
|
|
|
127
|
systemctl stop autonas.service 2>/dev/null || true
|
|
|
128
|
systemctl disable autonas.service 2>/dev/null || true
|
|
|
129
|
rm "/etc/systemd/system/$MAIN_SERVICE"
|
|
|
130
|
systemctl daemon-reload
|
|
|
131
|
log_message "✓ Main AutoNAS service removed"
|
|
|
132
|
fi
|
|
|
133
|
|
|
|
134
|
# Remove boot scan service
|
|
|
135
|
log_message "Removing boot scan service..."
|
|
|
136
|
if [ -f "/etc/systemd/system/$BOOT_SCAN_SERVICE" ]; then
|
|
|
137
|
systemctl stop autonas-boot-scan.service 2>/dev/null || true
|
|
|
138
|
systemctl disable autonas-boot-scan.service 2>/dev/null || true
|
|
|
139
|
rm "/etc/systemd/system/$BOOT_SCAN_SERVICE"
|
|
|
140
|
systemctl daemon-reload
|
|
|
141
|
log_message "✓ Boot scan service removed"
|
|
|
142
|
fi
|
|
|
143
|
|
|
|
144
|
# Handle configuration and data preservation
|
|
|
145
|
log_message ""
|
|
|
146
|
log_message "📁 Handling user data..."
|
|
|
147
|
|
|
|
148
|
# Check if configuration exists and has user data
|
|
|
149
|
if [ -f "$CONFIG_DIR/disks.conf" ]; then
|
|
|
150
|
if grep -v '^#' "$CONFIG_DIR/disks.conf" | grep -v '^$' | grep -q ':'; then
|
|
|
151
|
log_message "⚠️ User configurations detected in $CONFIG_DIR/disks.conf"
|
|
|
152
|
log_message " Configuration file preserved for manual cleanup"
|
|
|
153
|
log_message " Remove manually with: sudo rm -rf $CONFIG_DIR"
|
|
|
154
|
else
|
|
|
155
|
log_message "ℹ️ Configuration file contains only template - removing"
|
|
|
156
|
rm "$CONFIG_DIR/disks.conf"
|
|
|
157
|
rmdir "$CONFIG_DIR" 2>/dev/null || true
|
|
|
158
|
fi
|
|
|
159
|
else
|
|
|
160
|
log_message "ℹ️ No configuration file found"
|
|
|
161
|
rmdir "$CONFIG_DIR" 2>/dev/null || true
|
|
|
162
|
fi
|
|
|
163
|
|
|
|
164
|
# Check for mounted AutoNAS disks
|
|
|
165
|
log_message ""
|
|
|
166
|
log_message "💾 Checking for mounted AutoNAS disks..."
|
|
|
167
|
mounted_autonas=$(mount | grep "/mnt/autonas/" | wc -l)
|
|
|
168
|
if [ $mounted_autonas -gt 0 ]; then
|
|
|
169
|
log_message "⚠️ Found $mounted_autonas mounted AutoNAS disk(s):"
|
|
|
170
|
if [ "$FORCE_MODE" = false ]; then
|
|
|
171
|
mount | grep "/mnt/autonas/" | while read line; do
|
|
|
172
|
echo " $line"
|
|
|
173
|
done
|
|
|
174
|
fi
|
|
|
175
|
log_message ""
|
|
|
176
|
log_message " These disks are still mounted and in use."
|
|
|
177
|
log_message " Mount points preserved: /mnt/autonas/"
|
|
|
178
|
log_message " Unmount manually if needed: sudo umount /mnt/autonas/*"
|
|
|
179
|
else
|
|
|
180
|
log_message "ℹ️ No AutoNAS disks currently mounted"
|
|
|
181
|
if [ -d "/mnt/autonas" ]; then
|
|
|
182
|
# Only remove if empty
|
|
|
183
|
if [ -z "$(ls -A /mnt/autonas)" ]; then
|
|
|
184
|
rmdir "/mnt/autonas"
|
|
|
185
|
log_message "✓ Empty AutoNAS mount directory removed"
|
|
|
186
|
else
|
|
|
187
|
log_message "⚠️ AutoNAS mount directory contains files - preserved"
|
|
|
188
|
fi
|
|
|
189
|
fi
|
|
|
190
|
fi
|
|
|
191
|
|
|
|
192
|
# Check NFS exports
|
|
|
193
|
log_message ""
|
|
|
194
|
log_message "🌐 Checking NFS exports..."
|
|
|
195
|
if [ -f "/etc/exports" ] && grep -q "/mnt/autonas/" "/etc/exports" 2>/dev/null; then
|
|
|
196
|
log_message "⚠️ AutoNAS NFS exports found in /etc/exports"
|
|
|
197
|
log_message " Please manually remove AutoNAS entries from /etc/exports"
|
|
|
198
|
log_message " And reload NFS exports: sudo exportfs -ra"
|
|
|
199
|
else
|
|
|
200
|
log_message "ℹ️ No AutoNAS NFS exports found"
|
|
|
201
|
fi
|
|
|
202
|
|
|
|
203
|
log_message ""
|
|
|
204
|
log_message "🎉 AutoNAS core components removed successfully!"
|
|
|
205
|
|
|
|
206
|
if [ "$FORCE_MODE" = false ]; then
|
|
|
207
|
echo ""
|
|
|
208
|
echo "📋 Summary:"
|
|
|
209
|
echo "✓ Scripts removed from /usr/local/bin/"
|
|
|
210
|
echo "✓ Udev rules removed"
|
|
|
211
|
echo "✓ Systemd services removed"
|
|
|
212
|
echo ""
|
|
|
213
|
echo "⚠️ Preserved (manual cleanup required if desired):"
|
|
|
214
|
echo "• User configurations: $CONFIG_DIR/ (if contains user data)"
|
|
|
215
|
echo "• Mount points: /mnt/autonas/ (if contains data)"
|
|
|
216
|
echo "• NFS exports: /etc/exports (manual edit required)"
|
|
|
217
|
echo ""
|
|
|
218
|
echo "📝 To completely remove all AutoNAS data:"
|
|
|
219
|
echo "sudo rm -rf $CONFIG_DIR"
|
|
|
220
|
echo "sudo rm -rf /mnt/autonas"
|
|
|
221
|
echo "sudo nano /etc/exports # Remove AutoNAS entries manually"
|
|
|
222
|
echo "sudo exportfs -ra"
|
|
|
223
|
fi
|
|
|
224
|
echo ""
|
|
|
225
|
echo "🔄 To reinstall AutoNAS later, run: sudo bash scripts/install.sh"
|