-
Notifications
You must be signed in to change notification settings - Fork 3
/
uninstall-synology-homebrew.sh
executable file
·93 lines (73 loc) · 2.68 KB
/
uninstall-synology-homebrew.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
#!/bin/bash
source ./functions.sh
func_initialize_env_vars
# Set Trap for EXIT to Handle Normal Cleanup
trap 'code=$?; func_cleanup_exit $code' EXIT
# Set Trap for Interruption Signals to Handle Cleanup
trap 'func_cleanup_exit 130' INT TERM HUP QUIT ABRT ALRM PIPE
# Setup sudoers file
func_sudoers
# Ensure sudo credentials are cached
sudo -v || { echo "Failed to cache sudo credentials"; exit 1; }
read -rp "This will uninstall homebrew and remove all its folders. Do you want to continue? (yes/no): " response
[[ $DARWIN == 0 ]] && sudo chmod 775 /home /home/linuxbrew
# Convert the response to lowercase and trim leading/trailing whitespace
response=$(echo "$response" | tr '[:upper:]' '[:lower:]' | xargs)
# Check the response
if [[ $response == "yes" || $response == "y" ]]; then
echo "Uninstalling Homebrew..."
elif [[ $response == "no" || $response == "n" ]]; then
exit 0
else
echo "Invalid response. Please enter 'yes' or 'no'."
exit 1
fi
DEL_NVIM=0
read -rp "Do you also want to remove kickstart.nvim config and cached files? (yes/no): " response
# Convert the response to lowercase and trim leading/trailing whitespace
response=$(echo "$response" | tr '[:upper:]' '[:lower:]' | xargs)
# Check the response
if [[ $response == "yes" || $response == "y" ]]; then
DEL_NVIM=1
elif [[ $response == "no" || $response == "n" ]]; then
DEL_NVIM=0
echo "Skipping removal of nvim"
else
echo "Invalid response. Please enter 'yes' or 'no'."
exit 1
fi
if [[ $DEL_NVIM == 1 ]]; then
rm -rf ~/.config/nvim-kickstart
rm -rf ~/.cache/nvim-kickstart
rm -rf ~/.local/share/nvim-kickstart
rm -rf ~/.local/state/nvim-kickstart
fi
NONINTERACTIVE=1 sudo /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"
# Restore default profile
if [[ $DARWIN == 0 ]] ; then
sudo cp /etc.defaults/profile "$HOME/.profile"
sudo rm -rf /usr/bin/ldd /etc/ld.so.conf /etc/os-release
[ -L /usr/bin/perl ] && [[ $(readlink /usr/bin/perl) =~ .linuxbrew ]] && sudo rm -rf /usr/bin/perl
[ -L /bin/zsh ] && [[ $(readlink /bin/zsh) =~ .linuxbrew ]] && sudo rm -rf /bin/zsh
sudo rm -rf /home/linuxbrew
sudo umount -l /home
sudo rmdir /home # !!! THE rmdir COMMAND ONLY REMOVES IF EMPTY SO USE IT !!!
fi
[[ $DARWIN == 1 ]] && sudo rm ~/.zprofile > /dev/null 2>&1
rm -rf ~/.cache/Homebrew
rm -rf ~/.cache/p10k*
rm -rf ~/.oh-my-zsh
rm -rf ~/.p10k.zsh
rm -rf ~/.zshrc
sudo rm -rf ~/perl5 ~/.cpan ~/.npm
func_cleanup_exit
echo "Uninstall complete. Returning to the default shell.."
if [[ $DARWIN == 0 ]] ; then
source "$HOME/.profile"
exec /bin/ash --login
fi
if [[ $DARWIN == 1 ]] ; then
sudo rm ~/.zshrc ~/.zprofile > /dev/null 2>&1
source /etc/profile
/bin/zsh --login
fi