From owner-freebsd-questions@FreeBSD.ORG Wed Mar 23 22:37:49 2005 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 32F3C16A4DF for ; Wed, 23 Mar 2005 22:37:49 +0000 (GMT) Received: from weller-fahy.com (pD9FFFF96.dip.t-dialin.net [217.255.255.150]) by mx1.FreeBSD.org (Postfix) with ESMTP id CAD0B43D58 for ; Wed, 23 Mar 2005 22:37:47 +0000 (GMT) (envelope-from dave-lists-freebsd-questions@weller-fahy.com) Received: (qmail 80293 invoked by uid 1001); 23 Mar 2005 22:37:45 -0000 Date: Wed, 23 Mar 2005 23:37:45 +0100 From: "David J. Weller-Fahy" To: freebsd-questions@freebsd.org Message-ID: <20050323223723.GC75716@weller-fahy.com> Mail-Followup-To: freebsd-questions@freebsd.org References: <20050323193626.GH7474@weller-fahy.com> <20050323193716.GI7474@weller-fahy.com> <4241EDB9.5000107@toldme.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="MfFXiAuoTsnnDAfZ" Content-Disposition: inline In-Reply-To: <4241EDB9.5000107@toldme.com> X-URL-Me: http://weller-fahy.com X-Accept-Language: en X-Location: Germany, Gangelt, Hof Grootfeld User-Agent: Mutt/1.5.9i Subject: Re: Scripting oddness (sh) X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Mar 2005 22:37:49 -0000 --MfFXiAuoTsnnDAfZ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline * Danny Howard [2005-03-23 23:29 +0100]: > Bonus points if you inline the relevant portion, or at least name your > attachment something like foo.sh. And, as pointed out - apparently that didn't work either. Here's the relevant portion of the script (I'll include only the function that seems to be causing the trouble): #v+ list_not_required_by() { PKGLIST="" for PKG in $@ ; do if [ -s $PKGDB/$PKG/+REQUIRED_BY ] ; then # grab list of packages this package is required by RB_LIST=`cat $PKGDB/$PKG/+REQUIRED_BY` RB_TEMP=$RB_LIST for RB in $RB_LIST ; do for RM_PKG in $@ ; do if [ "$RB" = "$RM_PKG" ] ; then RB_TEMP=`echo $RB_TEMP | sed "s/$RM_PKG[^ ]*//g"` break fi done done [ -z "$RB_TEMP" ] && PKGLIST="$PKGLIST $PKG" else PKGLIST="$PKGLIST $PKG" fi done # true } #v- The line consisting of '# true' seems to be the clincher, as mentioned in the previous email. I'm also attaching the rm_leaf.sh file renamed to foo.txt. Thanks for the hint, Danny. Regards, -- dave [ please don't CC me ] --MfFXiAuoTsnnDAfZ Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="foo.txt" #!/bin/sh # $HOME/bin/remove_leaves.sh set -e set_variables() { LETC="/usr/local/etc" PBASE="/usr/ports" PKGDB="/var/db/pkg" RMLFCNF="rm_leaf.conf" # get a list of packages not to touch NOTLIST=`cat $LETC/$RMLFCNF` # get list of packages from FreeBSD's packages database PKGLIST=`cd $PKGDB && find . -type d | sed '/^.$/d;s/^\.\///'` } cut_keepers() { for PKG in $@ ; do # remove any packages that are in the parameter list PKGLIST=`echo $PKGLIST | sed "s/$PKG[^ ]*//g"` done } list_not_required_by() { # In this function, we need to create a list of all those packages that are: # 1. Not required by any other package # 2. Required by a package that is being removed - this would be easier # using C or something where I could use an array of char[], or # using the database access methods in portmanagers library, but I'm # hashing it out in sh first (then I'll convert). # So, first things first, we'll use the PKGLIST as a starting point. # PKGLIST will be the working list of removable packages (since we # passed as a parameter, we don't need to preserve it). # wipe out PKGLIST, we don't need it PKGLIST="" for PKG in $@ ; do if [ -s $PKGDB/$PKG/+REQUIRED_BY ] ; then # grab list of packages this package is required by RB_LIST=`cat $PKGDB/$PKG/+REQUIRED_BY` RB_TEMP=$RB_LIST for RB in $RB_LIST ; do for RM_PKG in $@ ; do if [ "$RB" = "$RM_PKG" ] ; then RB_TEMP=`echo $RB_TEMP | sed "s/$RM_PKG[^ ]*//g"` break fi done done [ -z "$RB_TEMP" ] && PKGLIST="$PKGLIST $PKG" else PKGLIST="$PKGLIST $PKG" fi done # true } create_rm_list() { # match up packages to origin in the ports tree for PKG in $@ ; do RMLIST="${RMLIST:-} $PKG:$PBASE/`pkg_info -o $( echo $PKG ) | sed -n '/^Origin:$/{n;p;}'`" done } set_variables cut_keepers $NOTLIST list_not_required_by $PKGLIST [ -z "$PKGLIST" ] && echo "No packages/ports to remove." && exit create_rm_list $PKGLIST echo "#!/bin/sh" echo "# script to remove all leaf packages not listed in $LETC/rm_leaf.conf" echo "set -e" ; echo for PKG in $RMLIST ; do PNAME=`echo $PKG | sed 's/:.*$//'` PPATH=`echo $PKG | sed 's/^[^:]*://'` echo "echo \"Removing $PNAME in $PPATH:\"" echo "cd $PPATH" echo "make deinstall clean distclean" echo "echo \"Success!\" ; echo" echo done --MfFXiAuoTsnnDAfZ--