Skip to content

Commit 5184ff5

Browse files
trlyampcode-com
andcommitted
Add uninstall script and command
Amp-Thread-ID: https://ampcode.com/threads/T-e17b5d82-0852-408b-87fe-6867a0ba8d11 Co-authored-by: Amp <amp@ampcode.com>
1 parent 45939a2 commit 5184ff5

File tree

2 files changed

+252
-0
lines changed

2 files changed

+252
-0
lines changed

revenue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ COMMANDS:
7070
7171
demo Manage demo applications (delegates to amp_demos/demo.sh)
7272
73+
uninstall Remove configuration and files (delegates to uninstall.sh)
74+
7375
help Show this help message
7476
7577
EXAMPLES:
@@ -78,6 +80,7 @@ EXAMPLES:
7880
revenue update
7981
revenue reset --confirm
8082
revenue demo start python flask
83+
revenue uninstall
8184
revenue help
8285
8386
For more information, visit: https://github.com/sourcegraph/revenue
@@ -491,6 +494,10 @@ main() {
491494
cd "$SCRIPT_DIR/amp_demos"
492495
exec bash "./demo" "$@"
493496
;;
497+
"uninstall")
498+
shift # Remove 'uninstall' from arguments
499+
exec bash "$SCRIPT_DIR/uninstall.sh" "$@"
500+
;;
494501
"help" | "-h" | "--help")
495502
show_help
496503
;;

uninstall.sh

