pkg-repgen: merge globbed packages into the old index more intelligently

pkg-get: ensure all variables in status messages are initialized
This commit is contained in:
John McQuah 2023-09-19 21:22:22 +00:00
parent 206657b510
commit 43eb68a532
2 changed files with 177 additions and 92 deletions

View File

@ -32,7 +32,7 @@ my %locked; my %installed;
# CL Options
my $download_only; my $pre_install; my $post_install;
my $install_scripts; my $filter = ""; my $all; my $unused;
my $aargs=""; my $ignore_md5sum; my $force; my $root;
my $aargs=""; my $ignore_md5sum; my $force; my $root="";
GetOptions("do"=>\$download_only,
"pre-install"=>\$pre_install, "post-install"=>\$post_install,
"install-scripts"=>\$install_scripts, "all"=>\$all,
@ -428,7 +428,7 @@ sub installpkg {
if ($pkg{'readme'} eq "yes") {$readmetasks{$pkg{'name'}} = 1};
$pptasks{$pkg{'name'}} = "";
if ($force){$aa = $aa."-f ";}
if ($root) {$aa = $aa."-r ".$root." ";}
if ($root ne "") {$aa = $aa."-r ".$root." ";}
if ($install_scripts or $pre_install) {doscript("pre",%pkg);}
my $fullpath = $pkg{'path'}."/".$pkg{'name'}."#".$pkg{'version'}."-".$pkg{'release'}.".pkg.tar.$compress";
print "pkg-get: /usr/bin/pkgadd $upgrade $aa$fullpath\n";
@ -441,7 +441,7 @@ sub installpkg {
sub doscript {
my ($when, %pkg) = @_;
($pkg{$when . "_install"} eq "yes") or return;
my $cmd = ($root) ? "chroot $root " : "";
my $cmd = ($root ne "") ? "chroot $root " : "";
$cmd .= "/bin/bash $pkg{'path'}/PKGINST $pkg{'name'} $when";
if ((-e "$root$pkg{'path'}/PKGINST") and (system($cmd) == 0)) {
$pptasks{$pkg{'name'}} .= " [$when: ok]";
@ -575,7 +575,7 @@ sub remove {
$curraction = "removed";
shift(@ARGV);
my $cmd = "/usr/bin/pkgrm";
$cmd .= " -r $root" if ($root);
$cmd .= " -r $root" if ($root ne "");
foreach my $pkg(@ARGV) {
$pptasks{$pkg} = "";
if (system("$cmd $pkg")==0) {
@ -813,7 +813,7 @@ sub upinst {
my ($cmd, @args) = @_; my $aa;
($curraction, $aa) = ($cmd =~ /^up/) ? ("updated","-u") : ("installed","");
if ($root) {
if ($root ne "") {
foreach my $repo(@repos) {
my ($dir, $url) = split(/\|/, $repo);
( -e "$root$dir" ) or make_path("$root$dir");

View File

@ -47,6 +47,10 @@ sub pkg_mtime {
}
my $pkgdir = shift @ARGV; my $quickMode=0;
if (($pkgdir) and (! -d "$pkgdir")) {
print "usage: pkg-repgen [options] [directory [pkgname1..pkgnameN]]\n";
exit 1;
}
my @dirlist = ("$pkgdir") ? glob("$pkgdir/*.pkg.tar.$compress") : glob("*.pkg.tar.$compress");
@dirlist = sort pkg_mtime @dirlist;
%isDup = map { $_ => 0 } @dirlist;
@ -55,8 +59,7 @@ if (@ARGV) { # individual packages
$quickMode=1;
my @updates = sort @ARGV;
while (my $name = shift @updates) {
my @hits = grep { m/$name#.*\.pkg/ } @dirlist;
push(@packages,@hits);
push @packages, grep { m/$name#.*\.pkg/ } @dirlist;
}
} else { # the entire directory
@packages = @dirlist;
@ -103,108 +106,185 @@ pkgreadscripts();
sub pkg_single {
my ($oR, $oD, $oH, $nR, $nD, $nH, $oline, $oname);
my $count = 0; # needed for the html index
my @dep_packages = @packages;
my @idx_packages = @packages;
my %firstrun = map { $_ => 0 } ("PKGREPO", "PKGDEPS", "index.html");
open ($oR, "$pkgdir/PKGREPO") or $firstrun{"PKGREPO"} = 1;
open ($oD, "$pkgdir/PKGDEPS") or $firstrun{"PKGDEPS"} = 1;
open ($oH, "$pkgdir/index.html") or $firstrun{"index.html"} = 1;
open ($nR, ">$pkgdir/PKGREPO.new");
open ($nD, ">$pkgdir/PKGDEPS.new");
printheader(1);
open ($nH, ">>$pkgdir/index.html.new");
foreach my $mf ("repository", "dependency map", "html index") {
print "+ Updating specified entries in $mf\n";
}
PACKAGE: while (my $p =shift @packages) {
my ($pver, $url, $du, $md5, $desc, $ppr, $pdeps, $date) = metadata($p);
my $basename = (split /\//, $p)[-1];
($firstrun{"PKGREPO"}==0) or printf $nR "%-s:%-s:%-s:%-s:%-s\n",
$basename, $du, $md5, $desc, $ppr;
($firstrun{"PKGDEPS"}==0) or ($pdeps eq "") or ($isDup{$p})
or printf $nD "%-30s : %-s\n", $pname{$p}, $pdeps;
if ($firstrun{"index.html"} == 1) {
$count++;
htmlrow($nH,$count,$pname{$p},$url,$pver,$desc,$date);
print "+ Updating specified entries in repository\n";
RPKG: while (my $p =shift @packages) {
my ($basename, $du, $md5, $ppr) = repodata($p);
my $desc = (! $descrip{$pname{$p}}) ? "N.A." : $descrip{$pname{$p}};
if ($firstrun{"PKGREPO"}==1) {
printf $nR "%-s:%-s:%-s:%-s:%-s\n",$basename, $du, $md5, $desc, $ppr;
next RPKG;
}
($firstrun{"PKGREPO"}*$firstrun{"PKGDEPS"}*$firstrun{"index.html"}==0) or next PACKAGE;
# Pop entries from the old repository until we reach an entry
# that would come after the current package.
while ( ($firstrun{"PKGREPO"}==0) and $oline = <$oR> ) {
# Shift entries from the old repository until we find
# a successor to the current package.
while ( (! $followR{$pname{$p}}) and $oline = <$oR> ) {
chomp($oline); $oname = $oline;
$oname =~ s/#.*//;
$oname =~ s/\#.*//;
print $nR "$oline\n" if ($oname lt $pname{$p});
# before breaking out of the loop, either overwrite the old
# entry in the repository, or insert the requested package
# where it should appear.
printf $nR "%-s:%-s:%-s:%-s:%-s\n", $basename, $du, $md5, $desc, $ppr
if ($oname ge $pname{$p});
# before breaking out of the loop, append all the packages
# from the globbed queue that are lexographically earlier
# than the current entry in the old repository.
while ($pname{$p} le $oname) {
printf $nR "%-s:%-s:%-s:%-s:%-s\n", $basename, $du, $md5, $desc, $ppr;
next RPKG if (! $isDup{$p});
$p = shift @packages;
($basename, $du, $md5, $ppr) = repodata($p);
$desc = (! $descrip{$pname{$p}}) ? "N.A." : $descrip{$pname{$p}};
# save what got popped from the repository, in case of dups
$followR{$pname{$p}} = $oline if ($oname gt $pname{$p});
# stop reading the repository, at least until the next package
last if ($oname ge $pname{$p});
# save what got shifted from the repository if we're not going to
# print it now, but don't save packages that match the same glob.
$followR{$pname{$p}} = "$oline\n" if ($pname{$p} lt $oname);
}
}
# if the current package comes after everything in the old repository,
# just append its metadata
($followR{$pname{$p}}) or printf $nR "%-s:%-s:%-s:%-s:%-s\n", $basename, $du, $md5, $desc, $ppr;
# Likewise for the html index
while ( ($firstrun{"index.html"}==0) and $oline=<$oH> ) {
chomp($oline);
# no need to copy the header, it should already be there
next if ($oline !~ m/^<tr class="(odd|even)"/);
$oname = $oline;
$oname =~ s/.*a href="(.*)"/$1/;
$oname =~ s/\%23.*//;
next RPKG if (($isDup{$p}) or (! $followR{$pname{$p}}));
if ($oname lt $pname{$p}) {
print $nH "$oline\n";
} elsif ($oname eq $pname{$p}) {
$count++;
htmlrow($nH,$count,$pname{$p},$url, $pver,$desc,$date);
} else {
$followH{$pname{$p}} = $oline;
}
last if ($oname ge $pname{$p});
# Arriving here means the current package is not a dup, and
# definitely has a successor in the old repository. But the
# next globbed package might be a more immediate successor.
# Decide which of the two possible successors comes first.
# By defining a successor for the next package in the queue,
# we delay shifting entries off the old repo.
if ((@packages) and ($pname{$packages[0]} le $followR{$pname{$p}})) {
$followR{$pname{$packages[0]}} = $followR{$pname{$p}};
next RPKG;
} else {
print $nR $followR{$pname{$p}};
}
# Likewise for the dependency map, but avoid creating duplicate entries
while ( ($firstrun{"PKGDEPS"}==0) and $oline = <$oD> ) {
# Shift another package from the queue
}
# Likewise for the html index
printheader(1);
open ($nH, ">>$pkgdir/index.html.new");
print "+ Updating specified entries in the html index\n";
HPKG: while (my $p =shift @idx_packages) {
my ($url, $pver, $desc, $date) = htmldata($p);
if ($firstrun{"index.html"} == 1) {
$count++;
htmlrow($nH,$count,$pname{$p},$url,$pver,$desc,$date);
next HPKG;
}
# Shift entries from the old html index until we find
# a successor to the current package.
while ( (! $followH{$pname{$p}}) and $oline=<$oH> ) {
chomp($oline);
# no need to copy the header, it should already be there
next if ($oline !~ m/^<tr class="(odd|even)"/);
$oname = $oline;
$oname =~ s/.*a href="(.*)"/$1/; $oname =~ s/\%23.*//;
if ($oname lt $pname{$p}) { $count++; print $nH "$oline\n"; }
# before breaking out of the loop, append all the packages
# from the globbed queue that are lexographically earlier
# than the current entry in the old html index.
while ($pname{$p} le $oname) {
$count++;
htmlrow($nH,$count,$pname{$p},$url,$pver,$desc,$date);
next HPKG if (! $isDup{$p});
$p = shift @idx_packages;
($url, $pver, $desc, $date) = htmldata($p);
# save what got shifted from the index if we're not going to print
# it now, but ignore packages that match the same glob.
$followH{$pname{$p}} = "$oline\n" if ($pname{$p} lt $oname);
}
}
# if the current package comes after everything in the old html index,
# just append its metadata
if (! $followH{$pname{$p}}) {
$count++;
htmlrow($nH,$count,$pname{$p},$url,$pver,$desc,$date);
}
next HPKG if (($isDup{$p}) or (! $followH{$pname{$p}}));
# Arriving here means the current package is not a dup, and
# definitely has a successor in the old html index. But the
# next globbed package might be a more immediate successor.
# Decide which of the two possible successors comes first. If the
# globbed package is the more immediate successor, use its name
# as a key to retain the most recent entry from the html index.
if ((@packages) and ($pname{$packages[0]} le $followH{$pname{$p}})) {
$followH{$pname{$packages[0]}} = $followH{$pname{$p}};
next HPKG;
} else {
$count++;
$followH{$pname{$p}} =~ s/class="(even|odd)"/class="$parity{($count %2)}"/;
print $nH $followH{$pname{$p}};
}
# Shift another package from the queue
}
# Likewise for the dependency map, but avoid creating duplicate entries
open ($nD, ">$pkgdir/PKGDEPS.new");
print "+ Updating specified entries in the depmap\n";
DPKG: while (my $p =shift @dep_packages) {
if ($firstrun{"PKGDEPS"}==1) {
(! $depends{$pname{$p}}) or ($isDup{$p})
or printf $nD "%-30s : %-s\n", $pname{$p}, $depends{$pname{$p}};
next DPKG;
}
# Shift entries from the old depmap until we find a successor
# to the current package
while ( (! $followD{$pname{$p}}) and $oline = <$oD> ) {
chomp($oline); $oname = $oline;
$oname =~ s/\s*\:.*//;
if ($oname lt $pname{$p}) {
print $nD "$oline\n";
} else {
printf $nD "%-30s : %-s\n", $pname{$p}, $pdeps;
$followD{$pname{$p}} = $oline if ($oname gt $pname{$p});
}
last if ($oname ge $pname{$p});
print $nD "$oline\n" if ($oname lt $pname{$p});
while ($pname{$p} le $oname) {
if (! $isDup{$p}) {
printf $nD "%-30s : %-s\n", $pname{$p}, $depends{$pname{$p}};
next DPKG;
} else {
$p = shift @dep_packages;
}
# save what got shifted from the depmap if we're not going to print
# it now, but ignore packages that match the same glob.
$followD{$pname{$p}} = $oline if ($pname{$p} lt $oname);
}
}
# if the current package comes after everything in the old depmap,
# just append its metadata
($followD{$pname{$p}}) or ($isDup{$p}) or ($pdeps eq "")
or printf $nD "%-30s : %-s\n", $pname{$p}, $pdeps;
# if the current package comes after everything in the old depmap
# and is not a dup, just append its metadata
($followD{$pname{$p}}) or ($isDup{$p}) or (! $depends{$pname{$p}})
or printf $nD "%-30s : %-s\n", $pname{$p}, $depends{$pname{$p}};
# after reaching the last in a sequence of dups, copy the
# successor line from the old {html index, repository}
if ( (! $isDup{$p}) and ($followH{$pname{$p}}) ) {
$count++;
$followH{$pname{$p}} =~ s/class="(even|odd)"/class="$parity{($count %2)}"/;
print $nH $followH{$pname{$p}};
next DPKG if (($isDup{$p}) or (! $followD{$pname{$p}}));
# Arriving here means the current package is not a dup, and
# definitely has a successor entry in the old depmap.
# But the next globbed package might be a more immediate successor.
# Decide which of the two possible successors comes first. If it's the
# globbed package that comes next, save the old depmap entry.
if ((@packages) and ($pname{$packages[0]} le $followD{$pname{$p}})) {
$followD{$pname{$packages[0]}} = $followD{$pname{$p}};
next DPKG;
} else {
printf $nD $followD{$pname{$p}};
}
($isDup{$p}) or (! $followR{$pname{$p}}) or print $nR $followR{$pname{$p}};
# Restart the loop with the next package in the queue
# Shift another package from the queue
}
# Done with all the packages that match command-line arguments.
@ -224,7 +304,7 @@ sub pkg_single {
($firstrun{"PKGDEPS"}==1) or close($oD);
($firstrun{"index.html"}==1) or close($oH);
foreach my $db (keys %firstrun) { rename("$pkgdir/$db.new", "$pkgdir/$db"); }
#foreach my $db (keys %firstrun) { rename("$pkgdir/$db.new", "$pkgdir/$db"); }
printfooter($count) if ($firstrun{"index.html"} == 1);
}
@ -238,10 +318,10 @@ sub pkg_dir {
my $count = 0;
open (my $ih, ">>$pkgdir/index.html");
foreach my $p (@packages) {
my ($pver, $url, $du, $md5, $desc, $ppr, $pdeps, $date) = metadata($p);
($pdeps eq "") or ($isDup{$p})
or printf $iD "%-30s : %-s\n", $pname{$p}, $pdeps;
my $basename = (split /\//, $p)[-1];
my ($basename, $du, $md5, $ppr) = repodata($p);
my ($url, $pver, $desc, $date) = htmldata($p);
(! $depends{$pname{$p}}) or ($isDup{$p})
or printf $iD "%-30s : %-s\n", $pname{$p}, $depends{$pname{$p}};
printf $iR "%-s:%-s:%-s:%-s:%-s\n", $basename,$du,$md5,$desc,$ppr;
$count++;
htmlrow($ih,$count,$pname{$p},$url,$pver,$desc,$date);
@ -392,18 +472,23 @@ EOH
close($ih);
}
sub metadata {
sub htmldata {
my $p = shift;
my ($pver, $url) = ($p, $p);
$pver =~ s/.*\#//; $pver =~ s/\.pkg\.tar.*//;
$url =~ s/\#/\%23/; while ($url =~ s/.*\///) {};
$url = (split /\//, $p)[-1]; $url =~ s/\#/\%23/;
my $date = isotime( (stat($p))[9], 1);
my $desc = (! $descrip{$pname{$p}}) ? "N.A." : $descrip{$pname{$p}};
return $url, $pver, $desc, $date;
}
sub repodata {
my $p = shift;
my $basename = (split /\//, $p)[-1];
my $du = (-s $p);
my $md5 = digest_file_hex($p,"MD5");
my $desc = (! $descrip{$pname{$p}}) ? "N.A." : $descrip{$pname{$p}};
my $ppr = (! $flags{$pname{$p}}) ? "no:no:no" : $flags{$pname{$p}};
my $pdeps = (! $depends{$pname{$p}}) ? "" : $depends{$pname{$p}};
my $date = isotime( (stat($p))[9], 1);
return $pver, $url, $du, $md5, $desc, $ppr, $pdeps, $date;
return $basename, $du, $md5, $ppr;
}
sub isotime {