#!/bin/sh # Copyright (c) 2004 Matthias S. Benkmann
# You may do everything with this code except misrepresent its origin. # PROVIDED `AS IS' WITH ABSOLUTELY NO WARRANTY OF ANY KIND! # Copyright (c) 2007 Steve Youngs # Originally, all this script did was to echo a command to stdout. It didn't # actually do any deleting. To remove the package you had to kill/yank that # command and then remove the "echo"s in it to get the job done. # Rewritten to eliminate the need for kill/yank and echo removal. The default # is still a dry-run, but now the "wet" run is achieved by adding a 2nd argument # to the command line: `now'. The `dry_run' is piped through less(1) for easier # inspection. And errors are redirected to /tmp/.err during the real # uninstall. if [ $# = 0 -o "$1" = '--help' ]; then echo 1>&2 'USAGE: uninstall_package [now]' echo echo 1>&2 'Unless you specify "now" as the 2nd arg, nothing will actually' echo 1>&2 'be deleted.' exit 1 fi pkg=$1 dry_run() { forall_direntries_from ${pkg} -type d -exec echo rm -rvf {} 2>/dev/null \; forall_direntries_from ${pkg} -not -type d -exec echo rm -vf {} 2>/dev/null \; suid=$(forall_direntries_from ${pkg} -not -user ${pkg}) if [ -n "${suid}" ]; then echo '###' echo '# There were setuid binaries found. You _could_ use root' echo '# to delete this package, but you run a very real risk of' echo '# completely FUCKING UP your system. Instead, run this:' echo '#' echo '# forall_direntries_from ${pkg} -not -user ${pkg}' echo '#' echo '# and delete those files manually and individually' echo '###' else echo echo User \"${pkg}\", or \"root\" can safely delete this package. fi echo echo Use: \"uninstall_package ${pkg} now\" to really remove this package. echo Any errors will be redirected to /tmp/${pkg}.err } run() { # We have to do it twice to actually get the job done properly. for (( i=1; i<=2; ++i )); do forall_direntries_from ${pkg} -type d -exec rm -rvf {} 2>>/tmp/${pkg}.err \; forall_direntries_from ${pkg} -not -type d -exec rm -vf {} 2>>/tmp/${pkg}.err \; done leftovers=$(forall_direntries_from ${pkg}) if [ -s /tmp/${pkg}.err -a -n "${leftovers}" ]; then echo Errors were reported. Please inspect /tmp/${pkg}.err else # Bring ~/.project inline with reality sed -i -e 's/\(Last_Updated: \).*$/\1Not Installed/' \ -e 's/\(Version: \).*$/\1Not Installed/' ${HOME}/.project awk '/^CONTENTS:/ { print; exit; } {print}' ${HOME}/.project > ${HOME}/.projtmp echo "--------" >> ${HOME}/.projtmp mv ${HOME}/.projtmp ${HOME}/.project # We should be done. echo Package: ${pkg} successfully removed rm -f /tmp/${pkg}.err fi } case $2 in now) run ;; *) dry_run|less ;; esac exit 0