diff options
author | Simone Rota <sip@crux.nu> | 2006-04-23 14:55:54 +0000 |
---|---|---|
committer | Simone Rota <sip@crux.nu> | 2006-04-23 14:55:54 +0000 |
commit | 278d699fb63ce1fb9b49983a24df9e822dd5cda8 (patch) | |
tree | 7416f06fafd2b815995ecae83995e99644498012 /oldfiles | |
parent | b2ec2a0e4228961c783b012b2b3376bdfa61b1a0 (diff) | |
download | prt-utils-278d699fb63ce1fb9b49983a24df9e822dd5cda8.tar.gz prt-utils-278d699fb63ce1fb9b49983a24df9e822dd5cda8.tar.xz |
merged oldfiles with Mark Rosenstrand's script, added missing manpages, prepare for release
Diffstat (limited to 'oldfiles')
-rwxr-xr-x | oldfiles | 151 |
1 files changed, 46 insertions, 105 deletions
@@ -2,16 +2,20 @@ # # oldfiles - show outdated packages and sources for a CRUX system # -# by Simone Rota <sip@varlock.com> +# by Simone Rota <sip@varlock.com>, +# Mark Rosenstand <mark@borkware.net> # License: GNU GPL v2 # # Requires prt-get by Johannes Winkelmann -#use warnings; +use warnings; use strict; -use File::Basename; my %options = %{getoptions(@ARGV)}; +my $pkgdir = ""; +my $srcdir = ""; +my %wanted; +my %keepme; # Cannot specify -p -s together (use no options instead) if ( $options{"-p"} && $options{"-s"} ) { @@ -25,118 +29,74 @@ if ( !$options{"-p"} && !$options{"-s"} ) { $options{"-s"} = 1; } -my $PKGMK_PACKAGE_DIR = ""; -my $PKGMK_SOURCE_DIR = ""; - # Read pkgmk.conf -open(my $cfgfile, "/etc/pkgmk.conf") or die "Couldn't open /etc/pkgmk.conf"; -while (<$cfgfile>){ - my $line = $_; - chomp($line); - $line =~ /^PKGMK_PACKAGE_DIR="(.*?)"|^PKGMK_SOURCE_DIR="(.*?)"/; - if ($1){ - $PKGMK_PACKAGE_DIR = $1; - } - if ($2){ - $PKGMK_SOURCE_DIR = $2; - } +open CONFIG, "/etc/pkgmk.conf" or die "Could not open /etc/pkgmk.conf"; +while (<CONFIG>) { + $srcdir = $1 if m/^PKGMK_SOURCE_DIR="(.*)"\n/; + $pkgdir = $1 if m/^PKGMK_PACKAGE_DIR="(.*)"\n/; } -close($cfgfile) or die "Could not close /etc/pkgmk.conf"; +close CONFIG; # Check if dirs are specified / exists if ( $options{"-p"} ) { - if ($PKGMK_PACKAGE_DIR eq ""){ + if ($pkgdir eq ""){ print "error: no PKGMK_PACKAGE_DIR specified in /etc/pkgmk.conf\n"; exit 1; } else { - if (! -d $PKGMK_PACKAGE_DIR) { - print "error: $PKGMK_PACKAGE_DIR is not a directory\n"; + if (! -d $pkgdir) { + print "error: $pkgdir is not a directory\n"; exit 1; } } } if ( $options{"-s"} ) { - if ($PKGMK_SOURCE_DIR eq ""){ + if ($srcdir eq ""){ print "error: no PKGMK_PACKAGE_DIR specified in /etc/pkgmk.conf\n"; exit 1; } else { - if (! -d $PKGMK_SOURCE_DIR) { - print "error: $PKGMK_SOURCE_DIR is not a directory\n"; + if (! -d $srcdir) { + print "error: $srcdir is not a directory\n"; exit 1; } } } -# Found / current packages and sources -my @packages; -my @cpackages = (); -my @sources; -my @csources = (); - -# Current / found packages, current / found sources -if ( $options{"-p"} ) { - my $packages = `find $PKGMK_PACKAGE_DIR -maxdepth 1 -type f`; - @packages=split("\n", $packages); -} -if ( $options{"-s"} ) { - my $sources = `find $PKGMK_SOURCE_DIR -maxdepth 1 -type f`; - @sources=split("\n", $sources); -} - -# Get all ports through prt-get -my @ports = `prt-get printf "%n|%v|%r|%p\n"`; - -foreach my $port (@ports) { - my ($name, $version, $release, $path) = split(/\|/, $port); - chop($path); - - # Add current package +# Collect curent sources / packages +foreach (split('\n', `prt-get printf "%p:%n:%v:%r\n"`)) { + my ($path, $name, $version, $release) = split(':', $_, 4); if ( $options{"-p"} ) { - push(@cpackages, "$PKGMK_PACKAGE_DIR/$name#$version-$release.pkg.tar.gz"); + $wanted{$pkgdir}{"$name\#$version-$release.pkg.tar.gz"} = 1; } - - # Add current source(s) if ( $options{"-s"} ) { - # Read Pkgfile - my $pkgfilename = "$path\/$name\/Pkgfile"; - open FILE, "< $pkgfilename" or die "Couldn't open $pkgfilename"; - local $/ = undef; - my $pkgfile = <FILE>; - close FILE; - - # Parse sources from Pkgfile - $pkgfile =~ s/\s{1,}/ /gi; # remove multiple spaces - $pkgfile =~ s/\n//g; # remove newlines - $pkgfile =~ s/\\//g; # remove '\' - $pkgfile =~ /source=\((.*?)\)/; # get source array contents - $pkgfile = $1; # prepare some tea - # Add url(s) - my @psources = split(" ", $pkgfile); - foreach my $url (@psources) { - my @split = glob($url); - foreach my $s (@split) { - $s =~ s/\$name/$name/g; # substitute $name - $s =~ s/\$version/$version/g; # substitute $version - $s =~ s/\$release/$release/g; # substitute $release - push(@csources, "$PKGMK_SOURCE_DIR/".basename($s)); - } + open MD5SUMS, "$path/$name/.md5sum" or next; + while (<MD5SUMS>) { + m/^[a-z0-9]{32}\s\s(\S+)\n/; + $wanted{$srcdir}{$1} = 1; } + close MD5SUMS; } - - -} # foreach my $port - - -# Print outdated packages -if ( $options{"-p"} ) { - printdiff(\@packages,\@cpackages); } -# Print outdated sources -if ( $options{"-s"} ) { - printdiff(\@sources,\@csources); +# Keep user-specified files +if ( -f "/etc/oldfiles.conf") { + my $keep; + open KEEPME, "/etc/oldfiles.conf" or die "Could not open /etc/oldfiles.conf"; + while ($keep = <KEEPME>) { + chomp($keep); + $keepme{$keep} = 1; + } +} +close KEEPME; + +# Display unwanted files +foreach my $dir (keys %wanted) { + opendir DIR, $dir; + foreach (readdir DIR) { + next if ($_ eq '.' or $_ eq '..'); + print "$dir/$_\n" unless ($wanted{$dir}{$_} or $keepme{"$dir/$_"}); + } + closedir DIR; } - ######################## subroutines ######################## @@ -162,22 +122,3 @@ sub getoptions { sub usage { print "usage: oldfiles [-p|-s]\n"; } - -# Print differences between two lists -# (from O'Reilly Perl Cookbook) -sub printdiff { - my ($A,$B) = @_; - my @A = @{$A}; - my @B = @{$B}; - my %seen; # lookup table - my @aonly;# answer - @seen{@B} = (); # build lookup table - - foreach my $item (@A) { - unless ( exists $seen{$item} ) { - push(@aonly, $item); - $seen{$item} = 1; - print "$item\n"; - } - } -} |