pkgsrc-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[pkgsrc/trunk]: pkgsrc/pkgtools/pkg_distinst This is a simple script that wil...
details: https://anonhg.NetBSD.org/pkgsrc/rev/43c8bdfbc790
branches: trunk
changeset: 552420:43c8bdfbc790
user: adrianp <adrianp%pkgsrc.org@localhost>
date: Sun Jan 04 00:44:38 2009 +0000
description:
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}.
diffstat:
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(+), 0 deletions(-)
diffs (248 lines):
diff -r 421fae647ab0 -r 43c8bdfbc790 pkgtools/pkg_distinst/DESCR
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pkgtools/pkg_distinst/DESCR Sun Jan 04 00:44:38 2009 +0000
@@ -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 -r 421fae647ab0 -r 43c8bdfbc790 pkgtools/pkg_distinst/MESSAGE
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pkgtools/pkg_distinst/MESSAGE Sun Jan 04 00:44:38 2009 +0000
@@ -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 -r 421fae647ab0 -r 43c8bdfbc790 pkgtools/pkg_distinst/Makefile
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pkgtools/pkg_distinst/Makefile Sun Jan 04 00:44:38 2009 +0000
@@ -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@localhost
+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 -r 421fae647ab0 -r 43c8bdfbc790 pkgtools/pkg_distinst/PLIST
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pkgtools/pkg_distinst/PLIST Sun Jan 04 00:44:38 2009 +0000
@@ -0,0 +1,2 @@
+@comment $NetBSD: PLIST,v 1.1.1.1 2009/01/04 00:44:38 adrianp Exp $
+bin/pkg_distinst
diff -r 421fae647ab0 -r 43c8bdfbc790 pkgtools/pkg_distinst/files/pkg_distinst.pl
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pkgtools/pkg_distinst/files/pkg_distinst.pl Sun Jan 04 00:44:38 2009 +0000
@@ -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(<PKG_INFO>) {
+ $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 <pkgsrc dir> | --distdir <distfiles dir> | --delete | --help]\n";
+ print "\t --pkgsrc <pkgsrc dir>: Specify a pkgsrc directory to use.\n";
+ print "\t\t This will default to \${PKGSRCDIR}\n";
+ print "\t --distdir <distfiles dir>: 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";
+}
Home |
Main Index |
Thread Index |
Old Index