-
Notifications
You must be signed in to change notification settings - Fork 0
/
uninstall_git.sh
140 lines (127 loc) · 3.38 KB
/
uninstall_git.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/bin/bash
check_root() {
if [ -n "$TERMUX_VERSION" ]; then
return 0
fi
if [ "$PACKAGE_MANAGER" = "brew" ]; then
return 0
fi
if [ "$(id -u)" != "0" ]; then
echo "Error: This script must be run as root for $PACKAGE_MANAGER operations"
exit 1
fi
}
detect_os_and_package_manager() {
if [ -f /etc/os-release ]; then
. /etc/os-release
OS=$ID
elif type lsb_release &> /dev/null; then
OS=$(lsb_release -si | tr '[:upper:]' '[:lower:]')
elif [ "$(uname -o)" == "Android" ]; then
OS="android"
elif [ "$(uname)" == "Darwin" ]; then
OS="darwin"
elif [ -f /etc/debian_version ]; then
OS="debian"
elif [ -f /etc/fedora-release ]; then
OS="fedora"
elif [ -f /etc/centos-release ]; then
OS="centos"
elif [ -f /etc/arch-release ]; then
OS="arch"
elif [ -f /etc/gentoo-release ]; then
OS="gentoo"
else
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
fi
if [ "$OS" == "ubuntu" ] || [ "$OS" == "debian" ]; then
PACKAGE_MANAGER="apt"
elif [ "$OS" == "fedora" ]; then
PACKAGE_MANAGER="dnf"
elif [ "$OS" == "centos" ]; then
if command -v dnf &> /dev/null; then
PACKAGE_MANAGER="dnf"
else
PACKAGE_MANAGER="yum"
fi
elif [ "$OS" == "arch" ]; then
PACKAGE_MANAGER="pacman"
elif [ "$OS" == "gentoo" ]; then
PACKAGE_MANAGER="emerge"
elif [ "$OS" == "darwin" ]; then
PACKAGE_MANAGER="brew"
elif [ "$OS" == "android" ]; then
PACKAGE_MANAGER="pkg"
else
echo "Unsupported operating system or package manager."
exit 1
fi
echo "Detected OS: $OS"
echo "Using package manager: $PACKAGE_MANAGER"
}
check_git() {
if ! command -v git &> /dev/null; then
echo "Git is not installed on this system."
exit 0
else
echo "Git is installed, current version:"
git --version
fi
}
uninstall_git() {
echo "Uninstalling Git..."
case $PACKAGE_MANAGER in
"apt")
apt-get update
apt-get remove --purge git git-core git-man git-doc -y
apt-get autoremove -y
apt-get autoclean
;;
"dnf")
dnf remove git git-core git-doc -y
dnf clean all
;;
"yum")
yum remove git git-core git-doc -y
yum clean all
;;
"pacman")
pacman -Sy
pacman -Rns git --noconfirm
pacman -Sc --noconfirm
;;
"emerge")
emerge --sync
emerge -C dev-vcs/git
emerge --depclean
;;
"brew")
brew update
brew uninstall git
;;
"pkg")
pkg update
pkg uninstall git -y
pkg clean -y
;;
*)
echo "Unsupported package manager for automatic uninstallation."
exit 1
;;
esac
echo "Git has been uninstalled."
}
main() {
check_sudo
detect_os_and_package_manager
check_git
uninstall_git
if ! command -v git &> /dev/null; then
echo "Verification: Git has been successfully removed."
exit 0
else
echo "Warning: Git might still be installed, please check manually."
exit 1
fi
}
main