Skip to content

Commit 07ff0b9

Browse files
committed
feat: add uninstall script
1 parent acd62a4 commit 07ff0b9

2 files changed

Lines changed: 145 additions & 0 deletions

File tree

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ git clone https://github.com/caffienerd/struct-cli.git && cd struct-cli
4040
chmod +x install.sh && ./install.sh
4141
```
4242

43+
## Uninstallation
44+
45+
```bash
46+
git clone https://github.com/caffienerd/struct-cli.git && cd struct-cli
47+
chmod +x uninstall.sh && ./uninstall.sh
48+
```
49+
4350
## Quick Start
4451

4552
```bash

uninstall.sh

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
#!/bin/bash
2+
3+
# Colors
4+
RED='\033[0;31m'
5+
GREEN='\033[0;32m'
6+
YELLOW='\033[1;33m'
7+
CYAN='\033[0;36m'
8+
NC='\033[0m' # No Color
9+
10+
echo -e "${CYAN}struct uninstaller${NC}"
11+
echo ""
12+
13+
# Check if Linux
14+
OS="$(uname -s)"
15+
if [ "$OS" != "Linux" ]; then
16+
echo -e "${RED}This uninstaller only supports Linux${NC}"
17+
exit 1
18+
fi
19+
20+
# Check common installation locations
21+
LOCATIONS=(
22+
"/usr/local/bin/struct"
23+
"$HOME/.local/bin/struct"
24+
"/usr/bin/struct"
25+
)
26+
27+
FOUND=()
28+
29+
echo -e "${CYAN}Checking for struct installations...${NC}"
30+
echo ""
31+
32+
for location in "${LOCATIONS[@]}"; do
33+
if [ -f "$location" ]; then
34+
FOUND+=("$location")
35+
echo -e "${YELLOW}Found: $location${NC}"
36+
fi
37+
done
38+
39+
if [ ${#FOUND[@]} -eq 0 ]; then
40+
echo -e "${YELLOW}No struct installations found${NC}"
41+
echo ""
42+
echo "Checked locations:"
43+
for location in "${LOCATIONS[@]}"; do
44+
echo " - $location"
45+
done
46+
exit 0
47+
fi
48+
49+
echo ""
50+
echo -e "${CYAN}Select what to remove:${NC}"
51+
52+
# Show menu with found installations
53+
for i in "${!FOUND[@]}"; do
54+
echo " $((i+1))) ${FOUND[$i]}"
55+
done
56+
echo " $((${#FOUND[@]}+1))) Remove all"
57+
echo " $((${#FOUND[@]}+2))) Cancel"
58+
59+
echo ""
60+
read -p "Enter choice: " choice
61+
62+
# Handle all option
63+
if [ "$choice" -eq $((${#FOUND[@]}+1)) ]; then
64+
echo ""
65+
for location in "${FOUND[@]}"; do
66+
if [[ "$location" == "/usr/local/bin/"* ]] || [[ "$location" == "/usr/bin/"* ]]; then
67+
echo -e "${YELLOW}Removing $location (requires sudo)${NC}"
68+
sudo rm -f "$location"
69+
else
70+
echo -e "${GREEN}Removing $location${NC}"
71+
rm -f "$location"
72+
fi
73+
done
74+
75+
# Remove config if exists
76+
CONFIG_PATH="$HOME/.config/struct"
77+
if [ -d "$CONFIG_PATH" ]; then
78+
echo ""
79+
read -p "Also remove config directory ($CONFIG_PATH)? (y/n): " remove_config
80+
if [ "$remove_config" = "y" ] || [ "$remove_config" = "Y" ]; then
81+
rm -rf "$CONFIG_PATH"
82+
echo -e "${GREEN}Removed config directory${NC}"
83+
fi
84+
fi
85+
86+
echo ""
87+
echo -e "${GREEN}All installations removed!${NC}"
88+
exit 0
89+
fi
90+
91+
# Handle cancel
92+
if [ "$choice" -eq $((${#FOUND[@]}+2)) ]; then
93+
echo ""
94+
echo -e "${YELLOW}Cancelled${NC}"
95+
exit 0
96+
fi
97+
98+
# Handle single selection
99+
if [ "$choice" -ge 1 ] && [ "$choice" -le ${#FOUND[@]} ]; then
100+
location="${FOUND[$((choice-1))]}"
101+
echo ""
102+
103+
if [[ "$location" == "/usr/local/bin/"* ]] || [[ "$location" == "/usr/bin/"* ]]; then
104+
echo -e "${YELLOW}Removing $location (requires sudo)${NC}"
105+
sudo rm -f "$location"
106+
else
107+
echo -e "${GREEN}Removing $location${NC}"
108+
rm -f "$location"
109+
fi
110+
111+
# Check if this was the last installation
112+
remaining=0
113+
for loc in "${FOUND[@]}"; do
114+
if [ -f "$loc" ] && [ "$loc" != "$location" ]; then
115+
remaining=$((remaining+1))
116+
fi
117+
done
118+
119+
# Ask about config only if this was the last installation
120+
if [ $remaining -eq 0 ]; then
121+
CONFIG_PATH="$HOME/.config/struct"
122+
if [ -d "$CONFIG_PATH" ]; then
123+
echo ""
124+
read -p "Also remove config directory ($CONFIG_PATH)? (y/n): " remove_config
125+
if [ "$remove_config" = "y" ] || [ "$remove_config" = "Y" ]; then
126+
rm -rf "$CONFIG_PATH"
127+
echo -e "${GREEN}Removed config directory${NC}"
128+
fi
129+
fi
130+
fi
131+
132+
echo ""
133+
echo -e "${GREEN}Uninstalled successfully!${NC}"
134+
else
135+
echo ""
136+
echo -e "${RED}Invalid choice${NC}"
137+
exit 1
138+
fi

0 commit comments

Comments
 (0)