#!/bin/sh
+# Original...
# Copyright (c) 2004 Matthias S. Benkmann <article AT winterdrache DOT de>
# 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 <steve@sxemacs.org>
+# Copyright (C) 2007 - 2014 Steve Youngs <steve@sxemacs.org>
# 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.
# inspection. And errors are redirected to /tmp/<pkgname>.err during the real
# uninstall.
-if [ $# = 0 -o "$1" = '--help' ]; then
- echo 1>&2 'USAGE: uninstall_package <package-name> [now]'
- echo
- echo 1>&2 'Unless you specify "now" as the 2nd arg, nothing will actually'
- echo 1>&2 'be deleted.'
- exit 1
+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<<EOF
+USAGE: uninstall_package [now]
+
+Unless you specify "now" as the 1st arg, nothing will actually
+be deleted.
+
+EOF
+}
+
+pkg=$(whoami)
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 '# 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 Use: \"uninstall_package 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
+ # Delete anything that isn't a directory
+ forall_direntries_from ${pkg} \
+ -not -type d -exec rm -vf {} 2>>/tmp/${pkg}.err \;
+ # Remove any empty directories, but ONLY empty directories
+ forall_direntries_from ${pkg} \
+ -type d -empty -exec rmdir -v {} 2>>/tmp/${pkg}.err \;
- leftovers=$(forall_direntries_from ${pkg})
- if [ -s /tmp/${pkg}.err -a -n "${leftovers}" ]; then
- echo Errors were reported. Please inspect /tmp/${pkg}.err
- else
+ 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
+ -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
fi
}
-case $2 in
- now) run ;;
+case $1 in
+ now) IGNORE_READDIR_RACE='-ignore_readdir_race'; run ;;
+ -h|--help|--usage|help|usage) usage ;;
*) dry_run|less ;;
esac