-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuninstall.bash
executable file
·186 lines (160 loc) · 4.77 KB
/
uninstall.bash
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/usr/bin/env bash
# ------------------------------------------------------------------------- #
#*# ###### #
# # # # # ##### ##### ## # #
# # # # # # # # # # # # #
# ###### ##### # # # # # # # # #
# # ####### ##### ##### ###### #
# # # # # # # # # # #
### # # # # # # # # # #
# ------------------------------------------------------------------------- #
#
# Copyright (C) 2005-2018 Mart Frauenlob aka AllKind
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# ------------------------------------------------------------------------- #
#
# IP-ARRAY UNINSTALL SCRIPT
#
# ------------------------------------------------------------------------- #
# ------------------------------------------------------------------------- #
# FUNCTIONS
# ------------------------------------------------------------------------- #
usage() {
printf "
USAGE: ${0##*/} [Option] [...]\n
Options:
-?, -h, --help Show this usage instructions
-n, --no-act Perform a dry-run
-v, --verbose Verbose output
\n"
}
no_act() { # just print the command string
printf "%s\n" "$*"
}
rem_dir() {
${NOACT}command rm $VERBOSE -rf "$1"
}
rem_file() {
${NOACT}command rm $VERBOSE -f "$1"
}
rem_empty_dir() {
# all done in a sub-shell, as we change shell options
(
shopt -s nullglob
shopt -s dotglob
set +f
# Check for empty files using arrays
chk_files=(${1}/*)
if (( ${#chk_files[*]} )); then
if [[ $VERBOSE ]]; then
printf "Directory \`%s' is not empty. Skipping it.\n" "$1"
fi
else
${NOACT}command rmdir $VERBOSE "$1"
fi
)
}
# ------------------------------------------------------------------------- #
# MAIN
# ------------------------------------------------------------------------- #
ME="ip-array"
: ${PATH:=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin}
# parse arguments
unset NOACT VERBOSE
while (($#)); do
case "$1" in
"-?"|-h|--help) usage
exit 0
;;
-n|--no-act) NOACT="no_act "
;;
-v|--verbose) VERBOSE="-v"
;;
*) usage
exit 3
esac
shift
done
# install.bash created ${ME}-install.log, need the declarations from it
. ./${ME}-install.log || {
printf "Cannot find ./${ME}-install.log. Aborting.\n" >&2
exit 1
}
# check if the variable are defined
for f in LIBDIR DATAROOTDIR DOCDIR SYSCONFDIR \
BINDIR DEFAULTSDIR BASHCOMPDIR MANDIR INITDIR
do
if [[ -z ${!f} ]]; then
printf "Need variable \`%s'. Aborting.\n" "$f" >&2
exit 1
fi
done
[[ $SYSTEMDDIR ]] || SYSTEMDDIR="upstart"
# check for needed programs
for f in rm rmdir; do
command -v $f &>/dev/null || {
printf "Unable to find the \`$f' program in \$PATH.\n" >&2
exit 1
}
done
# warn about ownership - if not root
if ((EUID != 0)); then
printf "Warning: Not running as root.\n"
fi
if [[ $NOACT ]]; then
printf "\nNO ACT MODE - NOT UNINSTALLING!\n\n"
else
printf "Starting uninstall\n"
fi
# start deletion
for f in LIBDIR DOCDIR DATAROOTDIR SYSCONFDIR; do
rem_dir "${!f}/$ME"
done
for f in BINDIR DEFAULTSDIR; do
rem_file "${!f}/$ME"
done
rem_file "${INITDIR}/$ME"
rem_file "${INITDIR}/${ME}_pre_net_boot"
if [[ $BASHCOMPDIR = \~ ]]; then
printf "bashcompdir is \`~'.\n\tRemember to manually remove completion from: \`%s'.\n" "~/.bash_completion"
else
rem_file "${BASHCOMPDIR}/$ME"
fi
for f in "${MANDIR}"/man5/${ME}*.5 "${MANDIR}"/man8/${ME}*.8; do
rem_file "$f"
done
for f in 5 8; do
rem_empty_dir "${MANDIR}/man${f}"
done
rem_empty_dir "${MANDIR}"
for f in BINDIR LIBDIR DOCDIR DEFAULTSDIR SYSCONFDIR BASHCOMPDIR INITDIR DATAROOTDIR
do
rem_empty_dir "${!f}"
done
if [[ $SYSTEMDDIR != upstart ]]; then
rem_file "${SYSTEMDDIR}/${ME}.service"
rem_file "${SYSTEMDDIR}/${ME}_pre_net_boot.service"
rem_empty_dir "$SYSTEMDDIR"
printf "Reloading systemd.\n"
if ! [[ $NOACT ]]; then
command systemctl daemon-reload || printf "Failed reloading systemd configuration.\n" >&2
fi
fi
if [[ $PREFIX ]]; then
rem_empty_dir "$PREFIX"
fi
printf "Finished uninstall\n"