-
Notifications
You must be signed in to change notification settings - Fork 5
/
uninstall
executable file
·80 lines (62 loc) · 1.46 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
#!/usr/bin/env bash
print_in_color() {
local color="$1"
shift
if [[ -z ${NO_COLOR+x} ]]; then
printf "$color%b\e[0m\n" "$*"
else
printf "%b\n" "$*"
fi
}
red() { print_in_color "\e[31m" "$*"; }
green() { print_in_color "\e[32m" "$*"; }
green_bold() { print_in_color "\e[1;32m" "$*"; }
blue() { print_in_color "\e[34m" "$*"; }
section() {
printf "\n=== %s\n" "$(green_bold "$@")"
}
command_exist() {
[[ -x "$(command -v "$1")" ]]
}
rm_executable() {
if [[ -z "$1" ]]; then return; fi
printf "%s %s\n" "$(blue rm)" "$1"
$sudo rm -f "/usr/local/bin/$1"
if command_exist "$1"; then
fail "Command $1 still exists"
fi
}
rm_man() {
if [[ ! -d "/usr/local/share/man/man1/" ]]; then return; fi
if [[ -z "$1" ]]; then return; fi
printf "%s %s\n" "$(blue rm)" "/usr/local/share/man/man1/$1*.1"
$sudo rm -f /usr/local/share/man/man1/"$1"*.1
printf "%s %s\n" "$(blue rm)" "/usr/local/share/man/man5/$1*.5"
$sudo rm -f /usr/local/share/man/man5/"$1"*.5
if command_exist makewhatis; then
$sudo makewhatis /usr/local/man
fi
}
onerror() {
local exit_status=$?
printf "\n=== %s\n" "$(red "Aborted with exit status $exit_status")"
exit $exit_status
}
fail() {
printf "$(red 'ERR') %s\n" "$*"
return 1
}
initialize() {
set -e
trap 'onerror' ERR
# Figure out if we need sudo or not
sudo=''
if [[ $EUID -ne 0 ]]; then
sudo='sudo'
fi
}
initialize
section "Removing files"
rm_executable 'alf'
rm_man 'alf'
section "Done"