Skip to content

Commit de58fe0

Browse files
Add uninstall.sh
1 parent 1f25f40 commit de58fe0

1 file changed

Lines changed: 188 additions & 0 deletions

File tree

uninstall.sh

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
#!/bin/bash
2+
3+
# Luca Uninstallation Script
4+
# This script removes the Luca executable and its associated shell hooks
5+
6+
# =============================================================================
7+
# CONFIGURATION VARIABLES
8+
# =============================================================================
9+
10+
TOOL_NAME="Luca"
11+
INSTALL_DIR="/usr/local/bin"
12+
TOOL_FOLDER=".luca"
13+
TOOL_DIR="$HOME/$TOOL_FOLDER"
14+
SHELL_HOOK_SCRIPT_PATH="$TOOL_DIR/shell_hook.sh"
15+
EXECUTABLE_FILE="$INSTALL_DIR/$TOOL_NAME"
16+
17+
# =============================================================================
18+
# TERMINAL COLORS
19+
# =============================================================================
20+
21+
RED='\033[0;31m'
22+
GREEN='\033[0;32m'
23+
YELLOW='\033[0;33m'
24+
BLUE='\033[0;34m'
25+
NC='\033[0m' # No Color
26+
27+
# =============================================================================
28+
# HELPER FUNCTIONS
29+
# =============================================================================
30+
31+
print_header() {
32+
echo -e "\n${BLUE}==============================================================================${NC}"
33+
echo -e "${BLUE}$1${NC}"
34+
echo -e "${BLUE}==============================================================================${NC}\n"
35+
}
36+
37+
print_success() {
38+
echo -e "${GREEN}$1${NC}"
39+
}
40+
41+
print_warning() {
42+
echo -e "${YELLOW}⚠️ $1${NC}"
43+
}
44+
45+
print_error() {
46+
echo -e "${RED}$1${NC}"
47+
}
48+
49+
print_info() {
50+
echo -e "${BLUE}ℹ️ $1${NC}"
51+
}
52+
53+
# Helper function to run commands with sudo only if needed
54+
sudo_if_install_dir_not_writeable() {
55+
local command="$1"
56+
if [ -w "$INSTALL_DIR" ]; then
57+
# Directory is writable, run without sudo
58+
sh -c "$command"
59+
else
60+
# Directory requires elevated privileges
61+
print_info "Administrator privileges required to remove files from $INSTALL_DIR"
62+
sudo sh -c "$command"
63+
fi
64+
}
65+
66+
# =============================================================================
67+
# CHECK FOR EXISTING INSTALLATION
68+
# =============================================================================
69+
70+
print_header "CHECKING FOR EXISTING INSTALLATION"
71+
72+
if [ -f "$EXECUTABLE_FILE" ]; then
73+
print_info "Found $TOOL_NAME installation at $EXECUTABLE_FILE"
74+
75+
# Get the currently installed version
76+
EXISTING_EXECUTABLE_VERSION=$($EXECUTABLE_FILE --version 2>/dev/null)
77+
78+
if [ -n "$EXISTING_EXECUTABLE_VERSION" ]; then
79+
print_info "Current version: $EXISTING_EXECUTABLE_VERSION"
80+
fi
81+
else
82+
print_warning "No $TOOL_NAME installation found at $EXECUTABLE_FILE"
83+
fi
84+
85+
if [ -d "$TOOL_DIR" ]; then
86+
print_info "Found tool directory at $TOOL_DIR"
87+
else
88+
print_warning "No tool directory found at $TOOL_DIR"
89+
fi
90+
91+
# =============================================================================
92+
# REMOVE EXECUTABLE
93+
# =============================================================================
94+
95+
print_header "REMOVING $TOOL_NAME EXECUTABLE"
96+
97+
if [ -f "$EXECUTABLE_FILE" ]; then
98+
print_info "Removing $EXECUTABLE_FILE..."
99+
sudo_if_install_dir_not_writeable "rm -f $EXECUTABLE_FILE"
100+
101+
if [ ! -f "$EXECUTABLE_FILE" ]; then
102+
print_success "$TOOL_NAME executable has been removed"
103+
else
104+
print_error "Failed to remove $TOOL_NAME executable"
105+
fi
106+
else
107+
print_warning "$TOOL_NAME executable not found at $EXECUTABLE_FILE"
108+
fi
109+
110+
# =============================================================================
111+
# REMOVE SHELL HOOK
112+
# =============================================================================
113+
114+
print_header "REMOVING SHELL HOOKS"
115+
116+
# Detect the current shell and set the appropriate RC file
117+
SHELL_RC_FILE=""
118+
HOOK_LINE="[[ -s \"\$HOME/$TOOL_FOLDER/shell_hook.sh\" ]] && source \"\$HOME/$TOOL_FOLDER/shell_hook.sh\""
119+
120+
case "$SHELL" in
121+
*/bash)
122+
SHELL_RC_FILE="$HOME/.bashrc"
123+
print_info "Detected Bash shell, checking $SHELL_RC_FILE"
124+
;;
125+
*/zsh)
126+
SHELL_RC_FILE="$HOME/.zshrc"
127+
print_info "Detected Zsh shell, checking $SHELL_RC_FILE"
128+
;;
129+
*)
130+
print_warning "Unsupported shell: $SHELL"
131+
print_warning "Manual cleanup may be required. Supported shells: bash, zsh"
132+
;;
133+
esac
134+
135+
# Remove shell hook reference from RC file if it exists
136+
if [ -n "$SHELL_RC_FILE" ] && [ -f "$SHELL_RC_FILE" ]; then
137+
if grep -Fq "$HOOK_LINE" "$SHELL_RC_FILE"; then
138+
print_info "Found hook in $SHELL_RC_FILE, removing..."
139+
140+
# Create a temporary file
141+
temp_file=$(mktemp)
142+
143+
# Remove the hook line and its comment
144+
grep -v -F "# Initialize $TOOL_NAME shell hook" "$SHELL_RC_FILE" | grep -v -F "$HOOK_LINE" > "$temp_file"
145+
146+
# Replace the original file with our modified version
147+
mv "$temp_file" "$SHELL_RC_FILE"
148+
149+
print_success "Shell hook removed from $SHELL_RC_FILE"
150+
else
151+
print_info "No shell hook found in $SHELL_RC_FILE"
152+
fi
153+
else
154+
print_warning "Shell configuration file not found: $SHELL_RC_FILE"
155+
fi
156+
157+
# =============================================================================
158+
# REMOVE TOOL DIRECTORY
159+
# =============================================================================
160+
161+
print_header "REMOVING TOOL DIRECTORY"
162+
163+
if [ -d "$TOOL_DIR" ]; then
164+
print_info "Removing tool directory at $TOOL_DIR..."
165+
rm -rf "$TOOL_DIR"
166+
167+
if [ ! -d "$TOOL_DIR" ]; then
168+
print_success "Tool directory has been removed"
169+
else
170+
print_error "Failed to remove tool directory at $TOOL_DIR"
171+
print_info "You may need to manually remove it with: rm -rf $TOOL_DIR"
172+
fi
173+
else
174+
print_info "Tool directory not found at $TOOL_DIR"
175+
fi
176+
177+
# =============================================================================
178+
# UNINSTALLATION COMPLETE
179+
# =============================================================================
180+
181+
print_header "UNINSTALLATION COMPLETE"
182+
183+
echo ""
184+
print_success "$TOOL_NAME has been uninstalled from your system"
185+
echo ""
186+
print_info "To complete the uninstallation, please restart your terminal or run:"
187+
echo "source $SHELL_RC_FILE"
188+
echo ""

0 commit comments

Comments
 (0)