-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuninstall.sh
More file actions
executable file
·500 lines (428 loc) · 13.7 KB
/
uninstall.sh
File metadata and controls
executable file
·500 lines (428 loc) · 13.7 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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
#!/bin/bash
set -e
echo "🗑️ Eclipse Formatter CLI Uninstaller"
echo "======================================"
# Colours for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Colour
# Detect all installed files
detect_installations() {
echo -e "${YELLOW}🔍 Detecting installed files...${NC}"
echo ""
local found_count=0
# Common installation locations
local locations=(
# System locations
"/usr/local/bin/eclipse-format"
"/usr/local/bin/eclipse-format.jar"
"/usr/bin/eclipse-format"
"/usr/bin/eclipse-format.jar"
# User locations
"$HOME/.local/bin/eclipse-format"
"$HOME/.local/bin/eclipse-format.jar"
"$HOME/bin/eclipse-format"
"$HOME/bin/eclipse-format.jar"
# Project directory
"$(pwd)/eclipse-format"
"$(pwd)/eclipse-format.jar"
"$(pwd)/eclipse-format.sh"
"$(pwd)/eclipse-format.bat"
"$(pwd)/eclipse-format-simple.sh"
# Other common locations
"/opt/eclipse-format/"
"$HOME/Applications/eclipse-format"
)
for location in "${locations[@]}"; do
if [ -e "$location" ]; then
found_count=$((found_count + 1))
if [ -f "$location" ]; then
local size=$(du -h "$location" 2>/dev/null | cut -f1 || echo "?")
echo -e "${GREEN}✅ Found file: $location${NC} (Size: $size)"
elif [ -d "$location" ]; then
local item_count=$(find "$location" -type f 2>/dev/null | wc -l || echo "?")
echo -e "${BLUE}📁 Found directory: $location${NC} (Files: $item_count)"
fi
fi
done
if [ $found_count -eq 0 ]; then
echo -e "${YELLOW}⚠️ No Eclipse Formatter CLI installations detected${NC}"
else
echo ""
echo -e "${GREEN}Found $found_count installation(s)${NC}"
fi
return $found_count
}
# Interactive uninstall
interactive_uninstall() {
detect_installations
local found_count=$?
if [ $found_count -eq 0 ]; then
exit 0
fi
echo ""
echo "Uninstall Options:"
echo " 1) Remove system-wide installation (/usr/local/bin)"
echo " 2) Remove local user installation (~/.local/bin)"
echo " 3) Remove ALL detected installations"
echo " 4) Remove specific file or directory"
echo " 5) Cancel"
echo ""
read -p "Choose option (1-5): " -n 1 -r
echo
case $REPLY in
1)
remove_system
;;
2)
remove_local
;;
3)
remove_all
;;
4)
remove_specific
;;
5)
echo "Cancelled"
exit 0
;;
*)
echo -e "${RED}❌ Invalid option${NC}"
exit 1
;;
esac
}
# Remove system-wide installation
remove_system() {
echo -e "${YELLOW}🗑️ Removing system-wide installation...${NC}"
local removed=0
local need_sudo=false
# Check if we can write to /usr/local/bin
if [ ! -w "/usr/local/bin" ] && [ "$(id -u)" -ne 0 ]; then
need_sudo=true
fi
if [ -f "/usr/local/bin/eclipse-format" ]; then
echo "Removing: /usr/local/bin/eclipse-format"
if [ "$need_sudo" = true ]; then
sudo rm -f "/usr/local/bin/eclipse-format"
else
rm -f "/usr/local/bin/eclipse-format"
fi
removed=$((removed + 1))
fi
if [ -f "/usr/local/bin/eclipse-format.jar" ]; then
echo "Removing: /usr/local/bin/eclipse-format.jar"
if [ "$need_sudo" = true ]; then
sudo rm -f "/usr/local/bin/eclipse-format.jar"
else
rm -f "/usr/local/bin/eclipse-format.jar"
fi
removed=$((removed + 1))
fi
if [ $removed -eq 0 ]; then
echo -e "${YELLOW}⚠️ No system-wide installation found${NC}"
else
echo -e "${GREEN}✅ Removed $removed system file(s)${NC}"
fi
}
# Remove local user installation
remove_local() {
echo -e "${YELLOW}🗑️ Removing local user installation...${NC}"
local removed=0
# ~/.local/bin
if [ -f "$HOME/.local/bin/eclipse-format" ]; then
echo "Removing: $HOME/.local/bin/eclipse-format"
rm -f "$HOME/.local/bin/eclipse-format"
removed=$((removed + 1))
fi
if [ -f "$HOME/.local/bin/eclipse-format.jar" ]; then
echo "Removing: $HOME/.local/bin/eclipse-format.jar"
rm -f "$HOME/.local/bin/eclipse-format.jar"
removed=$((removed + 1))
fi
# ~/bin
if [ -f "$HOME/bin/eclipse-format" ]; then
echo "Removing: $HOME/bin/eclipse-format"
rm -f "$HOME/bin/eclipse-format"
removed=$((removed + 1))
fi
if [ -f "$HOME/bin/eclipse-format.jar" ]; then
echo "Removing: $HOME/bin/eclipse-format.jar"
rm -f "$HOME/bin/eclipse-format.jar"
removed=$((removed + 1))
fi
if [ $removed -eq 0 ]; then
echo -e "${YELLOW}⚠️ No local user installation found${NC}"
else
echo -e "${GREEN}✅ Removed $removed local file(s)${NC}"
fi
}
# Remove all detected installations
remove_all() {
echo -e "${YELLOW}🗑️ Removing ALL installations...${NC}"
echo ""
# First pass: remove files we can remove without asking
local auto_locations=(
"$HOME/.local/bin/eclipse-format"
"$HOME/.local/bin/eclipse-format.jar"
"$HOME/bin/eclipse-format"
"$HOME/bin/eclipse-format.jar"
"$(pwd)/eclipse-format"
"$(pwd)/eclipse-format.jar"
"$(pwd)/eclipse-format.sh"
"$(pwd)/eclipse-format.bat"
"$(pwd)/eclipse-format-simple.sh"
)
for location in "${auto_locations[@]}"; do
if [ -f "$location" ]; then
echo "Removing: $location"
rm -f "$location"
fi
done
echo ""
echo -e "${YELLOW}System files (may require sudo):${NC}"
# System files that might need sudo
local system_locations=(
"/usr/local/bin/eclipse-format"
"/usr/local/bin/eclipse-format.jar"
"/usr/bin/eclipse-format"
"/usr/bin/eclipse-format.jar"
)
local need_sudo=false
for location in "${system_locations[@]}"; do
if [ -f "$location" ]; then
if [ ! -w "$(dirname "$location")" ] && [ "$(id -u)" -ne 0 ]; then
need_sudo=true
fi
break
fi
done
if [ "$need_sudo" = true ]; then
echo -e "${YELLOW}⚠️ Some system files require sudo permission${NC}"
read -p "Continue with sudo? (y/N): " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Skipping system files"
else
for location in "${system_locations[@]}"; do
if [ -f "$location" ]; then
echo "Removing: $location"
sudo rm -f "$location"
fi
done
fi
else
for location in "${system_locations[@]}"; do
if [ -f "$location" ]; then
echo "Removing: $location"
rm -f "$location"
fi
done
fi
# Check for directories
echo ""
echo -e "${YELLOW}Checking for directories...${NC}"
local dir_locations=(
"/opt/eclipse-format/"
"$HOME/Applications/eclipse-format"
)
for location in "${dir_locations[@]}"; do
if [ -d "$location" ]; then
echo -e "${YELLOW}Found directory: $location${NC}"
read -p "Remove this directory? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
if [ ! -w "$location" ] && [ "$(id -u)" -ne 0 ]; then
echo "Removing with sudo: $location"
sudo rm -rf "$location"
else
echo "Removing: $location"
rm -rf "$location"
fi
fi
fi
done
echo -e "${GREEN}✅ Uninstall complete${NC}"
}
# Remove specific file or directory
remove_specific() {
echo -e "${YELLOW}🗑️ Remove specific file or directory${NC}"
echo "Enter the full path to remove:"
echo "(e.g., /usr/local/bin/eclipse-format or ~/.local/bin/eclipse-format.jar)"
echo ""
read -p "Path: " target_path
# Expand ~ to home directory
target_path="${target_path/#\~/$HOME}"
if [ -z "$target_path" ]; then
echo -e "${RED}❌ No path specified${NC}"
exit 1
fi
if [ ! -e "$target_path" ]; then
echo -e "${RED}❌ Path does not exist: $target_path${NC}"
exit 1
fi
echo ""
echo -e "${YELLOW}Target: $target_path${NC}"
if [ -f "$target_path" ]; then
echo "Type: File"
ls -la "$target_path"
elif [ -d "$target_path" ]; then
echo "Type: Directory"
ls -la "$target_path/" | head -10
echo "..."
else
echo -e "${RED}❌ Not a file or directory${NC}"
exit 1
fi
echo ""
read -p "Are you sure you want to remove this? (y/N): " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Cancelled"
exit 0
fi
# Check permissions
if [ ! -w "$(dirname "$target_path")" ] && [ "$(id -u)" -ne 0 ]; then
echo -e "${YELLOW}⚠️ Need sudo permission${NC}"
if [ -f "$target_path" ]; then
sudo rm -f "$target_path"
elif [ -d "$target_path" ]; then
sudo rm -rf "$target_path"
fi
else
if [ -f "$target_path" ]; then
rm -f "$target_path"
elif [ -d "$target_path" ]; then
rm -rf "$target_path"
fi
fi
echo -e "${GREEN}✅ Removed: $target_path${NC}"
}
# Clean up PATH entries
cleanup_path() {
echo -e "${YELLOW}🔧 Optional: Clean up PATH entries${NC}"
echo "The installer may have added entries to your PATH."
echo "Would you like to remove them from your shell configuration?"
echo ""
echo "Shell configuration files checked:"
echo " ~/.bashrc, ~/.bash_profile, ~/.zshrc, ~/.profile"
echo ""
read -p "Clean up PATH entries? (y/N): " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
return
fi
local shell_files=(
"$HOME/.bashrc"
"$HOME/.bash_profile"
"$HOME/.zshrc"
"$HOME/.profile"
)
local path_patterns=(
'export PATH="\$HOME/.local/bin:\$PATH"'
'export PATH=\$HOME/.local/bin:\$PATH'
'export PATH="\$HOME/bin:\$PATH"'
'export PATH=\$HOME/bin:\$PATH'
'# Eclipse Formatter CLI'
)
for file in "${shell_files[@]}"; do
if [ -f "$file" ]; then
local temp_file="${file}.tmp"
local changed=false
# Create a backup
cp "$file" "${file}.backup-$(date +%Y%m%d-%H%M%S)"
# Remove lines matching our patterns
grep -v -F -f <(printf "%s\n" "${path_patterns[@]}") "$file" > "$temp_file" || true
if ! cmp -s "$file" "$temp_file"; then
mv "$temp_file" "$file"
echo "Cleaned: $file"
changed=true
else
rm -f "$temp_file"
fi
if [ "$changed" = true ]; then
echo -e "${GREEN}✅ Updated $file${NC}"
echo "Backup created: ${file}.backup-*"
fi
fi
done
echo ""
echo -e "${YELLOW}⚠️ Changes will take effect after restarting your shell${NC}"
echo "Or run: source ~/.bashrc (or your shell config file)"
}
# Show help
show_help() {
cat << EOF
${BLUE}Eclipse Formatter CLI Uninstaller${NC}
${GREEN}Version: 0.1${NC}
${YELLOW}GitHub: https://github.com/algodesigner/eclipse-format${NC}
Usage:
./uninstall.sh [options]
Options:
--help, -h Show this help message
--system Remove system-wide installation only
--local Remove local user installation only
--all Remove ALL installations (default)
--specific <path> Remove specific file or directory
--clean-path Clean up PATH entries from shell config
--interactive Interactive mode (default)
Examples:
./uninstall.sh # Interactive uninstall
./uninstall.sh --system # Remove system files only
./uninstall.sh --local # Remove user files only
./uninstall.sh --all # Remove everything
./uninstall.sh --clean-path # Clean PATH entries
./uninstall.sh --specific ~/.local/bin/eclipse-format
EOF
}
# Main function
main() {
# Parse command line arguments
if [ $# -eq 0 ]; then
interactive_uninstall
cleanup_path
exit 0
fi
case "$1" in
--help|-h)
show_help
exit 0
;;
--system)
remove_system
;;
--local)
remove_local
;;
--all)
remove_all
;;
--specific)
if [ -z "$2" ]; then
echo -e "${RED}❌ --specific requires a path argument${NC}"
exit 1
fi
target_path="$2"
remove_specific
;;
--clean-path)
cleanup_path
;;
--interactive)
interactive_uninstall
cleanup_path
;;
*)
echo -e "${RED}❌ Unknown option: $1${NC}"
show_help
exit 1
;;
esac
echo ""
echo -e "${GREEN}🎉 Uninstall complete!${NC}"
}
# Run main function
main "$@"