-
Notifications
You must be signed in to change notification settings - Fork 0
/
uninstaller.sh
executable file
·119 lines (103 loc) · 3.39 KB
/
uninstaller.sh
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
#!/usr/bin/env sh
# Makes the script exit immediately if any command returns a non-zero exit status.
set -e
# Function to display information about the script
display_info() {
echo "⚠️ Welcome to the create-poetry-app Uninstaller!"
echo
echo "This script will guide you through the uninstallation process of create-poetry-app."
echo "Here's what will happen:"
echo
echo "1. ❓ Confirming if you want to uninstall create-poetry-app."
echo "2. 🗑️ Removing the create-poetry-app installation directory."
echo "3. 🔗 Removing the symbolic link."
echo "4. 🔧 Removing create-poetry-app from your PATH in your shell configuration file."
echo
echo "Let's proceed with the uninstallation. ⚠️"
echo
}
# Function to display error messages
fmt_error() {
printf "\033[31m%s\033[0m\n" "$*" >&2
}
# Function to confirm uninstallation
confirm_uninstallation() {
read -r -p "Are you sure you want to remove create-poetry-app? [y/N] " confirmation
if [ "$confirmation" != y ] && [ "$confirmation" != Y ]; then
echo "Uninstall cancelled."
exit
fi
}
# Function to remove installation directory
remove_installation_directory() {
if [ -d "$HOME/.create-poetry-app" ]; then
echo "Removing $HOME/.create-poetry-app..."
rm -rf "$HOME/.create-poetry-app"
echo "Installation directory removed."
else
echo "$HOME/.create-poetry-app does not exist. Skipping."
fi
}
# Function to remove symbolic link
remove_symbolic_link() {
if [ -L /usr/local/bin/create-poetry-app ]; then
echo "Removing /usr/local/bin/create-poetry-app..."
sudo rm -f /usr/local/bin/create-poetry-app
echo "Symbolic link removed."
else
echo "/usr/local/bin/create-poetry-app does not exist. Skipping."
fi
}
# Function to determine the user's shell and shell configuration file
determine_shell_config() {
SHELL_NAME=$(basename "$SHELL")
case "$SHELL_NAME" in
bash)
SHELL_CONFIG="$HOME/.bashrc"
;;
zsh)
SHELL_CONFIG="$HOME/.zshrc"
;;
*)
fmt_error "Unsupported shell: $SHELL_NAME. Please manually remove the create-poetry-app path from your PATH."
exit 1
;;
esac
}
# Function to remove the create-poetry-app PATH modification from the shell configuration file
remove_path_modification() {
if [ -f "$SHELL_CONFIG" ]; then
echo "Removing create-poetry-app from your PATH in $SHELL_CONFIG..."
sed -i.bak "\|export PATH=\"$HOME/.create-poetry-app:\$PATH\"|d" "$SHELL_CONFIG"
echo "PATH modification removed."
echo "A backup of your original shell configuration file has been created: $SHELL_CONFIG.bak"
# Reload shell configuration
if [ -n "$BASH_SOURCE" ]; then
source "$SHELL_CONFIG"
else
. "$SHELL_CONFIG"
fi
else
fmt_error "$SHELL_CONFIG not found. Please manually remove the create-poetry-app path from your PATH."
fi
}
# Main function to uninstall create-poetry-app
main() {
# Display information
display_info
# Confirm uninstallation
confirm_uninstallation
# Remove installation directory
remove_installation_directory
# Remove symbolic link
remove_symbolic_link
# Determine the shell and configuration file
determine_shell_config
# Remove PATH modification
remove_path_modification
# Confirm uninstallation
echo "Thanks for trying out create-poetry-app. It's been uninstalled. 🚮"
echo "Don't forget to restart your terminal! 🖥️"
}
# Run the main function
main