-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuninstall.sh
More file actions
395 lines (338 loc) · 11.3 KB
/
uninstall.sh
File metadata and controls
395 lines (338 loc) · 11.3 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
#!/bin/bash
#############################################################################
# pyp C++ Virtual Environment Manager - Uninstallation Script
# Removes the pyp binary and cleans up configuration
#############################################################################
# Colors for beautiful output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
BOLD='\033[1m'
RESET='\033[0m'
# Configuration
APP_NAME="pyp"
BINARY_NAME="pyp"
INSTALL_DIR="${HOME}/.local/bin"
CONFIG_FILE="${HOME}/.pyp_config.json"
BACKUP_FILE="${HOME}/.pyp_config.json.backup"
SOURCE_DIR="$(pwd)"
# Version info
VERSION="2.0.0"
echo -e "${BOLD}${CYAN}"
echo " ____ _____ _ ____ _____ ___ ___ _ _ ____ "
echo " | _ \\| ____| / \\ / ___| |_ _|_ _|_ _| | | | _ \\ "
echo " | |_) | _| / _ \\ \\___ \\ | | | | | | | | | |_) |"
echo " | __/| |___ / ___ \\ ___) | | | | | | | |_| | __/ "
echo " |_| |_____/_/ \\_\\____/ |_| |___|___| (_)_| |_| "
echo -e "${RESET}"
echo -e "${BOLD} Python Virtual Environment Manager - Uninstaller${RESET}"
echo -e " Version ${VERSION}"
echo ""
echo ""
# Function to print status messages
print_status() {
echo -e "${BLUE}[*]${RESET} $1"
}
print_success() {
echo -e "${GREEN}[✓]${RESET} $1"
}
print_warning() {
echo -e "${YELLOW}[!]${RESET} $1"
}
print_error() {
echo -e "${RED}[✗]${RESET} $1"
}
# Show usage information
show_usage() {
echo -e "${BOLD}Usage:${RESET}"
echo " ./uninstall.sh [OPTIONS]"
echo ""
echo -e "${BOLD}Options:${RESET}"
echo " --help Show this help message"
echo " --keep-config Keep configuration file"
echo " --force Skip confirmation"
echo " --install-dir Specify installation directory"
echo ""
echo -e "${BOLD}This will:${RESET}"
echo " 1. Remove the pyp binary"
echo " 2. Remove PATH configuration from shell files"
echo " 3. Optionally remove configuration file"
echo ""
}
# Parse command line arguments
parse_args() {
KEEP_CONFIG=false
FORCE=false
while [[ $# -gt 0 ]]; do
case $1 in
--help)
show_usage
exit 0
;;
--keep-config)
KEEP_CONFIG=true
shift
;;
--force)
FORCE=true
shift
;;
--install-dir)
INSTALL_DIR="$2"
shift 2
;;
*)
print_error "Unknown option: $1"
show_usage
exit 1
;;
esac
done
}
# Check if pyp is installed
check_installation() {
print_status "Checking installation..."
INSTALLED=false
INSTALL_PATH=""
# Check common installation locations
if [ -L "${INSTALL_DIR}/${BINARY_NAME}" ]; then
INSTALLED=true
INSTALL_PATH=$(readlink -f "${INSTALL_DIR}/${BINARY_NAME}")
elif [ -f "${INSTALL_DIR}/${BINARY_NAME}" ]; then
INSTALLED=true
INSTALL_PATH="${INSTALL_DIR}/${BINARY_NAME}"
elif [ -f "/usr/local/bin/${BINARY_NAME}" ]; then
INSTALLED=true
INSTALL_DIR="/usr/local/bin"
INSTALL_PATH="/usr/local/bin/${BINARY_NAME}"
elif [ -f "/usr/bin/${BINARY_NAME}" ]; then
INSTALLED=true
INSTALL_DIR="/usr/bin"
INSTALL_PATH="/usr/bin/${BINARY_NAME}"
fi
if [ "$INSTALLED" = true ]; then
print_success "Found pyp installation"
echo -e " ${CYAN}Location: ${RESET}${INSTALL_PATH}"
if [ -f "$INSTALL_PATH" ]; then
if command -v file &> /dev/null; then
FILE_INFO=$(file "$INSTALL_PATH" | head -1)
echo -e " ${CYAN}Type: ${RESET}${FILE_INFO}"
fi
fi
else
print_warning "pyp installation not found in standard locations"
print_status "Searching in PATH..."
if command -v pyp &> /dev/null; then
INSTALL_PATH=$(which pyp)
INSTALL_DIR=$(dirname "$INSTALL_PATH")
print_success "Found pyp in PATH"
echo -e " ${CYAN}Location: ${RESET}${INSTALL_PATH}"
else
print_warning "pyp binary not found"
fi
fi
return 0
}
# Confirm uninstallation
confirm_uninstall() {
if [ "$FORCE" = true ]; then
return 0
fi
echo ""
echo -e "${BOLD}${YELLOW}WARNING: This will remove pyp from your system!${RESET}"
echo ""
if [ "$KEEP_CONFIG" = false ]; then
echo -e "${YELLOW}Your configuration file will also be removed:${RESET}"
echo -e " ${CYAN}${CONFIG_FILE}${RESET}"
echo -e " ${CYAN}${BACKUP_FILE}${RESET}"
else
echo -e "${GREEN}Configuration file will be preserved${RESET}"
fi
echo ""
echo -n -e "${BOLD}Do you want to continue? [y/N] ${RESET}"
read -r response
if [[ ! "$response" =~ ^[Yy]$ ]]; then
echo "Uninstallation cancelled."
exit 0
fi
}
# Remove binary
remove_binary() {
print_status "Removing pyp binary..."
# Try different locations
REMOVED=false
# Try symlink first
if [ -L "${INSTALL_DIR}/${BINARY_NAME}" ]; then
rm -f "${INSTALL_DIR}/${BINARY_NAME}"
print_success "Removed symlink: ${INSTALL_DIR}/${BINARY_NAME}"
REMOVED=true
fi
# Try direct binary
if [ -f "${INSTALL_DIR}/${BINARY_NAME}" ]; then
rm -f "${INSTALL_DIR}/${BINARY_NAME}"
print_success "Removed binary: ${INSTALL_DIR}/${BINARY_NAME}"
REMOVED=true
fi
# Check /usr/local/bin
if [ -f "/usr/local/bin/${BINARY_NAME}" ]; then
sudo rm -f "/usr/local/bin/${BINARY_NAME}"
print_success "Removed: /usr/local/bin/${BINARY_NAME}"
REMOVED=true
fi
# Check /usr/bin
if [ -f "/usr/bin/${BINARY_NAME}" ]; then
sudo rm -f "/usr/bin/${BINARY_NAME}"
print_success "Removed: /usr/bin/${BINARY_NAME}"
REMOVED=true
fi
if [ "$REMOVED" = false ]; then
print_warning "No pyp binary found to remove"
fi
}
# Remove PATH configuration from shell files
clean_path_config() {
print_status "Cleaning PATH configuration from shell files..."
# Shell configuration files to check
SHELL_CONFIGS=(
"${HOME}/.bashrc"
"${HOME}/.bash_profile"
"${HOME}/.zshrc"
"${HOME}/.profile"
"${HOME}/.bash_login"
)
CONFIG_REMOVED=false
for CONFIG_FILE in "${SHELL_CONFIGS[@]}"; do
if [ -f "$CONFIG_FILE" ]; then
# Check for pyp-related entries
if grep -q "pyp" "$CONFIG_FILE" 2>/dev/null || grep -q "${INSTALL_DIR}" "$CONFIG_FILE" 2>/dev/null; then
print_status "Found pyp configuration in ${CONFIG_FILE}"
# Create backup
cp "$CONFIG_FILE" "${CONFIG_FILE}.bak"
print_success "Backup created: ${CONFIG_FILE}.bak"
# Remove pyp-related lines
# First, remove comments about pyp
sed -i.bak '/#.*pyp.*/d' "$CONFIG_FILE" 2>/dev/null
# Remove PATH additions for pyp
if grep -q "pyp" "$CONFIG_FILE" 2>/dev/null; then
# Use different sed syntax for different platforms
if [[ "$OSTYPE" == "darwin"* ]]; then
# macOS sed
sed -i '' "/pyp/d" "$CONFIG_FILE" 2>/dev/null
sed -i '' "/${INSTALL_DIR//\//\\\/}/d" "$CONFIG_FILE" 2>/dev/null
else
# Linux sed
sed -i "/pyp/d" "$CONFIG_FILE" 2>/dev/null
sed -i "/${INSTALL_DIR//\//\\\/}/d" "$CONFIG_FILE" 2>/dev/null
fi
fi
CONFIG_REMOVED=true
fi
fi
done
if [ "$CONFIG_REMOVED" = true ]; then
print_success "Cleaned PATH configuration"
print_warning "You may need to restart your shell or run:"
echo -e " ${GREEN}source ~/.bashrc${RESET} # or ~/.zshrc"
else
print_success "No PATH configuration found to clean"
fi
}
# Remove configuration files
remove_config() {
if [ "$KEEP_CONFIG" = true ]; then
print_status "Keeping configuration files (--keep-config specified)"
return 0
fi
print_status "Removing configuration files..."
if [ -f "${CONFIG_FILE}" ]; then
# Create backup just in case
if [ ! -f "${BACKUP_FILE}" ]; then
cp "${CONFIG_FILE}" "${BACKUP_FILE}"
print_status "Created backup: ${BACKUP_FILE}"
fi
rm -f "${CONFIG_FILE}"
print_success "Removed: ${CONFIG_FILE}"
fi
# Remove any other pyp-related files
if [ -f "${HOME}/.pyp_history" ]; then
rm -f "${HOME}/.pyp_history"
print_success "Removed: ${HOME}/.pyp_history"
fi
}
# Clean up local files
cleanup_local() {
print_status "Cleaning up local files..."
LOCAL_FILES=(
"pyp"
"main.cpp"
"install.sh"
"uninstall.sh"
)
for file in "${LOCAL_FILES[@]}"; do
if [ -f "$file" ]; then
print_status "Found local file: $file"
print_warning "This file was part of the source directory"
fi
done
}
# Verify uninstallation
verify_uninstall() {
print_status "Verifying uninstallation..."
# Check if binary is still accessible
if command -v pyp &> /dev/null; then
print_warning "pyp is still accessible in PATH"
print_status "Location: $(which pyp)"
echo -e "${YELLOW}You may need to manually remove it${RESET}"
else
print_success "pyp binary removed from PATH"
fi
# Check if symlink/binary still exists
if [ -L "${INSTALL_DIR}/${BINARY_NAME}" ] || [ -f "${INSTALL_DIR}/${BINARY_NAME}" ]; then
print_warning "pyp binary still exists at ${INSTALL_DIR}/${BINARY_NAME}"
echo -e "${YELLOW}You may need to manually remove it${RESET}"
fi
}
# Show completion message
show_completion() {
echo ""
echo -e "${BOLD}${GREEN}========================================${RESET}"
echo -e "${BOLD}${GREEN} Uninstallation Complete!${RESET}"
echo -e "${BOLD}${GREEN}========================================${RESET}"
echo ""
echo -e "${BOLD}Removed:${RESET}"
echo -e " ${RED}✗${RESET} pyp binary"
if [ "$KEEP_CONFIG" = false ]; then
echo -e " ${RED}✗${RESET} Configuration files"
fi
echo -e " ${GREEN}✓${RESET} PATH configuration"
echo ""
if [ -f "${BACKUP_FILE}" ]; then
echo -e "${YELLOW}Note: Backup files preserved:${RESET}"
echo -e " ${CYAN}${BACKUP_FILE}${RESET}"
fi
echo ""
echo -e "${BOLD}Thank you for using pyp!${RESET}"
echo ""
}
# Main uninstallation flow
main() {
KEEP_CONFIG=false
FORCE=false
parse_args "$@"
echo -e "${BOLD}========================================${RESET}"
echo -e "${BOLD} pyp Uninstallation Script${RESET}"
echo -e "${BOLD}========================================${RESET}"
echo ""
check_installation
confirm_uninstall
remove_binary
clean_path_config
remove_config
cleanup_local
verify_uninstall
show_completion
}
# Run main function
main "$@"