prt-auf: clean up whitespace; improve documentation

This commit is contained in:
John McQuah 2023-06-15 18:37:53 -04:00
parent b690906b27
commit c2583c3642
2 changed files with 359 additions and 340 deletions

View File

@ -473,11 +473,21 @@ note that \-d is already passed to pkgmk anyway.
Pass these additional arguments to pkgadd
.TP
.B \-\-install\-root="...", e.g. \-\-install\-root="/mnt"
.B \-\-install\-root=<dir>, e.g. \-\-install\-root="/mnt"
Specify a mountpoint other than "/", where the built packages are to be
installed. This setting affects the package database that is subject to
read/write operations, but not the ports tree (which remains governed by
the prtdir directives in \fBprt-get.conf(5)\fP).
.TP
Beware of combining this option with the directive 'runscripts yes' in
the configuration file. One side-effect of the naive attempt to reconcile
this combination is that \fBprt\-auf\fP copies the pre- or
post-install scripts into the ports tree under <dir>, before running
a \fBchroot(1)\fP command to launch the scripts. This workaround might
inadvertently pollute <dir> with unwanted files, if the mountpoint did not
already contain a copy of the ports tree. It is safer to set 'runscripts
no' in the configuration file, whenever you plan to use an alternate root
for installations.
.TP
.B \-\-cache

View File

