I have a complicated script that I intend to put in the pkg_rr package but haven't. It deletes binary packages which are both old and not currently installed, among other things. #!/bin/sh # $Id: _update-pkgsrc,v 1.14 2008/05/20 17:45:54 gdt Exp $ # Do automatic periodic maintenance in pkgsrc. Typically followed # by pkg_rolling-replace. # Copyright 2007 Gregory D. Troxel. # Copyright 2008 BBN Technologies. # Permission to copy granted under 3-clause BSD license. # This script expects to be invoked as a user, and uses sudo. # Consider invoking as root and a reverse su for cvs. For now, do the # sudo tasks early if possible. # XXX This script assumes that it is operating in /usr/pkgsrc. It # should be extended to work with the current directory, checking that # it is a pkgsrc directory. if [ "$1" = "noupdate" ]; then noupdate=t fi # XXX Substitute this at build time. MAKE=make if [ `uname` = "Darwin" ]; then MAKE=bmake fi # Get new vulnerability data. sudo download-vulnerability-list # Ensure that we have binary packages for all installed packages. mkdir -p /usr/pkgsrc/packages/All rm -f PKG.missing (cd /var/db/pkg && ls) \ | while read d; do if [ -d /var/db/pkg/"$d" ]; then if [ ! -f /usr/pkgsrc/packages/All/"$d".tgz ]; then echo $d >> PKG.missing sudo pkg_tarup -d /usr/pkgsrc/packages/All $d fi fi done # List working directories (for manual cleanup). rm -f PKG.WORK ls -d */*/work > PKG.WORK if [ ! -s PKG.WORK ]; then rm PKG.WORK fi # Update sources rm -f PKG.UPDATE if [ "$noupdate" = "" ]; then cvs -q up -d -P > PKG.UPDATE 2>&1 else echo "NOUPDATE" > PKG.UPDATE fi # Check for vulnerable packages. rm -f PKG.AUDIT; audit-packages | sort > PKG.AUDIT # Check for mismatched packages rm -f PKG.MISMATCH; pkg_chk -uq | sort > PKG.MISMATCH # Make a list of packages not required by anything else. rm -f PKG.automatic-required PKG.automatic-notrequired \ PKG.manual-required PKG.manual-notrequired for d in `cd /var/db/pkg && ls`; do D=/var/db/pkg/$d DREQ=$D/+REQUIRED_BY DINS=$D/+INSTALLED_INFO REQ=notrequired AUTO=manual if [ ! -d $D ]; then continue; fi if [ -s $DREQ ]; then REQ=required fi if [ -f $DINS ] && egrep 'automatic=(yes|YES)' $DINS > /dev/null; then AUTO=automatic fi echo $d >> PKG.$AUTO-$REQ done # Remove distfiles that are out of date. lintpkgsrc -mor # Ensure that we have sources for all packages that are installed, # plus all packages requested. pkg_chk -g cat pkgchk.conf pkgchk-manual.conf | egrep -v \# | while read pkg; do echo $pkg (cd $pkg && $MAKE fetch) done # Make list of out-dated binary packages, separated by whether they # are installed or not. rm -f PKG.old-installed PKG.old-notinstalled lintpkgsrc -p | egrep -v '^(Cannot extract|Bogus:)' | egrep . | while read p; do pbase=`basename $p .tgz` installed=notinstalled if [ -d /var/db/pkg/$pbase ]; then installed=installed fi echo "$p" >> PKG.old-$installed done # Delete binary packages that are old and not installed. # This must be done after the cvs update, and thus will probably not # be able to ride the sudo timer. if [ -f PKG.old-notinstalled ]; then cat PKG.old-notinstalled | sudo xargs rm -f && \ rm PKG.old-notinstalled fi
Attachment:
pgpAFNlfG6Byv.pgp
Description: PGP signature