From a88f7c13cd0616712cf6995d96bc05c5c3f82bdb Mon Sep 17 00:00:00 2001 From: adrianp Date: Sun, 4 Jan 2009 00:44:38 +0000 Subject: This is a simple script that will synchronise the content of your ${DISTDIR} directory with currently installed packages. This script will delete any ${DISTFILE} in ${DISTDIR} that does not currently have an installed package as an owner. If you play with packages a fair bit and download some just to have a play with and delete the package later your ${DISTDIR} can end up with a lot of orphaned ${DISTFILES}. While lintpkgsrc will help you remove outdated ${DISTFILES} it does not do any corealtion with installed packakges which is the gap this script aims to fill. With "lintpkgsrc -or && pkg_distinst --delete" you can and up with a fairly lean and current ${DISTDIR}. --- pkgtools/pkg_distinst/DESCR | 14 +++ pkgtools/pkg_distinst/MESSAGE | 10 ++ pkgtools/pkg_distinst/Makefile | 35 ++++++ pkgtools/pkg_distinst/PLIST | 2 + pkgtools/pkg_distinst/files/pkg_distinst.pl | 167 ++++++++++++++++++++++++++++ 5 files changed, 228 insertions(+) create mode 100644 pkgtools/pkg_distinst/DESCR create mode 100644 pkgtools/pkg_distinst/MESSAGE create mode 100644 pkgtools/pkg_distinst/Makefile create mode 100644 pkgtools/pkg_distinst/PLIST create mode 100644 pkgtools/pkg_distinst/files/pkg_distinst.pl diff --git a/pkgtools/pkg_distinst/DESCR b/pkgtools/pkg_distinst/DESCR new file mode 100644 index 00000000000..d4b24981786 --- /dev/null +++ b/pkgtools/pkg_distinst/DESCR @@ -0,0 +1,14 @@ +This is a simple script that will synchronise the content of your ${DISTDIR} +directory with currently installed packages. + +This script will delete any ${DISTFILE} in ${DISTDIR} that does not currently +have an installed package as an owner. + +If you play with packages a fair bit and download some just to have a play with +and delete the package later your ${DISTDIR} can end up with a lot of orphaned +${DISTFILES}. While lintpkgsrc will help you remove outdated ${DISTFILES} it +does not do any corealtion with installed packakges which is the gap this +script aims to fill. + +With "lintpkgsrc -or && pkg_distinst --delete" you can and up with a fairly +lean and current ${DISTDIR}. diff --git a/pkgtools/pkg_distinst/MESSAGE b/pkgtools/pkg_distinst/MESSAGE new file mode 100644 index 00000000000..b361e8067d9 --- /dev/null +++ b/pkgtools/pkg_distinst/MESSAGE @@ -0,0 +1,10 @@ +=========================================================================== +$NetBSD: MESSAGE,v 1.1.1.1 2009/01/04 00:44:38 adrianp Exp $ + +WARNING: +This script will quite hapily delete *any* file in ${DISTDIR} +(or --distdir) that does not belong to an installed package. The only +exception to this is that it tries to avoid deleting some CVS files. +Please be sure that you are not storing anything else in ${DISTDIR} +(or --distdir) that you may want to keep. +=========================================================================== diff --git a/pkgtools/pkg_distinst/Makefile b/pkgtools/pkg_distinst/Makefile new file mode 100644 index 00000000000..5d83e6f6920 --- /dev/null +++ b/pkgtools/pkg_distinst/Makefile @@ -0,0 +1,35 @@ +# $NetBSD: Makefile,v 1.1.1.1 2009/01/04 00:44:38 adrianp Exp $ + +DISTNAME= pkg_distinst-0.01 +CATEGORIES= pkgtools +MASTER_SITES= # empty +DISTFILES= # empty + +MAINTAINER= adrianp@NetBSD.org +COMMENT= Remove any distfiles not belonging to an installed package + +PKG_DESTDIR_SUPPORT= user-destdir + +WRKSRC= ${WRKDIR} +USE_TOOLS+= perl:run +NO_CHECKSUM= yes +NO_BUILD= yes +USE_LANGUAGES= # none +AUTO_MKDIRS= yes + +SUBST_CLASSES+= di +SUBST_STAGE.di= do-configure +SUBST_FILES.di= pkg_distinst.pl +SUBST_SED.di= -e 's,@PERL5@,${PERL5},g' +SUBST_SED.di+= -e 's,@PKGSRCDIR@,${PKGSRCDIR},g' +SUBST_SED.di+= -e 's,@MAKE@,${MAKE},g' +SUBST_MESSAGE.di= Fixing script for installation. + +do-extract: + cd ${FILESDIR} && cp pkg_distinst.pl ${WRKSRC}/ + +do-install: + ${INSTALL_SCRIPT} ${WRKSRC}/pkg_distinst.pl \ + ${DESTDIR}${PREFIX}/bin/pkg_distinst + +.include "../../mk/bsd.pkg.mk" diff --git a/pkgtools/pkg_distinst/PLIST b/pkgtools/pkg_distinst/PLIST new file mode 100644 index 00000000000..ac74cac48f8 --- /dev/null +++ b/pkgtools/pkg_distinst/PLIST @@ -0,0 +1,2 @@ +@comment $NetBSD: PLIST,v 1.1.1.1 2009/01/04 00:44:38 adrianp Exp $ +bin/pkg_distinst diff --git a/pkgtools/pkg_distinst/files/pkg_distinst.pl b/pkgtools/pkg_distinst/files/pkg_distinst.pl new file mode 100644 index 00000000000..ebaf08c4a08 --- /dev/null +++ b/pkgtools/pkg_distinst/files/pkg_distinst.pl @@ -0,0 +1,167 @@ +#!@PERL5@ -w + +# $NetBSD: pkg_distinst.pl,v 1.1.1.1 2009/01/04 00:44:38 adrianp Exp $ + +use Data::Dumper; +use File::Basename; +use File::Find; +use Getopt::Long; +use strict; + +my ($pkg_info, $pkgsrc, @pkg, @installed, $ipkg, $loc, @distfiles, $line); +my (@pdistfiles, %dupe, $distdir, @downloaded, $dl, @dltmp, $dir, $file); +my (@orphan, $found, $delete, $help); + +# set some defaults +# +$pkgsrc = ""; +$distdir = ""; +$delete = 0; +$found = 0; +$help = 0; + +GetOptions ( 'pkgsrc=s' => \$pkgsrc, + 'distdir=s' => \$distdir, + 'delete' => \$delete, + 'help' => \$help, + ); + +if ($help == 1) { + help(); + exit 0; +} + +# check everything we need exists +# +if ($pkgsrc eq "") { + $pkgsrc = "@PKGSRCDIR@"; +} + +if (! -d "$pkgsrc/pkgtools/pkglint") { + print "ERROR: Unable to find $pkgsrc: $!\n"; + exit 1; +} + +chdir("$pkgsrc/pkgtools/pkglint"); +$pkg_info = `@MAKE@ show-var VARNAME=PKG_INFO_CMD`; +chomp($pkg_info); + +if ($distdir eq "") { + $distdir = `@MAKE@ show-var VARNAME=DISTDIR`; + chomp($distdir); +} + +if (! -d "$distdir") { + print "ERROR: Unable to find $distdir: $!\n"; + exit 1; +} + +# get a list of installed packages +# +open(PKG_INFO, "$pkg_info|"); + +while() { + $line = $_; + @pkg = split / /, $line; + push(@installed, $pkg[0]); +} + +close(PKG_INFO); + +# get a list of distfiles for the installed packages +# +print "Gathering DISTFILES for installed packages"; + +foreach $ipkg (@installed) { + + $loc = `$pkg_info -Q PKGPATH $ipkg`; + chomp($loc); + + if (! -d "$pkgsrc/$loc") { + print "WARNING: Unable to find package $loc: $!\n"; + } else { + chdir("$pkgsrc/$loc"); + + $line = `@MAKE@ show-var VARNAME=DISTFILES`; + chomp($line); + + if ($line ne "") { + @pdistfiles = split / /, $line; + push(@distfiles, @pdistfiles); + } + + print "."; + } +} + +print "done\n"; + +# remove duplicates +# +%dupe = map { $_, 1 } @distfiles; +@distfiles = keys %dupe; + +# get a list of downloaded DISTFILES in DISTDIR +# +find(\&dfile, $distdir); + +# trim .cvsignore and CVS/* +# +foreach $dl (@downloaded) { + $dir = dirname($dl); + $file = basename($dir); + if (-f $dl && $dl ne "$distdir/.cvsignore" && $file ne "CVS") { + push(@dltmp, $dl); + } +} + +@downloaded = @dltmp; + +# figure out what belongs and what doesn't +# +foreach $dl (@downloaded) { + $file = basename($dl); + + foreach my $ipkg (@distfiles) { + if ($file eq $ipkg) { + $found = 1; + last; + } + } + + if ($found == 0) { + push(@orphan, $dl); + } else { + $found = 0; + } +} + +# Print the list of orphaned files +# +foreach $file (@orphan) { + print "$file\n"; + if ($delete == 1) { + unlink($file); + } +} + +exit 0; + +# +# subs follow +# + +sub dfile { + push(@downloaded, $File::Find::name); +} + +sub help { + print "pkg_distinst [--pkgsrc | --distdir | --delete | --help]\n"; + print "\t --pkgsrc : Specify a pkgsrc directory to use.\n"; + print "\t\t This will default to \${PKGSRCDIR}\n"; + print "\t --distdir : Specify a distfiles directory to use.\n"; + print "\t\t This will default to \${DISTDIR}\n"; + print "\t --delete: Delete any orphaned files found.\n"; + print "\t\t Default is to display the list of files.\n"; + print "\t --help: You\'re looking at it\n"; +} -- cgit v1.2.3