3 # Copyright (c) 2004 Matthias S. Benkmann <article AT winterdrache DOT de>
4 # You may do everything with this code except misrepresent its origin.
5 # PROVIDED `AS IS' WITH ABSOLUTELY NO WARRANTY OF ANY KIND!
7 # Copyright (C) 2007 - 2014 Steve Youngs <steve@sxemacs.org>
8 # Originally, all this script did was to echo a command to stdout. It didn't
9 # actually do any deleting. To remove the package you had to kill/yank that
10 # command and then remove the "echo"s in it to get the job done.
12 # Rewritten to eliminate the need for kill/yank and echo removal. The default
13 # is still a dry-run, but now the "wet" run is achieved by adding a 2nd argument
14 # to the command line: `now'. The `dry_run' is piped through less(1) for easier
15 # inspection. And errors are redirected to /tmp/<pkgname>.err during the real
18 if [ $(id -u) -eq 0 ]; then
19 echo 1>&2 "It is too hazardous to delete packages with root"
27 USAGE: uninstall_package [now]
29 Unless you specify "now" as the 1st arg, nothing will actually
39 forall_direntries_from ${pkg} -not -type d -exec echo rm -vf {} 2>/dev/null \;
40 suid=$(forall_direntries_from ${pkg} -not -user ${pkg})
41 if [ -n "${suid}" ]; then
43 echo '# There were setuid binaries found. You _could_ use root'
44 echo '# to delete this package, but you run a very real risk of'
45 echo '# completely FUCKING UP your system. Instead, run this:'
47 echo '# forall_direntries_from ${pkg} -not -user ${pkg}'
49 echo '# and delete those files manually and individually'
53 echo Use: \"uninstall_package now\" to really remove this package.
54 echo Any errors will be redirected to /tmp/${pkg}.err
59 # Delete anything that isn't a directory
60 forall_direntries_from ${pkg} -ignore_readdir_race \
61 -not -type d -exec rm -vf {} 2>>/tmp/${pkg}.err \;
62 # Remove any empty directories, but ONLY empty directories
63 forall_direntries_from ${pkg} -ignore_readdir_race \
64 -type d -empty -exec rmdir -v {} 2>>/tmp/${pkg}.err \;
66 leftovers=$(forall_direntries_from ${pkg})
67 if [ -s /tmp/${pkg}.err -a -n "${leftovers}" ]; then
68 echo Errors were reported. Please inspect /tmp/${pkg}.err
70 # Bring ~/.project inline with reality
71 sed -i -e 's/\(Last_Updated: \).*$/\1Not Installed/' \
72 -e 's/\(Version: \).*$/\1Not Installed/' \
73 -e 's/\(Deps: \).*$/\1Not Installed/' ${HOME}/.project
74 awk '/^CONTENTS:/ { print; exit; } {print}' ${HOME}/.project > ${HOME}/.projtmp
75 echo "--------" >> ${HOME}/.projtmp
76 mv ${HOME}/.projtmp ${HOME}/.project
78 echo Package: ${pkg} successfully removed
85 -h|--help|--usage|help|usage) usage ;;