#!/bin/sh # Original... # 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 - 2014 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 [ $(id -u) -eq 0 ]; then echo 1>&2 "It is too hazardous to delete packages with root" echo 1>&2 "Aborting" exit 1 fi pkg=$1 usage() { cat</dev/null \; # check for anything in /usr/lib/deprecated find /usr/lib/deprecated \( -user ${pkg} -o -group ${pkg} \) \ -exec echo rm -vf {} 2>/dev/null \; check_suid if [ $HAVE_SUID -eq 1 ]; then echo ******************** S U I D *********************** echo Detected setuid files that must be dealt with before echo this package can be safely removed. echo echo See: /tmp/${pkg}.suid echo ******************** S U I D *********************** fi echo echo Use: \`uninstall_package ${pkg} now\' to really remove this package. echo Any errors will be redirected to /tmp/${pkg}.err } run() { # Check for suid check_suid if [ $HAVE_SUID -eq 1 ]; then echo 1>&2 ******************** S U I D *********************** echo 1>&2 Detected setuid files that must be dealt with before echo 1>&2 this package can be safely removed. echo 1>&2 echo 1>&2 See: /tmp/${pkg}.suid echo 1>&2 ******************** S U I D *********************** exit 2 fi # Delete anything that isn't a directory forall_direntries_from ${pkg} \ -not -type d -exec rm -vf {} 2>>/tmp/${pkg}.err \; # Delete any deprecated libs find /usr/lib/deprecated \( -user ${pkg} -o -group ${pkg} \) -delete # Remove any empty directories, but ONLY empty directories dirlist=$(mktemp --tmpdir dirs.XXXXXXXX) forall_direntries_from ${pkg} -type d -empty -fprint ${dirlist} while [ -s ${dirlist} ]; do while read dir; do rmdir -v ${dir} 2>>/tmp/${pkg}.err done<${dirlist} forall_direntries_from ${pkg} -type d -empty -fprint ${dirlist} done # Make sure there isn't anything left leftovers=$(forall_direntries_from ${pkg}) if [ -s /tmp/${pkg}.err -a -n "${leftovers}" ]; then echo Errors were reported. Please inspect /tmp/${pkg}.err exit 1 else rm -f /tmp/${pkg}.err ${dirlist} /tmp/${pkg}.suid fi # Bring ~/.project inline with reality echo -n "Updating .project file... " if [ ${pkg} = $(id -un) ]; then sed -i -e 's/\(Last_Updated: \).*$/\1Not Installed/' \ -e 's/\(Version: \).*$/\1Not Installed/' \ -e 's/\(Deps: \).*$/\1Not Installed/' ${HOME}/.project awk '/^CONTENTS:/ { print; exit; } {print}' ${HOME}/.project > \ ${HOME}/.projtmp echo "--------" >> ${HOME}/.projtmp mv ${HOME}/.projtmp ${HOME}/.project else # doing a sub-pkg, just update-pkg-project update-pkg-project $(whoami) fi echo "Done!" # We should be done. echo Package: ${pkg} successfully removed } if [ ${pkg} != $(id -un) -a ${pkg} != $(id -gn) ]; then usage exit 0 fi if [ $# -lt 1 -o "$1" = "--help" ]; then usage exit 0 fi if [ "$2" = "now" ]; then IGNORE_READDIR_RACE='-ignore_readdir_race' \ run else dry_run|less fi exit 0