-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuninstall
executable file
·79 lines (68 loc) · 2.03 KB
/
uninstall
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
#!/bin/bash
set -e
if [ -n "$BASH_VERSION" ]; then
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
elif [ -n "$ZSH_VERSION" ]; then
SCRIPT_DIR="${0:a:h}"
else
echo "Unknown shell"
exit 1
fi
BASHRC_DIR="$SCRIPT_DIR"
BASHRC_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
if [[ -f "$BASHRC_DIR/scripts/src/10_basics.sh" ]]; then
source "$BASHRC_DIR/scripts/src/10_basics.sh"
else
echo "Could not find bashrc repo"
exit 1
fi
function get_file_owner {
ls -ld "$1" | awk 'NR==1 {print $3}'
}
function clean_source_line {
if [[ -f "$1" ]]; then
if [[ "$(get_file_owner "$1")" == "root" ]]; then
WITHOUT_BASHRC_EXTENSIONS="$(sudo cat "$1" | grep -v bashrc.extensions)"
echo "$WITHOUT_BASHRC_EXTENSIONS" | sudo tee "$1" > /dev/null
else
WITHOUT_BASHRC_EXTENSIONS="$(cat "$1" | grep -v bashrc.extensions)"
echo "$WITHOUT_BASHRC_EXTENSIONS" > "$1"
fi
fi
}
if [[ "$OS_TYPE" == "Linux" ]] || [[ "$OS_TYPE" == "Mac" ]]; then
if ! sudo echo " "; then
echo "You must be able to become root to uninstall this software"
exit 1
fi
fi
OS_TYPE=`get_os_type`
if [[ "$OS_TYPE" == "Linux" ]] || [[ "$OS_TYPE" == "Mac" ]]; then
clean_source_line /etc/bashrc
clean_source_line /etc/bash.bashrc
clean_source_line /root/.bashrc
if [[ "$OS_TYPE" == "Mac" ]]; then
clean_source_line /private/var/root/.bashrc
fi
fi
clean_source_line "$HOME/.zshrc"
clean_source_line "$HOME/.bashrc"
clean_source_line "$HOME/.bash_profile"
if [[ -d /etc/bashrc.extensions ]]; then
if [[ "$OS_TYPE" == "Linux" ]] || [[ "$OS_TYPE" == "Mac" ]]; then
sudo rm -rf /etc/bashrc.extensions
else
rm -rf /etc/bashrc.extensions
fi
fi
if [[ -d "$HOME/bashrc.extensions" ]]; then
rm -rf "$HOME/bashrc.extensions"
fi
if [[ -f /etc/profile.d/bashrc.extensions.sh ]]; then
if [[ "$OS_TYPE" == "Linux" ]] || [[ "$OS_TYPE" == "Mac" ]]; then
sudo rm -rf /etc/profile.d/bashrc.extensions.sh
else
rm -rf /etc/profile.d/bashrc.extensions.sh
fi
fi
echo "bashrc extensions uninstalled successfully"