#!/bin/sh # Remove packages and their dependencies # Copyright (c) 2007 by Johannes Winkelmann, jw@smts.ch # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # configuration LOGDIR=/tmp # configuration end VERSION=1.0 APPNAME=$(basename dep-remove) version() { echo "$APPNAME $VERSION, Copyright (c) 2007 "\ "by Johannes Winkelmann" } usage() { echo "Usage: $APPNAME " echo "Export DR_VERBOSE=1 to get more verbose output" } if [ -z "$1" ]; then usage exit 1 fi if [ "$1" = "-h" ]; then version usage exit 0 elif [ "$1" = "-v" ]; then version exit 0 fi prt-get info $1 &> /dev/null if [ ! $? = 0 ]; then echo "Package '$1' not found in ports tree" exit 2 fi dep=$1 log=$LOGDIR/$APPNAME-$$.log echo "Remove log for $APPNAME $1" > $log for r in $(prt-get quickdep $dep|rev); do p=$(echo $r|rev) prt-get isinst $p &> /dev/null if [ $? = 0 ]; then if [ -z "$(prt-get dependent $p)" ]; then echo -n "Remove '$p' (y/N) ? " read -n1 answer if [ "$answer" = "y" ]; then echo "" prt-get remove $p > /dev/null echo "Removed: $p" >> $log else echo "" fi else if [ -n "$DR_VERBOSE" ]; then echo "* keeping $p" fi fi fi done echo "Log available in '$log'"