@ -83,8 +83,8 @@ if ($action eq "path") { @results = find_port_by_name($query[0],1,1,0);
#################### Post-transaction reports #######################
$strf = "%s\n";
if (($action =~ /^(listinst|listorphans|dependent)/) and
($odepends{tree}==0)) {
if (($action =~ /^(listinst|listorphans|dependent)/)
and ($odepends{tree}==0)) {
foreach my $result (sort @results) {
$result = ($osearch{verbose}==1) ? " $result: $V_INST{$result}" : " $result";
$result = ($osearch{verbose}>1) ? " $result: $V_INST{$result}\n$DESC{$result}\n" : $result;
@ -128,8 +128,10 @@ if (($action =~ /^(listinst|listorphans|dependent)/) and
print "-- dependency list ([i] = installed)\n" if ($action =~ /^dep/);
my $strf="%3s %s\n"; my $dep; my $missing=0;
foreach $dep (@results) {
if ($dep =~ /MISSING/) { $missing=1; print "-- missing packages\n"; next; }
if (! $dep) { next; }
if ($dep =~ /MISSING/) {
$missing=1; print "-- missing packages\n"; next;
}
next if (! $dep);
if ($action ne "quickdep") {
$ind = (grep { $_ eq $dep } keys %V_INST) ? "[i]" : "[ ]";
$dep .= " $V_REPO{$dep}" if ($osearch{verbose}==1);
@ -145,16 +147,22 @@ if (($action =~ /^(listinst|listorphans|dependent)/) and
my @fields = ("Name", "Repository", "Version", "Release", "Description",
"Dependencies", "URL", "Optional Deps", "Maintainer",
"Readme", "PreInstall", "PostInstall");
for (my $i=0; $i<9; $i++) { printf $strf, $fields[$i], $results[$i] unless ($results[$i] =~ /^\s*$/); }
for (my $i=0; $i<9; $i++) {
printf $strf, $fields[$i], $results[$i]
unless ($results[$i] =~ /^\s*$/);
}
} elsif ($action eq "remove") {
my @removed = @$ind;
print "Ports removed:\n" if (@removed);
foreach my $p (@removed) { print "$p\n"; }
} elsif ($action =~ /^(install|sysup)$/) {
my @ok = @{$results[0]}; my %ok_pre = %{$results[1]}; my %ok_post = %{$results[2]};
my @ok_readme = @{$results[3]}; my @not_ok = @{$results[4]}; my $note;
if ($opkg{test} eq "yes") { print "\n$action successful.\n";
print "*** prt-auf: test mode end\n\n"; }
my @ok = @{$results[0]}; my %ok_pre = %{$results[1]};
my %ok_post = %{$results[2]}; my @ok_readme = @{$results[3]};
my @not_ok = @{$results[4]}; my $note;
if ($opkg{test} eq "yes") {
print "\n$action successful.\n";
print "*** prt-auf: test mode end\n\n";
}
if (($opkg{test} eq "no") and (@ok)) {
print "Successful ports:\n";
foreach my $k (@ok) {
@ -175,14 +183,14 @@ if (($action =~ /^(listinst|listorphans|dependent)/) and
foreach (@not_ok) { print " $_\n"; }
print "\n";
}
} else {}
}
# Done!
#################### Begin Subroutines #######################
sub parse_args {
my @query;
while (my $arg = shift) {
my @query;
while (my $arg = shift) {
if ($arg =~ /^(search|dsearch|fsearch|path|info|list|remove)$/) { $action = $1;
} elsif ($arg =~ /^(install|update|depinst)$/) { $action = "install";
} elsif ($arg eq "sysup") { $action = "sysup"; $opkg{nolock}=0;
@ -221,36 +229,36 @@ sub parse_args {
} elsif ($arg =~ /^-/) {
print "'$arg' is not a recognized option.\n";
} else { push (@query, $arg); }
}
if (! $action) { print_help(); }
if (($#query > -1) and
}
if (! $action) { print_help(); }
if (($#query > -1) and
($action =~ /^(diff|quickdiff|cache|list|sysup)/)) {
print "warning: $1 takes no arguments; ignoring those given.\n";
}
if (($#query > 0) and
}
if (($#query > 0) and
($action =~ /^(search|dsearch|fsearch|info|readme|path|ls)$/)) {
print "warning: $1 takes only one argument; ignoring all but the first.\n";
}
if ((! @query) and
}
if ((! @query) and
($action =~ /^(search|dsearch|fsearch|info|readme|path|ls)$/)) {
print "$1 requires an argument.\n"; exit 1;
}
if (($#query != 0) and
}
if (($#query != 0) and
($action =~ /^(deptree|dependent)$/)) {
print "$1 requires exactly one argument.\n"; exit 1;
}
if (($#query < 0) and
}
if (($#query < 0) and
($action =~ /^(install|update|depinst|remove)$/)) {
print "$1 requires at least one argument.\n"; exit 1;
}
return $action, @query;
}
return $action, @query;
}
sub parse_prt_conf {
my @basedirs; my @localports; my $conf = shift;
my @basedirs; my @localports; my $conf = shift;
open(PORTS, $conf) or die "could not open $conf";
while (<PORTS>) { chomp;
open(PORTS, $conf) or die "could not open $conf";
while (<PORTS>) { chomp;
if ( /^prtdir\s+/ ) {
my $line = $_;
$line =~ s/^prtdir\s+//; #remove the leading directive
@ -302,7 +310,8 @@ sub find_dups {
@info1 = (get_pkgfile_fields($hits[1],"all"))[1,2,6,8];
push(@dupinfo,@info1); unshift(@dupinfo,$dup);
$dupstr = "$format\n";
$dupstr =~ s/(%n|%p1|%v1|%u1|%M1|%p2|%v2|%u2|%M2)/$dupinfo[$subscripts{$1}]/g;
$dupstr =~
s/(%n|%p1|%v1|%u1|%M1|%p2|%v2|%u2|%M2)/$dupinfo[$subscripts{$1}]/g;
print $dupstr;
}
}
@ -331,9 +340,9 @@ sub who_aliased_to {
}
sub printf_ports {
my $FS; my @pstats; my $p; my $inputf=shift; my @targets=@_;
my @pstats; my $p; my $inputf=shift; my @targets=@_;
my @pos; my @outfields; my $outputf; my %FS = ( "t"=>"\t", "n"=>"\n" );
my %subscripts = ( "n"=>0, "p"=>1, "v"=>2, "r"=>3, "d"=>4, "u"=>5,
my %subscripts = ( "n"=>0, "p"=>1, "v"=>2, "r"=>3, "d"=>4, "e"=>5, "u"=>6,
"P"=>7, "M"=>8, "R"=>9, "E"=>10, "O"=>11, "l"=>12, "i"=>13);
if ($inputf eq "CACHE") {
open (CACHE,'>',$prtcache) or die "cannot create a new cache file";
@ -352,9 +361,9 @@ sub printf_ports {
foreach (@outfields) {
if (m/\\(t|n)/) { $outputf .= $FS{$1}; next; }
$strf = $_;
s/%(p|n|v|r|d|u|P|M|R|E|O|l|i)/_Z_$subscripts{$1}/g;
s/%(p|n|v|r|d|e|u|P|M|R|E|O|l|i)/_Z_$subscripts{$1}/g;
push @pos, grep { s/([0-9]+)(.*)/$1/ } (split /_Z_/, $_);
$strf =~ s/%(p|n|v|r|d|u|P|M|R|E|O|l|i)/%s/g;
$strf =~ s/%(p|n|v|r|d|e|u|P|M|R|E|O|l|i)/%s/g;
$outputf .= $strf;
}
@ -363,8 +372,8 @@ sub printf_ports {
@pstats = get_pkgfile_fields($pp,"all");
$pstats[12] = ($LOCKED{$p}) ? "yes" : "no";
$pstats[13] = (grep /^$p$/, keys %V_INST) ? "yes" : "no";
if (($pstats[13] eq "yes") and ($V_INST{$p} ne $V_REPO{$p})) {
$pstats[13] = "diff" }
$pstats[13] = "diff"
if (($pstats[13] eq "yes") and ($V_INST{$p} ne $V_REPO{$p}));
printf STDOUT $outputf, @pstats[@pos];
}
}
@ -568,8 +577,9 @@ sub list_ports {
@found = grep { $not_orphans{$_} eq 0 } keys %V_INST;
} elsif (($subset eq "dependent") and ($odepends{recursive}==0)) {
@found = grep { " $DEPENDS{$_} " =~ / $sseed / } @searchspace;
if ($odepends{soft}==1) { push (@found,
grep{ " $SOFTDEPS{$_} " =~ / $sseed / } @searchspace);
if ($odepends{soft}==1) {
push (@found, grep
{ " $SOFTDEPS{$_} " =~ / $sseed / } @searchspace);
}
if ($odepends{tree}==1) { unshift (@found, "$seed"); }
} elsif ($subset =~ /^dep(endent|tree)/) {
@ -618,7 +628,8 @@ sub list_ports {
foreach my $dc (keys %curdeps) {
if (grep /^$dc$/, @lineage) {
print "Warning: dependency cycle => ".$dc."\n" unless ($greedy|$curdeps{$dc});
print "Warning: dependency cycle => "
.$dc."\n" unless ($greedy|$curdeps{$dc});
return;
}
push (@lineage, $dc);
@ -630,11 +641,8 @@ sub list_ports {
}
delete $seen{$seed} if ($odepends{tree} == 0);
@found = sort(keys %seen);
}
# possibilities for the recursive switch have been exhausted
else { }
} # possibilities for the recursive switch have been exhausted
} # possibilities for the filter have been exhausted
else { }
return @found if ((! $subset) or ($subset =~ /^(orphans|locked)$/));
if (! $osearch{filter}) { return @found; }
else { return grep {$_ !~ /$osearch{filter}/} @found; }
@ -664,11 +672,12 @@ sub port_diff { # find differences between the pkgdb and the repo
push @outfile, "$q: version $V_INST{$q}" if ($dtype eq "current");
push @outfile, "$q is installed." if ($dtype eq "isinst");
} else {
push @outfile, "$q is provided by package ".who_aliased_to($q) if ($dtype eq "isinst");
push @outfile, "$q is provided by package ".who_aliased_to($q)
if ($dtype eq "isinst");
push @outfile, "Package $q not installed" if ($dtype eq "current");
}
}
} else {}
}
return $retval, @outfile if ($dtype !~ /^(utd|sysup)/);
return $retval if ($dtype ne "sysup");
@ -709,9 +718,7 @@ sub deporder { # returns a sorted list of packages required.
# that are already installed or are given on the command line
if ($odepends{soft} == 1) {
foreach (grep { ($V_INST{$_}) or ($given{$_}) }
split /[ ,]/, $SOFTDEPS{$s}) {
$curdeps{$_} = 1;
}
split /[ ,]/, $SOFTDEPS{$s}) { $curdeps{$_} = 1; }
}
foreach my $sd (keys %curdeps) {
@ -732,8 +739,8 @@ sub deporder { # returns a sorted list of packages required.
}
sub up_inst { # returns scalar references to five arrays
my @requested=@_; my @sortedList; my @targets; my %pdirs;
my %builtpkg; my %mkcmd; my %addcmd; my %logfile; my %pvars; my $status;
my @requested=@_; my @sortedList; my @targets; my %pdirs; my %builtpkg;
my %mkcmd; my %addcmd; my $rs_cmd; my %logfile; my %pvars; my $status;
my %ok; my %not_ok; my %ok_pre; my %ok_post; my @ok_readme=();
my $PKGMK=$opkg{makecommand}; my $PKGADD=$opkg{addcommand};
@ -749,7 +756,8 @@ sub up_inst { # returns scalar references to five arrays
# omit the ports that appear up to date, unless a rebuild is forced
if ("$opkg{margs} $opkg{aargs}" !~ m/-f/) {
@targets = grep {( (! $V_INST{$_}) or ($V_REPO{$_} ne $V_INST{$_}) )} @targets;
@targets = grep {( (! $V_INST{$_})
or ($V_REPO{$_} ne $V_INST{$_}) )} @targets;
}
# exempt any locked ports from being updated
@ -796,43 +804,45 @@ sub up_inst { # returns scalar references to five arrays
$ok{$t}=1;
next BUILDLOG;
}
if ($mkcmd{$t} ne "") {
if (($opkg{runscripts} eq "yes") and (-f "$pdirs{$t}/pre-install")) {
$rs_cmd="/bin/sh $pdirs{$t}/pre-install";
if ($altroot ne "") {
system("chroot",$altroot,"sh","$pdirs{$t}/pre-install");
} else {
system("sh","$pdirs{$t}/pre-install");
(-f "$altroot/$pdirs{$t}/pre-install") or
system("install -D $pdirs{$t}/pre-install $altroot/$pdirs{$t}/pre-install");
$rs_cmd = "chroot $altroot $rs_cmd";
}
( $?>>8 == 0 ) ? $ok_pre{$t} = 1 : delete $ok_pre{$t};
(system("$rs_cmd")==0) ? $ok_pre{$t} = 1 : delete $ok_pre{$t};
}
chdir $pdirs{$t}; system("$mkcmd{$t}"); $status=( $?>>8 == 0 );
chdir("$pdirs{$t}") or $not_ok{$t} = 1;
if ($not_ok{$t}) { next BUILDLOG; }
$status = (system("$mkcmd{$t}")==0);
if ($logfile{$t}) {
( ($mkcmd{$t} =~ /skipped build/) or ! log_failure($logfile{$t}) ) ? $ok{$t} = 1 : $not_ok{$t} = 1;
( ($mkcmd{$t} =~ /skipped build/) or ! log_failure($logfile{$t}) ) ?
$ok{$t} = 1 : $not_ok{$t} = 1;
} else {
( $status ) ? $ok{$t} = 1 : $not_ok{$t} = 1;
($status) ? $ok{$t} = 1 : $not_ok{$t} = 1;
}
if ( $ok{$t} ) {
if ($ok{$t}) {
$addcmd{$t} =~ s/ -u / / if (! $V_INST{$t});
system("$addcmd{$t}");
if ( $?>>8 == 0 ) { $ok{$t} = 1;
push (@ok_readme, $t) if (-f $pdirs{$t}."/README");
if (system("$addcmd{$t}")==0) {
$ok{$t} = 1;
push (@ok_readme, $t) if (-f "README");
} else {
$not_ok{$t} = 1; delete $ok{$t};
}
unlink($logfile{$t}) if (($logfile{$t}) and
($olog{rm_on_success} eq "yes") );
unlink($logfile{$t})
if ( ($logfile{$t}) and ($olog{rm_on_success} eq "yes") );
} elsif ( ($not_ok{$t}) and (-f "$builtpkg{$t}") ) {
system("mv $builtpkg{$t} $builtpkg{$t}.CHECKME");
rename("$builtpkg{$t}","$builtpkg{$t}.CHECKME");
}
if (($ok{$t}) and ($opkg{runscripts} eq "yes")
and (-f "$pdirs{$t}/post-install")) {
if (($ok{$t}) and ($opkg{runscripts} eq "yes") and (-f "post-install")) {
$rs_cmd="/bin/sh post-install";
if ($altroot ne "") {
system("chroot",$altroot,"sh","$pdirs{$t}/post-install");
} else {
system("sh","$pdirs{$t}/post-install");
}
( $?>>8 == 0 ) ? $ok_post{$t}=1 : delete $ok_post{$t};
(-f "$altroot/$pdirs{$t}/post-install") or
system("install -D $pdirs{$t}/post-install $altroot/$pdirs{$t}/post-install");
$rs_cmd="chroot $altroot $rs_cmd";
}
(system("$rs_cmd")==0) ? $ok_post{$t}=1 : delete $ok_post{$t};
}
last if (($opkg{group} eq "yes") and ($not_ok{$t}));
}
@ -844,8 +854,7 @@ sub up_inst { # returns scalar references to five arrays
close(FH); return $failed;
}
my @ok = keys %ok;
my @not_ok = keys %not_ok;
my @ok = keys %ok; my @not_ok = keys %not_ok;
return \@ok, \%ok_pre, \%ok_post, \@ok_readme, \@not_ok;
}