prtwash.pl: allow user to toggle the parsing of pkgmk.conf
This commit is contained in:
parent
0485af9be2
commit
3bf8fd6025
|
@ -36,34 +36,28 @@ All items not included in the previous list WILL be deleted
|
||||||
You can choose to delete some of the above by passing the proper
|
You can choose to delete some of the above by passing the proper
|
||||||
option:
|
option:
|
||||||
.TP
|
.TP
|
||||||
.B
|
.B \-p
|
||||||
-p
|
remove the built package (current version)
|
||||||
also remove the built package (current version)
|
|
||||||
.TP
|
.TP
|
||||||
.B
|
.B \-b
|
||||||
-b
|
remove older builds (any package tarball that does NOT match
|
||||||
also remove other built packages (older versions)
|
the current version)
|
||||||
.TP
|
.TP
|
||||||
.B
|
.B \-d
|
||||||
-d
|
remove add-on files provided by CRUX maintainers
|
||||||
also remove the add-on files provided by CRUX maintainers
|
|
||||||
(patches and initscripts downloaded with \fBports -u\fP)
|
(patches and initscripts downloaded with \fBports -u\fP)
|
||||||
.TP
|
.TP
|
||||||
.B
|
.B \-s
|
||||||
-s
|
remove upstream sources (those NOT obtained via \fBports -u\fP)
|
||||||
also remove the upstream sources (those NOT obtained via \fBports -u\fP)
|
|
||||||
.TP
|
.TP
|
||||||
.B
|
.B \-t
|
||||||
-t
|
|
||||||
(test mode) display the target files without deleting
|
(test mode) display the target files without deleting
|
||||||
.TP
|
.TP
|
||||||
.B
|
.B \-q
|
||||||
-q
|
|
||||||
(quiet mode) suppress messages about files that are kept;
|
(quiet mode) suppress messages about files that are kept;
|
||||||
basically the same as \fBprtwash [OPTIONS] | grep -v "keeping"\fP
|
basically the same as \fBprtwash [OPTIONS] | grep -v "keeping"\fP
|
||||||
.TP
|
.TP
|
||||||
.B
|
.B \-a
|
||||||
-a
|
|
||||||
(automatic mode) take the port collections from the
|
(automatic mode) take the port collections from the
|
||||||
/etc/prt-get.conf file and do a recursive cleaning;
|
/etc/prt-get.conf file and do a recursive cleaning;
|
||||||
if omitted, the command line must contain at least one <path> specifying
|
if omitted, the command line must contain at least one <path> specifying
|
||||||
|
@ -71,12 +65,14 @@ a valid port directory
|
||||||
.PP
|
.PP
|
||||||
Misc options
|
Misc options
|
||||||
.TP
|
.TP
|
||||||
.B
|
.B \-\-parse\-pkgmk\-conf
|
||||||
-h
|
Revert to the v0.9 behaviour of parsing /etc/pkgmk.conf to determine the
|
||||||
|
compression mode of built packages
|
||||||
|
.TP
|
||||||
|
.B \-h
|
||||||
Display usage information
|
Display usage information
|
||||||
.TP
|
.TP
|
||||||
.B
|
.B \-v
|
||||||
-v
|
|
||||||
Display version
|
Display version
|
||||||
.SH ENVIRONMENT
|
.SH ENVIRONMENT
|
||||||
In automatic mode, \fBprtwash\fP gets a list of repositories from
|
In automatic mode, \fBprtwash\fP gets a list of repositories from
|
||||||
|
@ -93,11 +89,24 @@ Sources under CRUX version control are only deleted if you pass the
|
||||||
option \fB\-d\fP. Sources from upstream are only deleted if you pass the
|
option \fB\-d\fP. Sources from upstream are only deleted if you pass the
|
||||||
option \fB\-s\fP.
|
option \fB\-s\fP.
|
||||||
.PP
|
.PP
|
||||||
The current version of the package is only deleted if you pass the
|
You can also delete the built package (current version) by passing
|
||||||
option \fB\-p\fP. Older versions of the package are only deleted if you
|
the option \fB\-p\fP. To select only older versions for deletion,
|
||||||
pass the option \fB\-b\fP. Note that if the compression mode defined
|
pass the option \fB\-b\fP instead. These two options operate independently,
|
||||||
in /etc/pkgmk.conf has been changed since you last built the package,
|
allowing you to target four distinct subsets (including the empty set)
|
||||||
\fBprtwash\fP will not recognize the tarball in its regexp search.
|
for deletion.
|
||||||
|
.PP
|
||||||
|
By passing the option \fB\-\-parse\-pkgmk\-conf\fP, you can modify the behaviour
|
||||||
|
of the pattern matching performed to detect built packages. By default, the
|
||||||
|
regexp searches are done with the patterns
|
||||||
|
.B /${name}#${version}.*.pkg.tar.(gz|lz|xz|bz2)/
|
||||||
|
and
|
||||||
|
.B /${name}#.*pkg.tar.(gz|lz|xz|bz2)/
|
||||||
|
using the variables defined in the \fBPkgfile\fP(5). Passing the option
|
||||||
|
.B \-\-parse\-pkgmk\-conf
|
||||||
|
will result in a more narrow regexp search, allowing the deletion of any package
|
||||||
|
tarball that uses a different compression algorithm than the one currently defined
|
||||||
|
in /etc/pkgmk.conf (which is how the v0.9 bash script worked).
|
||||||
|
|
||||||
.SH COMPARISON WITH OTHER UTILITIES
|
.SH COMPARISON WITH OTHER UTILITIES
|
||||||
Because \fBprtwash\fP reads the location of port collections from \fB/etc/prt-get.conf\fP(5),
|
Because \fBprtwash\fP reads the location of port collections from \fB/etc/prt-get.conf\fP(5),
|
||||||
you can easily control which collections are cleaned in automatic mode by commenting
|
you can easily control which collections are cleaned in automatic mode by commenting
|
||||||
|
|
|
@ -18,7 +18,7 @@ our @portdirs;
|
||||||
our $argports;
|
our $argports;
|
||||||
my $version = 1.2.1;
|
my $version = 1.2.1;
|
||||||
our %options = ( oldver=>0, pkgtoo=>0, srctoo=>0, addons=>0,
|
our %options = ( oldver=>0, pkgtoo=>0, srctoo=>0, addons=>0,
|
||||||
dryrun=>0, auto=>0, quiet=>0 );
|
dryrun=>0, auto=>0, quiet=>0, parse_pkgmk=>0 );
|
||||||
|
|
||||||
#################### main routine ################################
|
#################### main routine ################################
|
||||||
parse_args();
|
parse_args();
|
||||||
|
@ -46,9 +46,8 @@ if ($options{auto} == 1) {
|
||||||
|
|
||||||
#################### subroutines #################################
|
#################### subroutines #################################
|
||||||
sub parse_args {
|
sub parse_args {
|
||||||
while ( my $arg = pop(@ARGV) ) {
|
foreach my $arg (@ARGV) {
|
||||||
next if (-f $arg); # no filenames, only directories and options
|
if ($arg eq "-b") {
|
||||||
if ($arg eq "-b") {
|
|
||||||
$options{oldver} = 1;
|
$options{oldver} = 1;
|
||||||
} elsif ($arg eq "-p") {
|
} elsif ($arg eq "-p") {
|
||||||
$options{pkgtoo} = 1;
|
$options{pkgtoo} = 1;
|
||||||
|
@ -62,11 +61,16 @@ sub parse_args {
|
||||||
$options{auto} = 1;
|
$options{auto} = 1;
|
||||||
} elsif ($arg eq "-q") {
|
} elsif ($arg eq "-q") {
|
||||||
$options{quiet} = 1;
|
$options{quiet} = 1;
|
||||||
|
} elsif ($arg eq "--parse-pkgmk-conf") {
|
||||||
|
$options{parse_pkgmk} = 1;
|
||||||
} elsif ($arg eq "-v") {
|
} elsif ($arg eq "-v") {
|
||||||
print "$version\n";
|
print "$version\n";
|
||||||
exit(0);
|
exit(0);
|
||||||
} elsif (-d $arg) {
|
} elsif ((-d $arg) || # false for symlink to a portdir, so a
|
||||||
|
(-f "$arg/Pkgfile")) { # followup test is performed to catch those
|
||||||
push (@portdirs, $arg);
|
push (@portdirs, $arg);
|
||||||
|
} elsif (-f $arg) {
|
||||||
|
print "WARN: ignoring invalid port directory $arg\n";
|
||||||
} else {
|
} else {
|
||||||
print_usage();
|
print_usage();
|
||||||
}
|
}
|
||||||
|
@ -124,7 +128,7 @@ sub parse_pkgfile {
|
||||||
return \$name, \$version, \$release, \@source, \@renames;
|
return \$name, \$version, \$release, \@source, \@renames;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub keeplist { # remember to pop off the last element for regex purposes
|
sub keeplist { # remember to pop off the last two elements for regex purposes
|
||||||
my $port = shift;
|
my $port = shift;
|
||||||
my @keepers = ("Pkgfile",".footprint",".signature");
|
my @keepers = ("Pkgfile",".footprint",".signature");
|
||||||
push (@keepers,"pre-install","post-install","README","README.md",
|
push (@keepers,"pre-install","post-install","README","README.md",
|
||||||
|
@ -140,7 +144,7 @@ sub keeplist { # remember to pop off the last element for regex purposes
|
||||||
my $i; my $si; my $ki;
|
my $i; my $si; my $ki;
|
||||||
ENTRY: for ($i=0; $i<=$#source; $i++) {
|
ENTRY: for ($i=0; $i<=$#source; $i++) {
|
||||||
$si = $source[$i];
|
$si = $source[$i];
|
||||||
$ki = ($renames[$i] eq "SKIP" or $renames[$i] eq "") ? basename($si) :
|
$ki = ("$renames[$i]" eq "SKIP" or "$renames[$i]" eq "") ? basename($si) :
|
||||||
$renames[$i];
|
$renames[$i];
|
||||||
if ($si =~ /^remote:/) {
|
if ($si =~ /^remote:/) {
|
||||||
next ENTRY if ($options{srctoo}==1);
|
next ENTRY if ($options{srctoo}==1);
|
||||||
|
@ -150,21 +154,23 @@ sub keeplist { # remember to pop off the last element for regex purposes
|
||||||
push(@keepers, $ki);
|
push(@keepers, $ki);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
push (@keepers, $name.'#'.$version.'-'.$release.".pkg.tar.$compression_mode") if $options{pkgtoo}==0;
|
push (@keepers, "$name#$version.*\.pkg\.tar\.$compression_mode");
|
||||||
push (@keepers, $name."#.*pkg.tar.$compression_mode");
|
push (@keepers, "$name#.*\.pkg\.tar\.$compression_mode");
|
||||||
return @keepers;
|
return @keepers;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub get_compress {
|
sub get_compress {
|
||||||
my $conf = "/etc/pkgmk.conf";
|
my $suffix = "(gz|lz|xz|bz2)";
|
||||||
$compression_mode = "gz";
|
if ($options{parse_pkgmk} == 1) {
|
||||||
open(CONFIG,$conf) or return $compression_mode;
|
my $conf = "/etc/pkgmk.conf";
|
||||||
while(<CONFIG>) {
|
open(CONFIG,$conf) or return $suffix;
|
||||||
$compression_mode = $1 if m/^[\t ]*PKGMK_COMPRESSION_MODE=(.*)\n/;
|
while(<CONFIG>) {
|
||||||
|
$suffix = $1 if m/^[\t ]*PKGMK_COMPRESSION_MODE=(.*)\n/;
|
||||||
|
}
|
||||||
|
close(CONFIG);
|
||||||
|
$suffix =~ s/"//g; # ensure no double-quotes remain (thanks jaeger)
|
||||||
}
|
}
|
||||||
close(CONFIG);
|
return $suffix;
|
||||||
$compression_mode =~ s/"//g; # ensure no double-quotes remain (thanks jaeger)
|
|
||||||
return $compression_mode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub do_wash {
|
sub do_wash {
|
||||||
|
@ -174,16 +180,18 @@ sub do_wash {
|
||||||
print "WARN: no Pkgfile found in $port. Skipping.\n";
|
print "WARN: no Pkgfile found in $port. Skipping.\n";
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
my @keepers = keeplist($port);
|
my @keepers = keeplist($port); my $iswanted;
|
||||||
my $nevermatch = "ReallyLongStringThatWouldNeverMatchAnyBuiltPackage";
|
my $allbuilds = pop(@keepers);
|
||||||
my $pkgrex = pop(@keepers);
|
my $currbuild = pop(@keepers);
|
||||||
$pkgrex = ($options{oldver} == 1 or $options{pkgtoo} == 1) ? $nevermatch : $pkgrex;
|
|
||||||
|
|
||||||
opendir (DIR,$port) or return;
|
opendir (DIR,$port) or return;
|
||||||
|
print "=====> washing $port\n" unless $options{quiet} == 1;
|
||||||
foreach my $f (sort(readdir(DIR))) {
|
foreach my $f (sort(readdir(DIR))) {
|
||||||
next if ($f eq '.' or $f eq '..');
|
next if ($f eq '.' or $f eq '..');
|
||||||
$f =~ s/\+/\\\+/g; # plus sign in filenames interferes with regex search
|
$f =~ s/\+/\\\+/g; # plus sign in filenames interferes with regex search
|
||||||
if ((grep /$f/, @keepers) or ($f =~ /$pkgrex/)) {
|
$iswanted = ( grep (/$f/, @keepers ) >= 1 );
|
||||||
|
if ($iswanted or ($options{pkgtoo}==0)*($f =~ /$currbuild/)
|
||||||
|
or ($options{oldver}==0)*($f =~ /$allbuilds/)*($f !~ /$currbuild/)) {
|
||||||
print "... keeping file $port/$f.\n" unless $options{quiet} == 1;
|
print "... keeping file $port/$f.\n" unless $options{quiet} == 1;
|
||||||
} else {
|
} else {
|
||||||
remove ("$port/$f");
|
remove ("$port/$f");
|
||||||
|
@ -194,8 +202,7 @@ sub do_wash {
|
||||||
}
|
}
|
||||||
|
|
||||||
sub getportdirs { # returns scalar references to two arrays
|
sub getportdirs { # returns scalar references to two arrays
|
||||||
my @basedirs;
|
my @basedirs; my @localports;
|
||||||
my @localports;
|
|
||||||
my $conf = "/etc/prt-get.conf";
|
my $conf = "/etc/prt-get.conf";
|
||||||
|
|
||||||
open(PORTS, $conf) or die "could not open $conf";
|
open(PORTS, $conf) or die "could not open $conf";
|
||||||
|
@ -211,7 +218,7 @@ sub getportdirs { # returns scalar references to two arrays
|
||||||
push @basedirs, $line if (-d $line);
|
push @basedirs, $line if (-d $line);
|
||||||
} else {
|
} else {
|
||||||
my @a = split(/:/, $line);
|
my @a = split(/:/, $line);
|
||||||
my @b = split(/,/, @a[1]);
|
my @b = split(/,/, $a[1]);
|
||||||
while ( my $c = pop @b ) {
|
while ( my $c = pop @b ) {
|
||||||
my $port = $a[0] . "/" . $c;
|
my $port = $a[0] . "/" . $c;
|
||||||
push @localports, $port if (-d $port);
|
push @localports, $port if (-d $port);
|
||||||
|
|
Loading…
Reference in New Issue