#!/bin/sh # # Copyright 1994 Patrick Volkerding, Moorhead, Minnesota USA # All rights reserved. # # Redistribution and use of this script, with or without modification, is # permitted provided that the following conditions are met: # # 1. Redistributions of this script must retain the above copyright # notice, this list of conditions and the following disclaimer. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO # EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # TARGET_DIR=/ TMP=/tmp ADM_DIR=$TARGET_DIR/var/log keep_files() { while read FILE ; do if [ -r "$TARGET_DIR/$FILE" -a ! -d "$TARGET_DIR/$FILE" ]; then echo " --> $FILE was found in another package. Skipping." fi done } keep_links() { while read LINK ; do echo "Duplicate link. Not executing: $LINK" done } delete_files() { while read FILE ; do if [ -r "$TARGET_DIR/$FILE" -a ! -d "$TARGET_DIR/$FILE" ]; then if [ ! "$WARN" = "true" ]; then echo " --> Deleting $FILE" rm -f $TARGET_DIR/$FILE else echo " --> $FILE would be deleted" fi fi done } delete_links() { while read LINK ; do if [ ! "$WARN" = "true" ]; then echo "Unique link. Executing: $LINK" else echo "Unique link. Would execute: $LINK" fi done } # Conversion to 'comm' utility by Mark Wisdom. # is pretty nifty! :^) remove_packages() { for package_name in $* do echo if [ -r $ADM_DIR/packages/$package_name ]; then if [ ! "$WARN" = true ]; then echo "Removing package $package_name..." fi if fgrep "./" $ADM_DIR/packages/$package_name 1> /dev/null 2>&1; then TRIGGER=".\/" else TRIGGER="FILE LIST:" fi if [ ! "$WARN" = true ]; then echo "Removing files:" fi sed -n "/$TRIGGER/,/^$/p" < $ADM_DIR/packages/$package_name | sort -u > $TMP/delete_list # Pat's new-new && improved pre-removal routine. for DIR in $ADM_DIR/removed_packages $ADM_DIR/removed_scripts ; do if [ ! -d $DIR ] ; then mkdir -p $DIR ; chmod 755 $DIR ; fi done if [ "$WARN" = "true" ]; then mv $ADM_DIR/packages/$package_name $TMP/$package_name 1> /dev/null 2>&1 else mv $ADM_DIR/packages/$package_name $ADM_DIR/removed_packages 1> /dev/null 2>&1 fi if [ -r $ADM_DIR/scripts/$package_name ]; then cat $ADM_DIR/scripts/$package_name | fgrep 'rm -rf' | sort -u > $TMP/del_link_list if [ "$WARN" = "true" ]; then mv $ADM_DIR/scripts/$package_name $TMP/$package_name.script else mv $ADM_DIR/scripts/$package_name $ADM_DIR/removed_scripts 1> /dev/null 2>&1 fi cat $ADM_DIR/scripts/* | fgrep 'rm -rf' | sort -u > $TMP/required_links comm -12 $TMP/del_link_list $TMP/required_links | keep_links comm -23 $TMP/del_link_list $TMP/required_links | delete_links comm -23 $TMP/del_link_list $TMP/required_links > $TMP/delscript if [ ! "$WARN" = "true" ]; then ( cd $TARGET_DIR ; sh $TMP/delscript ) fi rm -f $TMP/del_link_list $TMP/required_links $TMP/delscript fi cat $ADM_DIR/packages/* | sort -u > $TMP/required_files comm -12 $TMP/delete_list $TMP/required_files | keep_files comm -23 $TMP/delete_list $TMP/required_files | delete_files rm -f $TMP/delete_list $TMP/required_files if [ "$WARN" = "true" ]; then mv $TMP/$package_name $ADM_DIR/packages/$package_name if [ -r $TMP/$package_name.script ]; then mv $TMP/$package_name.script $ADM_DIR/scripts/$package_name fi fi else echo "No such package: $package_name. Can't remove." fi done } if [ "$1" = "-warn" ]; then echo "Only warning... not actually removing any files." echo "Here's what would be removed (and left behind) if you" echo "removed the package(s):" echo WARN=true shift 1 fi remove_packages $*