Lines changed: 245 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,245 @@
1+
#!/bin/bash
2+
3+
# Sourcegraph Revenue Team Workstation Uninstaller
4+
# This script removes the configuration and files created by the installer
5+
6+
set -e
7+
8+
# Colors for output
9+
RED='\033[0;31m'
10+
GREEN='\033[0;32m'
11+
BLUE='\033[0;34m'
12+
YELLOW='\033[1;33m'
13+
NC='\033[0m' # No Color
14+
15+
# Function to print colored output
16+
print_success() {
17+
echo -e "${GREEN}${NC} $1"
18+
}
19+
20+
print_info() {
21+
echo -e "${BLUE}${NC} $1"
22+
}
23+
24+
print_warning() {
25+
echo -e "${YELLOW}${NC} $1"
26+
}
27+
28+
print_error() {
29+
echo -e "${RED}${NC} $1"
30+
}
31+
32+
# Parse command line arguments
33+
FORCE=false
34+
KEEP_REPO=false
35+
36+
while [[ $# -gt 0 ]]; do
37+
case $1 in
38+
--force)
39+
FORCE=true
40+
shift
41+
;;
42+
--keep-repo)
43+
KEEP_REPO=true
44+
shift
45+
;;
46+
--help | -h)
47+
print_info "Sourcegraph Revenue Team Workstation Uninstaller"
48+
echo ""
49+
print_info "Usage: $0 [OPTIONS]"
50+
echo ""
51+
print_info "Options:"
52+
print_info " --force Skip confirmation prompts"
53+
print_info " --keep-repo Do not remove the repository directory"
54+
print_info " --help, -h Show this help message"
55+
echo ""
56+
exit 0
57+
;;
58+
*)
59+
print_error "Unknown option: $1"
60+
print_info "Use --help for usage information"
61+
exit 1
62+
;;
63+
esac
64+
done
65+
66+
# Detect user's current shell (same logic as install.sh)
67+
detect_shell() {
68+
local current_shell
69+
current_shell=$(basename "$SHELL" 2>/dev/null || echo "unknown")
70+
71+
case "$current_shell" in
72+
zsh | bash)
73+
echo "$current_shell"
74+
;;
75+
*)
76+
if [[ -n "$ZSH_VERSION" ]]; then
77+
echo "zsh"
78+
elif [[ -n "$BASH_VERSION" ]]; then
79+
echo "bash"
80+
else
81+
echo "zsh" # Default
82+
fi
83+
;;
84+
esac
85+
}
86+
87+
# Get shell profile path (same logic as install.sh)
88+
get_shell_profile() {
89+
local shell_type="$1"
90+
91+
case "$shell_type" in
92+
zsh)
93+
echo "$HOME/.zshrc"
94+
;;
95+
bash)
96+
if [[ -f "$HOME/.bash_profile" ]]; then
97+
echo "$HOME/.bash_profile"
98+
elif [[ -f "$HOME/.bashrc" ]]; then
99+
echo "$HOME/.bashrc"
100+
else
101+
echo "$HOME/.bash_profile"
102+
fi
103+
;;
104+
*)
105+
echo "$HOME/.profile"
106+
;;
107+
esac
108+
}
109+
110+
# Confirmation prompt
111+
confirm() {
112+
if [[ "$FORCE" == true ]]; then
113+
return 0
114+
fi
115+
116+
read -p "$1 [y/N] " -n 1 -r
117+
echo
118+
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
119+
return 1
120+
fi
121+
return 0
122+
}
123+
124+
print_info "This will remove the Sourcegraph Revenue Team Workstation configuration."
125+
if ! confirm "Are you sure you want to continue?"; then
126+
print_info "Uninstall cancelled."
127+
exit 0
128+
fi
129+
130+
# Remove global command
131+
remove_global_command() {
132+
local symlink_path="$HOME/.local/bin/revenue"
133+
134+
if [[ -L "$symlink_path" || -f "$symlink_path" ]]; then
135+
print_info "Removing global revenue command..."
136+
rm "$symlink_path"
137+
print_success "Removed $symlink_path"
138+
else
139+
print_info "Global revenue command not found at $symlink_path"
140+
fi
141+
}
142+
143+
# Remove configuration from shell profile
144+
clean_shell_profile() {
145+
local shell_type
146+
shell_type=$(detect_shell)
147+
local profile_path
148+
profile_path=$(get_shell_profile "$shell_type")
149+
local profile_backup="${profile_path}.bak.$(date +%s)"
150+
151+
if [[ -f "$profile_path" ]]; then
152+
print_info "Checking shell profile: $(basename "$profile_path")"
153+
154+
# Check if we need to modify the file
155+
if grep -q "export PATH.*\.local/bin" "$profile_path" || grep -q "mise activate" "$profile_path"; then
156+
157+
print_info "Backing up profile to $(basename "$profile_backup")..."
158+
cp "$profile_path" "$profile_backup"
159+
160+
# Remove PATH addition
161+
# We use a temporary file to handle the sed differences and multi-line removals cleanly
162+
local temp_file
163+
temp_file=$(mktemp)
164+
165+
# Filter out the lines we added
166+
# Note: detailed matching to avoid removing user's own configs if they manually added similar lines
167+
# We look for the comments we added in install.sh
168+
169+
awk '
170+
BEGIN { skip = 0 }
171+
/# Add .*\/revenue\/.local\/bin to PATH/ { skip = 1; next }
172+
/# Add .*\/.local\/bin to PATH/ { skip = 1; next }
173+
/export PATH=".*\.local\/bin:\$PATH"/ {
174+
if (skip) { skip = 0; next }
175+
}
176+
/# Initialize mise/ { skip = 1; next }
177+
/eval "\$\(mise activate.*\)"/ {
178+
if (skip) { skip = 0; next }
179+
}
180+
{ print }
181+
' "$profile_path" > "$temp_file"
182+
183+
# Check if changes were made
184+
if ! cmp -s "$profile_path" "$temp_file"; then
185+
mv "$temp_file" "$profile_path"
186+
print_success "Removed configuration from $(basename "$profile_path")"
187+
print_info "You may need to restart your shell for changes to take effect."
188+
else
189+
rm "$temp_file"
190+
print_info "No automated changes made to $(basename "$profile_path") (patterns did not match exactly)"
191+
print_info "You may want to manually check for leftover configuration."
192+
fi
193+
else
194+
print_success "No revenue configuration found in $(basename "$profile_path")"
195+
fi
196+
fi
197+
}
198+
199+
# Remove repository
200+
remove_repository() {
201+
# Get directory of this script to find repo root
202+
# Assuming script is in repo root
203+
local script_dir
204+
script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
205+
206+
if [[ "$KEEP_REPO" == true ]]; then
207+
print_info "Skipping repository removal (--keep-repo specified)"
208+
print_info "Repository remains at: $script_dir"
209+
return
210+
fi
211+
212+
# Basic safety check - ensure we are removing the revenue repo
213+
if [[ -d "$script_dir/.git" ]] && grep -q "sourcegraph/revenue" "$script_dir/.git/config"; then
214+
if confirm "Do you want to remove the repository at $script_dir?"; then
215+
print_info "Removing repository..."
216+
# We can't remove the directory we are running the script from while running it easily
217+
# So we schedule it for removal or move to tmp?
218+
# Better approach: warn user that the script file itself will be gone.
219+
220+
# We will remove everything inside EXCEPT this script first, then finish?
221+
# Actually, simple rm -rf usually works on executed scripts in bash (it stays in memory),
222+
# but let's be safe and tell user to delete the dir manually if it fails.
223+
224+
rm -rf "$script_dir" || {
225+
print_warning "Could not remove directory while script is running."
226+
print_info "Please manually remove: $script_dir"
227+
}
228+
print_success "Repository removed"
229+
fi
230+
else
231+
print_warning "Current directory does not look like the revenue repository. Skipping removal."
232+
print_info "Path: $script_dir"
233+
fi
234+
}
235+
236+
# Main
237+
remove_global_command
238+
clean_shell_profile
239+
remove_repository
240+
241+
echo ""
242+
print_success "Uninstall complete!"
243+
print_info "Note: Homebrew and Amp CLI were NOT uninstalled as they may be used by other tools."
244+
print_info "To uninstall Amp CLI manually, remove ~/.amp (or check amp docs)."
245+
print_info "To uninstall Homebrew manually, see https://brew.sh"

0 commit comments

Comments
 (0)