pkg-repgen: use the html template installed by portspage

pkg-get: infer compression mode from the remote filename,
not from the local pkgmk.conf
This commit is contained in:
John McQuah 2024-04-22 20:53:01 +00:00
parent 3224209ff7
commit deaa06e52c
2 changed files with 68 additions and 116 deletions

View File

@ -40,15 +40,6 @@ GetOptions("do"=>\$download_only,
"f"=>\$force, "im"=>\$ignore_md5sum, "margs=s"=>\$unused, "f"=>\$force, "im"=>\$ignore_md5sum, "margs=s"=>\$unused,
"fr"=>\$force_reinst, "rargs=s"=>\$unused, "r=s"=>\$root); "fr"=>\$force_reinst, "rargs=s"=>\$unused, "r=s"=>\$root);
# use compression-mode defined in pkgmk.conf
our $compress = "gz";
open CONFIG, "/etc/pkgmk.conf" or die "Could not open /etc/pkgmk.conf";
while (<CONFIG>) {
$compress = $1 if m/^PKGMK_COMPRESSION_MODE=(.*)(#|$)/;
}
close CONFIG;
$compress =~ s/['" ]//g;
if ($root) { if ($root) {
$LOCKFILE = $root.$LOCKFILE ; $LOCKFILE = $root.$LOCKFILE ;
$PKGDB = $root.$PKGDB; $PKGDB = $root.$PKGDB;
@ -159,11 +150,11 @@ sub get_locked {
sub parsepackage { sub parsepackage {
my $type=shift; my @p = split(/\:/, $_[0]); my $type=shift; my @p = split(/\:/, $_[0]);
if ($#p < 6) {exiterr("$_[1]/PKGREPO appears to be in wrong format!\nAborting.")}; if ($#p < 6) {exiterr("$_[1]/PKGREPO appears to be in wrong format!\nAborting.")};
my ($N, $V) = ($p[0] =~ m/(.*)\#(.*\.pkg\.tar.*)/) ? ($1, $2) : ("",""); my ($N, $V, $C) = ($p[0] =~ m/(.*)\#(.*)\.pkg\.tar\.(bz2|gz|lz|xz|zstd)$/) ? ($1, $2, $3) : ("","","");
($type ne "light") or return ('name' => $N); ($type ne "light") or return ('name' => $N);
my $R = ($V =~ m/^.*-(\w*)\.pkg\.tar.*/) ? $1 : 0; my $R = ($V =~ m/^.*-(\w)$/) ? $1 : 0;
$V =~ s/-\w*\.pkg\.tar.*//; $V =~ s/-\w$//;
my %pkg = ( 'name' => $N, 'version' => $V, 'release' => $R); my %pkg = ( 'name' => $N, 'version' => $V, 'release' => $R, 'compression' => $C );
if (not $_[2]) {$_[2] = $_[1]}; if (not $_[2]) {$_[2] = $_[1]};
$pkg{'path'} = $_[1]; $pkg{'path'} = $_[1];
$pkg{'url'} = $_[2]; $pkg{'url'} = $_[2];
@ -338,16 +329,16 @@ sub getpackage {
$found = 1; $found = 1;
push @maybe, join("^", $pkg{'path'}, $pkg{'url'}, push @maybe, join("^", $pkg{'path'}, $pkg{'url'},
$pkg{'version'}, $pkg{'release'}, $pkg{'description'}, $pkg{'version'}, $pkg{'release'}, $pkg{'description'},
$pkg{'md5sum'}, $pkg{'size'}, $pkg{'md5sum'}, $pkg{'size'}, $pkg{'compression'},
$pkg{'pre_install'}, $pkg{'post_install'}, $pkg{'readme'}); $pkg{'pre_install'}, $pkg{'post_install'}, $pkg{'readme'});
$repver{$pkgname} = "$pkg{'version'}-$pkg{'release'}"; $repver{$pkgname} = "$pkg{'version'}-$pkg{'release'}";
} }
close (REPO); close (REPO);
while (my $match = shift @maybe) { while (my $match = shift @maybe) {
my ($p,$u,$v,$r,$d,$m,$s,$E,$O,$R) = split /\^/, $match; my ($p,$u,$v,$r,$d,$m,$s,$C,$E,$O,$R) = split /\^/, $match;
next if ("$v-$r" ne $repver{$pkgname}); next if ("$v-$r" ne $repver{$pkgname});
%res = ('name' => $pkgname, 'path' => $p, %res = ('name' => $pkgname, 'path' => $p, 'url' => $u,
'url' => $u, 'version' => $v, 'release' => $r, 'version' => $v, 'release' => $r, 'compression' => $C,
'description' => $d, 'md5sum' => $m, 'size' => $s, 'description' => $d, 'md5sum' => $m, 'size' => $s,
'pre_install' => $E, 'post_install' => $O, 'readme' => $R); 'pre_install' => $E, 'post_install' => $O, 'readme' => $R);
} }
@ -396,7 +387,7 @@ sub getdependencies {
sub downloadpkg { sub downloadpkg {
my %pkg = @_; my %pkg = @_;
my $url = $pkg{'url'}; $url =~ s/\#/\%23/; my $url = $pkg{'url'}; $url =~ s/\#/\%23/;
my $fullpath = $pkg{'path'}."/".$pkg{'name'}."#".$pkg{'version'}."-".$pkg{'release'}.".pkg.tar.$compress"; my $fullpath = $pkg{'path'}."/".$pkg{'name'}."#".$pkg{'version'}."-".$pkg{'release'}.".pkg.tar.".$pkg{'compression'};
return 0 if (($url eq "") and (! -f $fullpath)); # repo is local and pkg does not exist return 0 if (($url eq "") and (! -f $fullpath)); # repo is local and pkg does not exist
my $downloadcmd = "curl --retry 3 --retry-delay 3 -o $fullpath $url"; my $downloadcmd = "curl --retry 3 --retry-delay 3 -o $fullpath $url";
(! $force_reinst) or system ($downloadcmd) == 0 or return 0; (! $force_reinst) or system ($downloadcmd) == 0 or return 0;
@ -421,7 +412,7 @@ sub installpkg {
if ($force){$aa = $aa."-f ";} if ($force){$aa = $aa."-f ";}
if ($root ne "") {$aa = $aa."-r ".$root." ";} if ($root ne "") {$aa = $aa."-r ".$root." ";}
if ($install_scripts or $pre_install) {doscript("pre",%pkg);} if ($install_scripts or $pre_install) {doscript("pre",%pkg);}
my $fullpath = $pkg{'path'}."/".$pkg{'name'}."#".$pkg{'version'}."-".$pkg{'release'}.".pkg.tar.$compress"; my $fullpath = $pkg{'path'}."/".$pkg{'name'}."#".$pkg{'version'}."-".$pkg{'release'}.".pkg.tar.".$pkg{'compression'};
print "pkg-get: /usr/bin/pkgadd $upgrade $aa$fullpath\n"; print "pkg-get: /usr/bin/pkgadd $upgrade $aa$fullpath\n";
system ("/usr/bin/pkgadd $upgrade $aa$fullpath") == 0 or return 0; system ("/usr/bin/pkgadd $upgrade $aa$fullpath") == 0 or return 0;
if ($install_scripts or $post_install) {doscript("post",%pkg);} if ($install_scripts or $post_install) {doscript("post",%pkg);}
@ -745,7 +736,7 @@ sub dup {
my %pkg = parsepackage("full",$_, $dir, $url); my %pkg = parsepackage("full",$_, $dir, $url);
$found{$pkg{'name'}} .= "###$pkg{'path'}/$pkg{'name'}#" $found{$pkg{'name'}} .= "###$pkg{'path'}/$pkg{'name'}#"
. "$pkg{'version'}-$pkg{'release'}" . "$pkg{'version'}-$pkg{'release'}"
. ".pkg.tar.$compress"; . ".pkg.tar.$pkg{'compression'}";
} }
close(REPO); close(REPO);
} }

View File

@ -2,7 +2,7 @@
# #
# pkg-repgen: generates a binary repository for pkg-get # pkg-repgen: generates a binary repository for pkg-get
# #
# requires prt-get # requires prt-get and portspage
# #
# html index generation code adapted from Jukka Heino's portspage # html index generation code adapted from Jukka Heino's portspage
# #
@ -32,18 +32,18 @@ $prtget .= " --no-std-config --config-set=\"prtdir $prtdir\"" if ($prtdir);
my @packages; my %isDup; my @packages; my %isDup;
sub pkg_mtime { sub pkg_mtime {
my $aName = $a; my $bName = $b; my $aName = $a; my $bName = $b;
my $aTime; my $bTime; my $aTime; my $bTime;
$aName =~ s/#.*//; $aName =~ s/#.*//;
$bName =~ s/#.*//; $bName =~ s/#.*//;
if ($aName lt $bName) { return -1; } if ($aName lt $bName) { return -1; }
elsif ($aName gt $bName) { return 1; } elsif ($aName gt $bName) { return 1; }
else { else {
$aTime = (stat $a)[9]; $aTime = (stat $a)[9];
$bTime = (stat $b)[9]; $bTime = (stat $b)[9];
} }
if ($aTime le $bTime) { return -1; } if ($aTime le $bTime) { return -1; }
else { return 1; } else { return 1; }
} }
my $pkgdir = shift @ARGV; my $quickMode=0; my $pkgdir = shift @ARGV; my $quickMode=0;
@ -132,19 +132,19 @@ sub pkg_single {
print $nR "$oline\n" if ($oname lt $pname{$p}); print $nR "$oline\n" if ($oname lt $pname{$p});
# before breaking out of the loop, append all the packages # before breaking out of the loop, append all the packages
# from the globbed queue that are lexographically earlier # from the globbed queue that are lexographically earlier
# than the current entry in the old repository. # than the current entry in the old repository.
while ($pname{$p} le $oname) { while ($pname{$p} le $oname) {
printf $nR "%-s:%-s:%-s:%-s:%-s\n", $basename, $du, $md5, $desc, $ppr; printf $nR "%-s:%-s:%-s:%-s:%-s\n", $basename, $du, $md5, $desc, $ppr;
next RPKG if (! $isDup{$p}); next RPKG if (! $isDup{$p});
$p = shift @packages; $p = shift @packages;
($basename, $du, $md5, $ppr) = repodata($p); ($basename, $du, $md5, $ppr) = repodata($p);
$desc = (! $descrip{$pname{$p}}) ? "N.A." : $descrip{$pname{$p}}; $desc = (! $descrip{$pname{$p}}) ? "N.A." : $descrip{$pname{$p}};
# save what got shifted from the repository if we're not going to # 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. # print it now, but don't save packages that match the same glob.
$followR{$pname{$p}} = "$oline\n" if ($pname{$p} lt $oname); $followR{$pname{$p}} = "$oline\n" if ($pname{$p} lt $oname);
} }
} }
# if the current package comes after everything in the old repository, # if the current package comes after everything in the old repository,
@ -163,7 +163,7 @@ sub pkg_single {
$followR{$pname{$packages[0]}} = $followR{$pname{$p}}; $followR{$pname{$packages[0]}} = $followR{$pname{$p}};
next RPKG; next RPKG;
} else { } else {
print $nR $followR{$pname{$p}}; print $nR $followR{$pname{$p}};
} }
# Shift another package from the queue # Shift another package from the queue
@ -180,7 +180,7 @@ sub pkg_single {
if ($firstrun{"index.html"} == 1) { if ($firstrun{"index.html"} == 1) {
$count++; $count++;
htmlrow($nH,$count,$pname{$p},$url,$pver,$desc,$date); htmlrow($nH,$count,$pname{$p},$url,$pver,$desc,$date);
next HPKG; next HPKG;
} }
# Shift entries from the old html index until we find # Shift entries from the old html index until we find
# a successor to the current package. # a successor to the current package.
@ -194,19 +194,19 @@ sub pkg_single {
if ($oname lt $pname{$p}) { $count++; print $nH "$oline\n"; } if ($oname lt $pname{$p}) { $count++; print $nH "$oline\n"; }
# before breaking out of the loop, append all the packages # before breaking out of the loop, append all the packages
# from the globbed queue that are lexographically earlier # from the globbed queue that are lexographically earlier
# than the current entry in the old html index. # than the current entry in the old html index.
while ($pname{$p} le $oname) { while ($pname{$p} le $oname) {
$count++; $count++;
htmlrow($nH,$count,$pname{$p},$url,$pver,$desc,$date); htmlrow($nH,$count,$pname{$p},$url,$pver,$desc,$date);
next HPKG if (! $isDup{$p}); next HPKG if (! $isDup{$p});
$p = shift @idx_packages; $p = shift @idx_packages;
($url, $pver, $desc, $date) = htmldata($p); ($url, $pver, $desc, $date) = htmldata($p);
# save what got shifted from the index if we're not going to print # save what got shifted from the index if we're not going to print
# it now, but ignore packages that match the same glob. # it now, but ignore packages that match the same glob.
$followH{$pname{$p}} = "$oline\n" if ($pname{$p} lt $oname); $followH{$pname{$p}} = "$oline\n" if ($pname{$p} lt $oname);
} }
} }
# if the current package comes after everything in the old html index, # if the current package comes after everything in the old html index,
@ -252,17 +252,17 @@ sub pkg_single {
chomp($oline); $oname = $oline; chomp($oline); $oname = $oline;
$oname =~ s/\s*\:.*//; $oname =~ s/\s*\:.*//;
print $nD "$oline\n" if ($oname lt $pname{$p}); print $nD "$oline\n" if ($oname lt $pname{$p});
while ($pname{$p} le $oname) { while ($pname{$p} le $oname) {
if (! $isDup{$p}) { if (! $isDup{$p}) {
printf $nD "%-30s : %-s\n", $pname{$p}, $depends{$pname{$p}}; printf $nD "%-30s : %-s\n", $pname{$p}, $depends{$pname{$p}};
next DPKG; next DPKG;
} else { } else {
$p = shift @dep_packages; $p = shift @dep_packages;
} }
# save what got shifted from the depmap if we're not going to print # save what got shifted from the depmap if we're not going to print
# it now, but ignore packages that match the same glob. # it now, but ignore packages that match the same glob.
$followD{$pname{$p}} = $oline if ($pname{$p} lt $oname); $followD{$pname{$p}} = $oline if ($pname{$p} lt $oname);
} }
} }
# if the current package comes after everything in the old depmap # if the current package comes after everything in the old depmap
@ -278,10 +278,10 @@ sub pkg_single {
# Decide which of the two possible successors comes first. If it's the # Decide which of the two possible successors comes first. If it's the
# globbed package that comes next, save the old depmap entry. # globbed package that comes next, save the old depmap entry.
if ((@packages) and ($pname{$packages[0]} le $followD{$pname{$p}})) { if ((@packages) and ($pname{$packages[0]} le $followD{$pname{$p}})) {
$followD{$pname{$packages[0]}} = $followD{$pname{$p}}; $followD{$pname{$packages[0]}} = $followD{$pname{$p}};
next DPKG; next DPKG;
} else { } else {
printf $nD $followD{$pname{$p}}; printf $nD $followD{$pname{$p}};
} }
# Shift another package from the queue # Shift another package from the queue
@ -289,10 +289,13 @@ sub pkg_single {
# Done with all the packages that match command-line arguments. # Done with all the packages that match command-line arguments.
# Now append the tails of the old metadata files to their new counterparts. # Now append the tails of the old metadata files to their new counterparts.
# Remember to update the count, in case new packages were inserted.
while ($firstrun{"index.html"}==0 and $oline = <$oH>) { while ($firstrun{"index.html"}==0 and $oline = <$oH>) {
$count++; if ($oline =~ m/class="(even|odd)"/) {
$oline =~ s/class="(even|odd)"/class="$parity{($count % 2)}"/; $count++;
print $nH $oline; $oline =~ s/class="(even|odd)"/class="$parity{($count % 2)}"/;
print $nH $oline;
}
} }
while ($firstrun{"PKGDEPS"}==0 and $oline = <$oD>) { print $nD $oline; } while ($firstrun{"PKGDEPS"}==0 and $oline = <$oD>) { print $nD $oline; }
while ($firstrun{"PKGREPO"}==0 and $oline = <$oR>) { print $nR $oline; } while ($firstrun{"PKGREPO"}==0 and $oline = <$oR>) { print $nR $oline; }
@ -305,7 +308,7 @@ sub pkg_single {
($firstrun{"index.html"}==1) or close($oH); ($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); printfooter($count);
} }
######################## full repository ######################## ######################## full repository ########################
@ -319,7 +322,7 @@ sub pkg_dir {
open (my $ih, ">>$pkgdir/index.html"); open (my $ih, ">>$pkgdir/index.html");
foreach my $p (@packages) { foreach my $p (@packages) {
my ($basename, $du, $md5, $ppr) = repodata($p); my ($basename, $du, $md5, $ppr) = repodata($p);
my ($url, $pver, $desc, $date) = htmldata($p); my ($url, $pver, $desc, $date) = htmldata($p);
(! $depends{$pname{$p}}) or ($isDup{$p}) (! $depends{$pname{$p}}) or ($isDup{$p})
or printf $iD "%-30s : %-s\n", $pname{$p}, $depends{$pname{$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; printf $iR "%-s:%-s:%-s:%-s:%-s\n", $basename,$du,$md5,$desc,$ppr;
@ -351,9 +354,9 @@ run_script() {
my %seen; my %seen;
foreach my $name (@dirlist) { foreach my $name (@dirlist) {
$name =~ s/\#.*//; $name = (split /\//, $name)[-1]; $name =~ s/\#.*//; $name = (split /\//, $name)[-1];
next if ($seen{$name}); next if ($seen{$name});
$seen{$name} = 1; $seen{$name} = 1;
next if (! $path{$name}); next if (! $path{$name});
if (-f "$path{$name}/README"){ if (-f "$path{$name}/README"){
print $fR "##### PKGREADME: $name\n"; print $fR "##### PKGREADME: $name\n";
open(my $readme, "$path{$name}/README"); open(my $readme, "$path{$name}/README");
@ -383,57 +386,17 @@ run_script() {
######################## html index subs ######################## ######################## html index subs ########################
sub printheader { sub printheader {
my $isTemp = shift; my $ih; my $isTemp = shift; my $ih; my $fS;
my $stylePage = "/usr/share/portspage/style.html";
($isTemp == 0) ? open ($ih, ">$pkgdir/index.html") : open ($ih, ">$pkgdir/index.html.new"); ($isTemp == 0) ? open ($ih, ">$pkgdir/index.html") : open ($ih, ">$pkgdir/index.html.new");
print $ih <<EOH; open ($fS, $stylePage) or die "cannot find html template. Please install or update prt-utils.";
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" while (my $sline = <$fS>) {
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> if ($sline =~ m/<(title|h[1-3])>/) {
<html xmlns="http://www.w3.org/1999/xhtml"> $sline =~ s/(title|h[1-3])>[^<]*</$1>$title</;
<head> }
EOH print $ih $sline;
}
print $ih " <title>$title</title>\n";
print $ih <<EOH;
<style type="text/css">
body
{
font-family: Verdana, sans-serif;
font-size: 85%;
padding: 2em;
}
a
{
color: #67550d;
}
table
{
border: solid #e5dccf 1px;
font-size: 85%;
}
td
{
padding: 6px;
}
tr.header
{
background-color: #e5dccf;
}
tr.odd
{
background-color: #f7f3ed;
}
tr.even
{
background-color: #fcf9f8;
}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
</head>
<body>
EOH
print $ih " <h2>$title</h2>\n";
if ($header) { if ($header) {
open(FILE, $header) or die "Couldn't open header file"; open(FILE, $header) or die "Couldn't open header file";
while (<FILE>) { print $ih " " . $_; } while (<FILE>) { print $ih " " . $_; }
@ -464,7 +427,7 @@ sub printfooter {
while (<FILE>) { print $ih " " . $_; } while (<FILE>) { print $ih " " . $_; }
close(FILE); close(FILE);
} }
print $ih " <p><i>Generated by <a href=\"http://www.varlock.com\">pkg-repgen</a> on " . isotime() . ".</i></p>\n"; print $ih " <p><em>Generated by <a href=\"http://www.varlock.com\">pkg-repgen</a> on " . isotime() . ".</em></p>\n";
print $ih <<EOH; print $ih <<EOH;
</body> </body>
</html> </html>
@ -477,7 +440,7 @@ sub htmldata {
my ($pver, $url) = ($p, $p); my ($pver, $url) = ($p, $p);
$pver =~ s/.*\#//; $pver =~ s/\.pkg\.tar.*//; $pver =~ s/.*\#//; $pver =~ s/\.pkg\.tar.*//;
$url = (split /\//, $p)[-1]; $url =~ s/\#/\%23/; $url = (split /\//, $p)[-1]; $url =~ s/\#/\%23/;
my $date = isotime( (stat($p))[9], 1); my $date = isotime( (stat($p))[9] );
my $desc = (! $descrip{$pname{$p}}) ? "N.A." : $descrip{$pname{$p}}; my $desc = (! $descrip{$pname{$p}}) ? "N.A." : $descrip{$pname{$p}};
return $url, $pver, $desc, $date; return $url, $pver, $desc, $date;
} }
@ -493,12 +456,10 @@ sub repodata {
sub isotime { sub isotime {
my $time = (shift or time); my $time = (shift or time);
my $accuracy = (shift or 2);
my @t = gmtime ($time); my @t = gmtime ($time);
my $year = $t[5] + 1900; my $year = $t[5] + 1900;
my $month = sprintf("%02d", $t[4] + 1); my $month = sprintf("%02d", $t[4] + 1);
my $day = sprintf("%02d", $t[3]); my $day = sprintf("%02d", $t[3]);
return "$year-$month-$day" if ($accuracy == 1); return "$year-$month-$day";
return "$year-$month-$day " . sprintf("%02d:%02d:%02d UTC", $t[2], $t[1], $t[0]);
} }