-
Notifications
You must be signed in to change notification settings - Fork 3
/
uninstall
executable file
·104 lines (94 loc) · 2.82 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
#!/bin/sh
# POSIX
verbose=0
# Print usage to stdout.
# Arguments:
# None
# Outputs:
# print usage with examples.
show_help() {
cat <<EOF
uninstall --prefix /usr/local
Options:
--prefix/-P: base bath where all files will be deployed (default /usr/local if root, ~/.local if not)
--help/-h: show this message
-v: show more verbosity
EOF
}
# Parse arguments
while :; do
case $1 in
-h | --help)
# Call a "show_help" function to display a synopsis, then exit.
show_help
exit
;;
-v | --verbose)
shift
verbose=1
;;
-p | --path)
if [ -n "$2" ]; then
dest_path="$2"
shift
shift
fi
;;
-P | --prefix)
if [ -n "$2" ]; then
prefix="$2"
shift
shift
fi
;;
*) # Default case: If no more options then break out of the loop.
break ;;
esac
done
if [ -z "${prefix}" ]; then
prefix="/usr/local"
# in case we're not root, just default to the home directory
if [ "$(id -u)" -ne 0 ]; then
prefix="${HOME}/.local"
fi
fi
dest_path="${prefix}/bin"
template_dest_path="${prefix}/share/blincus/templates"
template_config_dest_path="${HOME}/.config/blincus/templates"
build_dest_path="${prefix}/share/blincus/build"
script_dest_path="${prefix}/share/blincus"
script_config_dest_path="${HOME}/.config/blincus"
man_dest_path="${prefix}/share/man/man1"
completion_dest_path="${prefix}/share/bash-completion/completions/"
dest_path="${prefix}/bin"
init_dest_path="${prefix}/share/blincus/cloud-init"
init_config_dest_path="${HOME}/.config/blincus/cloud-init"
profile_dest_path="${prefix}/share/blincus/profiles"
profile_config_dest_path="${HOME}/.config/blincus/profiles"
packer_dest_path="${prefix}/share/blincus/recipes"
packer_config_dest_path="${HOME}/.config/blincus/recipes"
set -o errexit
set -o nounset
# set verbosity
if [ "${verbose}" -ne 0 ]; then
set -o xtrace
fi
[ ! -w "${dest_path}" ] && printf >&2 "Cannot write into %s, permission denied.\n" "${dest_path}" && exit 1
#[ ! -w "${man_dest_path}" ] && printf >&2 "Cannot write into %s, permission denied.\n" "${man_dest_path}" && exit 1
# uninstall
for file in "${dest_path}/blincus"*; do
[ -e "${file}" ] && rm "${file}"
done
for file in "${man_dest_path}/blincus"*; do
[ -e "${file}" ] && rm "${file}"
done
for file in "${completion_dest_path}/blincus"*; do
[ -e "${file}" ] && rm "${file}"
done
[ -d "${script_dest_path}" ] && rm -rf "${script_dest_path}"
[ -d "${build_dest_path}" ] && rm -rf "${build_dest_path}"
[ -d "${script_config_dest_path}" ] && rm -rf "${script_config_dest_path}"
printf >&2 "\033[1;32m Thank you for using Blincus. Uninstall complete.\n\033[0m"
printf >&2 "\033[0m Removed shell scripts located in \033[1;31m%s\n\033[0m" "${dest_path}"
#printf >&2 "\033[0m Removed manpages located in \033[1;31m%s\n\033[0m" "${man_dest_path}"
printf >&2 "\033[0m Removed configuration directory located in \033[1;31m%s\n\033[0m" "${script_config_dest_path}"