Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 1 Feb 2005 15:19:36 +0100
From:      "David J. Weller-Fahy" <dave-lists-freebsd-questions@weller-fahy.com>
To:        freebsd-questions@freebsd.org
Subject:   Re: Cleaning Out Ports?
Message-ID:  <20050201141914.GC87827@weller-fahy.com>
In-Reply-To: <20050201072415.GB87827@weller-fahy.com>
References:  <200502010132.j111WhkT007090@smtp3.server.rpi.edu> <20050201072415.GB87827@weller-fahy.com>

next in thread | previous in thread | raw e-mail | index | archive | help

--V88s5gaDVPzZ0KCq
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

* David J. Weller-Fahy <dave-lists-freebsd-questions@weller-fahy.com> [2005-02-01 08:24 +0100]:
> * Matt LaPlante <laplante@cat.rpi.edu> [2005-02-01 02:36 +0100]:
> Attached is my script, and my conf file.

Unfortunately, my script got stripped.  Here's the script with a txt
extension.

Regards,
-- 
dave [ please don't CC me ]

--V88s5gaDVPzZ0KCq
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="rm_leaf.sh.txt"

#!/bin/sh
# $HOME/bin/rm_leaf.sh
set -e

LETC=/usr/local/etc
PBASE=/usr/ports
RMLFCNF=rm_leaf.conf
SCRFILE=remove_leaf_ports.sh

PKGINFO=`cd /var/db/pkg && find . -type d | sed '/^.$/d;s/^\.\///'`
PKGREQB=`cd /var/db/pkg && ls */+REQUIRED_BY | sed 's/\/+REQUIRED_BY//g'`
NOTLIST=`cat $LETC/$RMLFCNF`

# remove any packages that are required by any other packages
for PKG in $PKGREQB ; do [ -s /var/db/pkg/$PKG/+REQUIRED_BY ] && \
	PKGINFO=`echo $PKGINFO | sed "s/$PKG//"` ; done

# remove any packages that are in the users list of 'to keep' packages
for PKG in $NOTLIST ; do PKGINFO=`echo $PKGINFO | sed "s/$PKG[^ ]*//"` ; done

# if there's nothing left in PKGINFO, exit now
[ -z "$PKGINFO" ] && echo "No packages/ports to remove." && exit

rm -f $SCRFILE # remove the script file (just in case)

# match up packages to origin in the ports tree
for PKG in $PKGINFO ; do RMLIST="${RMLIST:-} $PKG:$PBASE/`pkg_info -o $( echo $PKG ) | sed -n '/^Origin:$/{n;p;}'`" ; done

cat > $SCRFILE << EOFA
#!/bin/sh
# script to remove all leaf packages not listed in /usr/local/etc/rm_leaf.list
set -e

EOFA

# create script to remove all selected packages
for PKG in $RMLIST ; do
	PNAME=`echo $PKG | sed 's/:.*$//'`
	PPATH=`echo $PKG | sed 's/^[^:]*://'`
	cat >> $SCRFILE <<-EOFB
	echo "Removing $PNAME in $PPATH:"
	cd $PPATH
	make deinstall clean distclean
	echo "Success!" ; echo ; echo
	EOFB
done

[ -n "${1:-}" ] && cat $SCRFILE && rm $SCRFILE

--V88s5gaDVPzZ0KCq--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050201141914.GC87827>