2 # Copyright (c) 2004 Matthias S. Benkmann <article AT winterdrache DOT de>
3 # You may do everything with this code except misrepresent its origin.
4 # PROVIDED `AS IS' WITH ABSOLUTELY NO WARRANTY OF ANY KIND!
6 # Copyright (c) 2007 Steve Youngs <steve@sxemacs.org>
7 # Originally, all this script did was to echo a command to stdout. It didn't
8 # actually do any deleting. To remove the package you had to kill/yank that
9 # command and then remove the "echo"s in it to get the job done.
11 # Rewritten to eliminate the need for kill/yank and echo removal. The default
12 # is still a dry-run, but now the "wet" run is achieved by adding a 2nd argument
13 # to the command line: `now'. The `dry_run' is piped through less(1) for easier
14 # inspection. And errors are redirected to /tmp/<pkgname>.err during the real
17 if [ $# = 0 -o "$1" = '--help' ]; then
18 echo 1>&2 'USAGE: uninstall_package <package-name> [now]'
20 echo 1>&2 'Unless you specify "now" as the 2nd arg, nothing will actually'
21 echo 1>&2 'be deleted.'
29 forall_direntries_from ${pkg} -type d -exec echo rm -rvf {} 2>/dev/null \;
30 forall_direntries_from ${pkg} -not -type d -exec echo rm -vf {} 2>/dev/null \;
31 suid=$(forall_direntries_from ${pkg} -not -user ${pkg})
32 if [ -n "${suid}" ]; then
34 echo '# There were setuid binaries found. You _could_ use root'
35 echo '# to delete this package, but you run a very real risk of'
36 echo '# completely FUCKING UP your system. Instead, run this:'
38 echo '# forall_direntries_from ${pkg} -not -user ${pkg}'
40 echo '# and delete those files manually and individually'
44 echo User \"${pkg}\", or \"root\" can safely delete this package.
47 echo Use: \"uninstall_package ${pkg} now\" to really remove this package.
48 echo Any errors will be redirected to /tmp/${pkg}.err
53 # We have to do it twice to actually get the job done properly.
54 for (( i=1; i<=2; ++i )); do
55 forall_direntries_from ${pkg} -type d -exec rm -rvf {} 2>>/tmp/${pkg}.err \;
56 forall_direntries_from ${pkg} -not -type d -exec rm -vf {} 2>>/tmp/${pkg}.err \;
59 leftovers=$(forall_direntries_from ${pkg})
60 if [ -s /tmp/${pkg}.err -a -n "${leftovers}" ]; then
61 echo Errors were reported. Please inspect /tmp/${pkg}.err
63 # Bring ~/.project inline with reality
64 sed -i -e 's/\(Last_Updated: \).*$/\1Not Installed/' \
65 -e 's/\(Version: \).*$/\1Not Installed/' ${HOME}/.project
66 awk '/^CONTENTS:/ { print; exit; } {print}' ${HOME}/.project > ${HOME}/.projtmp
67 echo "--------" >> ${HOME}/.projtmp
68 mv ${HOME}/.projtmp ${HOME}/.project
70 echo Package: ${pkg} successfully removed