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 Pass these additional arguments to pkgadd
.TP .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 Specify a mountpoint other than "/", where the built packages are to be
installed. This setting affects the package database that is subject to installed. This setting affects the package database that is subject to
read/write operations, but not the ports tree (which remains governed by read/write operations, but not the ports tree (which remains governed by
the prtdir directives in \fBprt-get.conf(5)\fP). 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 .TP
.B \-\-cache .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 ####################### #################### Post-transaction reports #######################
$strf = "%s\n"; $strf = "%s\n";
if (($action =~ /^(listinst|listorphans|dependent)/) and if (($action =~ /^(listinst|listorphans|dependent)/)
($odepends{tree}==0)) { and ($odepends{tree}==0)) {
foreach my $result (sort @results) { foreach my $result (sort @results) {
$result = ($osearch{verbose}==1) ? " $result: $V_INST{$result}" : " $result"; $result = ($osearch{verbose}==1) ? " $result: $V_INST{$result}" : " $result";
$result = ($osearch{verbose}>1) ? " $result: $V_INST{$result}\n$DESC{$result}\n" : $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/); print "-- dependency list ([i] = installed)\n" if ($action =~ /^dep/);
my $strf="%3s %s\n"; my $dep; my $missing=0; my $strf="%3s %s\n"; my $dep; my $missing=0;
foreach $dep (@results) { foreach $dep (@results) {
if ($dep =~ /MISSING/) { $missing=1; print "-- missing packages\n"; next; } if ($dep =~ /MISSING/) {
if (! $dep) { next; } $missing=1; print "-- missing packages\n"; next;
}
next if (! $dep);
if ($action ne "quickdep") { if ($action ne "quickdep") {
$ind = (grep { $_ eq $dep } keys %V_INST) ? "[i]" : "[ ]"; $ind = (grep { $_ eq $dep } keys %V_INST) ? "[i]" : "[ ]";
$dep .= " $V_REPO{$dep}" if ($osearch{verbose}==1); $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", my @fields = ("Name", "Repository", "Version", "Release", "Description",
"Dependencies", "URL", "Optional Deps", "Maintainer", "Dependencies", "URL", "Optional Deps", "Maintainer",
"Readme", "PreInstall", "PostInstall"); "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") { } elsif ($action eq "remove") {
my @removed = @$ind; my @removed = @$ind;
print "Ports removed:\n" if (@removed); print "Ports removed:\n" if (@removed);
foreach my $p (@removed) { print "$p\n"; } foreach my $p (@removed) { print "$p\n"; }
} elsif ($action =~ /^(install|sysup)$/) { } elsif ($action =~ /^(install|sysup)$/) {
my @ok = @{$results[0]}; my %ok_pre = %{$results[1]}; my %ok_post = %{$results[2]}; my @ok = @{$results[0]}; my %ok_pre = %{$results[1]};
my @ok_readme = @{$results[3]}; my @not_ok = @{$results[4]}; my $note; my %ok_post = %{$results[2]}; my @ok_readme = @{$results[3]};
if ($opkg{test} eq "yes") { print "\n$action successful.\n"; my @not_ok = @{$results[4]}; my $note;
print "*** prt-auf: test mode end\n\n"; } 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)) { if (($opkg{test} eq "no") and (@ok)) {
print "Successful ports:\n"; print "Successful ports:\n";
foreach my $k (@ok) { foreach my $k (@ok) {
@ -175,7 +183,7 @@ if (($action =~ /^(listinst|listorphans|dependent)/) and
foreach (@not_ok) { print " $_\n"; } foreach (@not_ok) { print " $_\n"; }
print "\n"; print "\n";
} }
} else {} }
# Done! # Done!
@ -302,7 +310,8 @@ sub find_dups {
@info1 = (get_pkgfile_fields($hits[1],"all"))[1,2,6,8]; @info1 = (get_pkgfile_fields($hits[1],"all"))[1,2,6,8];
push(@dupinfo,@info1); unshift(@dupinfo,$dup); push(@dupinfo,@info1); unshift(@dupinfo,$dup);
$dupstr = "$format\n"; $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; print $dupstr;
} }
} }
@ -331,9 +340,9 @@ sub who_aliased_to {
} }
sub printf_ports { 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 @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); "P"=>7, "M"=>8, "R"=>9, "E"=>10, "O"=>11, "l"=>12, "i"=>13);
if ($inputf eq "CACHE") { if ($inputf eq "CACHE") {
open (CACHE,'>',$prtcache) or die "cannot create a new cache file"; open (CACHE,'>',$prtcache) or die "cannot create a new cache file";
@ -352,9 +361,9 @@ sub printf_ports {
foreach (@outfields) { foreach (@outfields) {
if (m/\\(t|n)/) { $outputf .= $FS{$1}; next; } if (m/\\(t|n)/) { $outputf .= $FS{$1}; next; }
$strf = $_; $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_/, $_); 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; $outputf .= $strf;
} }
@ -363,8 +372,8 @@ sub printf_ports {
@pstats = get_pkgfile_fields($pp,"all"); @pstats = get_pkgfile_fields($pp,"all");
$pstats[12] = ($LOCKED{$p}) ? "yes" : "no"; $pstats[12] = ($LOCKED{$p}) ? "yes" : "no";
$pstats[13] = (grep /^$p$/, keys %V_INST) ? "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]; printf STDOUT $outputf, @pstats[@pos];
} }
} }
@ -568,8 +577,9 @@ sub list_ports {
@found = grep { $not_orphans{$_} eq 0 } keys %V_INST; @found = grep { $not_orphans{$_} eq 0 } keys %V_INST;
} elsif (($subset eq "dependent") and ($odepends{recursive}==0)) { } elsif (($subset eq "dependent") and ($odepends{recursive}==0)) {
@found = grep { " $DEPENDS{$_} " =~ / $sseed / } @searchspace; @found = grep { " $DEPENDS{$_} " =~ / $sseed / } @searchspace;
if ($odepends{soft}==1) { push (@found, if ($odepends{soft}==1) {
grep{ " $SOFTDEPS{$_} " =~ / $sseed / } @searchspace); push (@found, grep
{ " $SOFTDEPS{$_} " =~ / $sseed / } @searchspace);
} }
if ($odepends{tree}==1) { unshift (@found, "$seed"); } if ($odepends{tree}==1) { unshift (@found, "$seed"); }
} elsif ($subset =~ /^dep(endent|tree)/) { } elsif ($subset =~ /^dep(endent|tree)/) {
@ -618,7 +628,8 @@ sub list_ports {
foreach my $dc (keys %curdeps) { foreach my $dc (keys %curdeps) {
if (grep /^$dc$/, @lineage) { 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; return;
} }
push (@lineage, $dc); push (@lineage, $dc);
@ -630,11 +641,8 @@ sub list_ports {
} }
delete $seen{$seed} if ($odepends{tree} == 0); delete $seen{$seed} if ($odepends{tree} == 0);
@found = sort(keys %seen); @found = sort(keys %seen);
} } # possibilities for the recursive switch have been exhausted
# possibilities for the recursive switch have been exhausted
else { }
} # possibilities for the filter have been exhausted } # possibilities for the filter have been exhausted
else { }
return @found if ((! $subset) or ($subset =~ /^(orphans|locked)$/)); return @found if ((! $subset) or ($subset =~ /^(orphans|locked)$/));
if (! $osearch{filter}) { return @found; } if (! $osearch{filter}) { return @found; }
else { return grep {$_ !~ /$osearch{filter}/} @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: version $V_INST{$q}" if ($dtype eq "current");
push @outfile, "$q is installed." if ($dtype eq "isinst"); push @outfile, "$q is installed." if ($dtype eq "isinst");
} else { } 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"); push @outfile, "Package $q not installed" if ($dtype eq "current");
} }
} }
} else {} }
return $retval, @outfile if ($dtype !~ /^(utd|sysup)/); return $retval, @outfile if ($dtype !~ /^(utd|sysup)/);
return $retval if ($dtype ne "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 # that are already installed or are given on the command line
if ($odepends{soft} == 1) { if ($odepends{soft} == 1) {
foreach (grep { ($V_INST{$_}) or ($given{$_}) } foreach (grep { ($V_INST{$_}) or ($given{$_}) }
split /[ ,]/, $SOFTDEPS{$s}) { split /[ ,]/, $SOFTDEPS{$s}) { $curdeps{$_} = 1; }
$curdeps{$_} = 1;
}
} }
foreach my $sd (keys %curdeps) { 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 sub up_inst { # returns scalar references to five arrays
my @requested=@_; my @sortedList; my @targets; my %pdirs; my @requested=@_; my @sortedList; my @targets; my %pdirs; my %builtpkg;
my %builtpkg; my %mkcmd; my %addcmd; my %logfile; my %pvars; my $status; 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 %ok; my %not_ok; my %ok_pre; my %ok_post; my @ok_readme=();
my $PKGMK=$opkg{makecommand}; my $PKGADD=$opkg{addcommand}; 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 # omit the ports that appear up to date, unless a rebuild is forced
if ("$opkg{margs} $opkg{aargs}" !~ m/-f/) { 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 # exempt any locked ports from being updated
@ -796,43 +804,45 @@ sub up_inst { # returns scalar references to five arrays
$ok{$t}=1; $ok{$t}=1;
next BUILDLOG; next BUILDLOG;
} }
if ($mkcmd{$t} ne "") {
if (($opkg{runscripts} eq "yes") and (-f "$pdirs{$t}/pre-install")) { if (($opkg{runscripts} eq "yes") and (-f "$pdirs{$t}/pre-install")) {
$rs_cmd="/bin/sh $pdirs{$t}/pre-install";
if ($altroot ne "") { if ($altroot ne "") {
system("chroot",$altroot,"sh","$pdirs{$t}/pre-install"); (-f "$altroot/$pdirs{$t}/pre-install") or
} else { system("install -D $pdirs{$t}/pre-install $altroot/$pdirs{$t}/pre-install");
system("sh","$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}) { 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 { } 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}); $addcmd{$t} =~ s/ -u / / if (! $V_INST{$t});
system("$addcmd{$t}"); if (system("$addcmd{$t}")==0) {
if ( $?>>8 == 0 ) { $ok{$t} = 1; $ok{$t} = 1;
push (@ok_readme, $t) if (-f $pdirs{$t}."/README"); push (@ok_readme, $t) if (-f "README");
} else { } else {
$not_ok{$t} = 1; delete $ok{$t}; $not_ok{$t} = 1; delete $ok{$t};
} }
unlink($logfile{$t}) if (($logfile{$t}) and unlink($logfile{$t})
($olog{rm_on_success} eq "yes") ); if ( ($logfile{$t}) and ($olog{rm_on_success} eq "yes") );
} elsif ( ($not_ok{$t}) and (-f "$builtpkg{$t}") ) { } 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") if (($ok{$t}) and ($opkg{runscripts} eq "yes") and (-f "post-install")) {
and (-f "$pdirs{$t}/post-install")) { $rs_cmd="/bin/sh post-install";
if ($altroot ne "") { if ($altroot ne "") {
system("chroot",$altroot,"sh","$pdirs{$t}/post-install"); (-f "$altroot/$pdirs{$t}/post-install") or
} else { system("install -D $pdirs{$t}/post-install $altroot/$pdirs{$t}/post-install");
system("sh","$pdirs{$t}/post-install"); $rs_cmd="chroot $altroot $rs_cmd";
}
( $?>>8 == 0 ) ? $ok_post{$t}=1 : delete $ok_post{$t};
} }
(system("$rs_cmd")==0) ? $ok_post{$t}=1 : delete $ok_post{$t};
} }
last if (($opkg{group} eq "yes") and ($not_ok{$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; close(FH); return $failed;
} }
my @ok = keys %ok; my @ok = keys %ok; my @not_ok = keys %not_ok;
my @not_ok = keys %not_ok;
return \@ok, \%ok_pre, \%ok_post, \@ok_readme, \@not_ok; return \@ok, \%ok_pre, \%ok_post, \@ok_readme, \@not_ok;
} }