-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuninstall
executable file
·153 lines (133 loc) · 3.57 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
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
#!/usr/bin/env bash
DOTFILES_PATH="$HOME/.dotfiles"
function main() {
ask_for_sudo
run_modules_uninstall_tasks
uninstall_ansible
uninstall_homebrew
uninstall_xcode_command_line_tools
remove_dotfiles_repo
}
function ask_for_sudo() {
info "Checking for \`sudo\` access (which may request your password)..."
if sudo --validate &> /dev/null; then
# Update `sudo` timestamp until script has finished
# More info: https://gist.github.com/cowboy/3118588
while true; do
sudo --non-interactive true;
sleep 60;
kill -0 "$$" || exit
done 2>/dev/null &
success "Running script using \`sudo\` credentials..."
else
error "Request for \`sudo\` access failed"
exit 1
fi
}
function run_modules_uninstall_tasks() {
info "Executing Ansible uninstall tasks"
/opt/homebrew/bin/ansible-playbook \
-i "$DOTFILES_PATH/inventory" \
"$DOTFILES_PATH/main.yml" \
--extra-vars "command=uninstall" \
--ask-become-pass \
|| exit 1
}
function uninstall_ansible() {
info "Uninstalling Ansible"
if [[ "$(type -P ansible)" ]]; then
if /opt/homebrew/bin/brew uninstall ansible; then
success "Ansible uninstalled successfully"
else
error "Ansible uninstall process failed"
exit 1
fi
else
success "Ansible is not installed"
fi
}
function uninstall_homebrew() {
info "Uninstalling Homebrew"
if [[ "$(type -P brew)" ]]; then
url=https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh
if yes | /bin/bash -c "$(curl -fsSL ${url})"; then
success "Homebrew uninstalled successfully"
else
error "Homebrew uninstall process failed"
exit 1
fi
else
success "Homebrew is not installed"
fi
}
function uninstall_xcode_command_line_tools() {
info "Uninstalling Xcode command line tools"
if [[ -d "$('xcode-select' -print-path 2>/dev/null)" ]]; then
if sudo rm -rf "$('xcode-select' -print-path)"; then
success "Xcode command line tools uninstalled successfully"
else
error "Fail trying to uninstall Xcode command line tools"
exit 1
fi
else
success "Xcode command line tools are not installed"
fi
}
function remove_dotfiles_repo() {
info "Removing dotfiles repository from ${DOTFILES_PATH}"
if [[ -e "$DOTFILES_PATH" ]]; then
if rm -rf "$DOTFILES_PATH"; then
success "Dotfiles repo removed successfully"
else
error "Fail trying to remove ${DOTFILES_PATH}"
exit 1
fi
fi
}
#
# Utilities
#
# Adapted from https://github.com/Sajjadhosn/dotfiles
function colored_echo() {
local color="$1";
local exp="$2";
local arrow="$3";
if ! [[ $color =~ '^[0-9]$' ]] ; then
case $(echo $color | tr '[:upper:]' '[:lower:]') in
black) color=0 ;;
red) color=1 ;;
green) color=2 ;;
yellow) color=3 ;;
blue) color=4 ;;
magenta) color=5 ;;
cyan) color=6 ;;
white|*) color=7 ;; # white or invalid color
esac
fi
tput bold;
tput setaf "$color";
echo "$arrow $exp";
tput sgr0;
}
function info() {
colored_echo blue "$1" "==>"
}
function success() {
colored_echo green "$1" "==>"
}
function error() {
colored_echo red "$1" "==>"
}
main "$@"
unset -f \
colored_echo \
info \
success \
error \
ask_for_sudo \
run_modules_uninstall_tasks \
uninstall_ansible \
uninstall_homebrew \
uninstall_xcode_command_line_tools \
remove_dotfiles_repo \
main