#!/usr/bin/env perl # # oldfiles - show outdated packages and sources for a CRUX system # # by Simone Rota , # Mark Rosenstand # License: GNU GPL v2 # # Requires prt-get by Johannes Winkelmann use warnings; use strict; my %options = %{getoptions(@ARGV)}; my $pkgdir = ""; my $srcdir = ""; my $compress = "gz"; my %wanted; my %keepme; # Cannot specify -p -s together (use no options instead) if ( $options{"-p"} && $options{"-s"} ) { usage(); exit 1; } # Assume both packages and sources if no options specified if ( !$options{"-p"} && !$options{"-s"} ) { $options{"-p"} = 1; $options{"-s"} = 1; } # Read pkgmk.conf open CONFIG, "/etc/pkgmk.conf" or die "Could not open /etc/pkgmk.conf"; while () { $srcdir = $1 if m/^PKGMK_SOURCE_DIR="(.*)"\n/; $pkgdir = $1 if m/^PKGMK_PACKAGE_DIR="(.*)"\n/; $compress = $1 if m/^PKGMK_COMPRESSION_MODE="(.*)"\n/; } close CONFIG; # Check if dirs are specified / exists if ( $options{"-p"} ) { if ($pkgdir eq ""){ print "error: no PKGMK_PACKAGE_DIR specified in /etc/pkgmk.conf\n"; exit 1; } else { if (! -d $pkgdir) { print "error: $pkgdir is not a directory\n"; exit 1; } } } if ( $options{"-s"} ) { if ($srcdir eq ""){ print "error: no PKGMK_PACKAGE_DIR specified in /etc/pkgmk.conf\n"; exit 1; } else { if (! -d $srcdir) { print "error: $srcdir is not a directory\n"; exit 1; } } } # 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"} ) { $wanted{$pkgdir}{"$name\#$version-$release.pkg.tar.$compress"} = 1; } if ( $options{"-s"} ) { open SIGNATURES, "$path/$name/.signature" or next; while () { m/^SHA256\s\((.+)\)\s.+\n/; if ($1 && !($1 =~ "Pkgfile") && !($1 =~ ".footprint")) { $wanted{$srcdir}{$1} = 1; } } close SIGNATURES; } } # 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 = ) { 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 ######################## # Adapted from Martin Opel's prtorphan script sub getoptions { my @args = reverse @_; my %options = (); while (my $argument = pop @args) { if ( $argument eq "-p" ) { $options{"-p"} = 1; } elsif ( $argument eq "-s" ) { $options{"-s"} = 1; } else { usage(); exit 1; } } return \%options; } # Show usage sub usage { print "usage: oldfiles [-p|-s]\n"; }