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,
"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) {
$LOCKFILE = $root.$LOCKFILE ;
$PKGDB = $root.$PKGDB;
@ -159,11 +150,11 @@ sub get_locked {
sub parsepackage {
my $type=shift; my @p = split(/\:/, $_[0]);
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);
my $R = ($V =~ m/^.*-(\w*)\.pkg\.tar.*/) ? $1 : 0;
$V =~ s/-\w*\.pkg\.tar.*//;
my %pkg = ( 'name' => $N, 'version' => $V, 'release' => $R);
my $R = ($V =~ m/^.*-(\w)$/) ? $1 : 0;
$V =~ s/-\w$//;
my %pkg = ( 'name' => $N, 'version' => $V, 'release' => $R, 'compression' => $C );
if (not $_[2]) {$_[2] = $_[1]};
$pkg{'path'} = $_[1];
$pkg{'url'} = $_[2];
@ -338,16 +329,16 @@ sub getpackage {
$found = 1;
push @maybe, join("^", $pkg{'path'}, $pkg{'url'},
$pkg{'version'}, $pkg{'release'}, $pkg{'description'},
$pkg{'md5sum'}, $pkg{'size'},
$pkg{'md5sum'}, $pkg{'size'}, $pkg{'compression'},
$pkg{'pre_install'}, $pkg{'post_install'}, $pkg{'readme'});
$repver{$pkgname} = "$pkg{'version'}-$pkg{'release'}";
}
close (REPO);
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});
%res = ('name' => $pkgname, 'path' => $p,
'url' => $u, 'version' => $v, 'release' => $r,
%res = ('name' => $pkgname, 'path' => $p, 'url' => $u,
'version' => $v, 'release' => $r, 'compression' => $C,
'description' => $d, 'md5sum' => $m, 'size' => $s,
'pre_install' => $E, 'post_install' => $O, 'readme' => $R);
}
@ -396,7 +387,7 @@ sub getdependencies {
sub downloadpkg {
my %pkg = @_;
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
my $downloadcmd = "curl --retry 3 --retry-delay 3 -o $fullpath $url";
(! $force_reinst) or system ($downloadcmd) == 0 or return 0;
@ -421,7 +412,7 @@ sub installpkg {
if ($force){$aa = $aa."-f ";}
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";
my $fullpath = $pkg{'path'}."/".$pkg{'name'}."#".$pkg{'version'}."-".$pkg{'release'}.".pkg.tar.".$pkg{'compression'};
print "pkg-get: /usr/bin/pkgadd $upgrade $aa$fullpath\n";
system ("/usr/bin/pkgadd $upgrade $aa$fullpath") == 0 or return 0;
if ($install_scripts or $post_install) {doscript("post",%pkg);}
@ -745,7 +736,7 @@ sub dup {
my %pkg = parsepackage("full",$_, $dir, $url);
$found{$pkg{'name'}} .= "###$pkg{'path'}/$pkg{'name'}#"
. "$pkg{'version'}-$pkg{'release'}"
. ".pkg.tar.$compress";
. ".pkg.tar.$pkg{'compression'}";
}
close(REPO);
}

View File

@ -2,7 +2,7 @@
#
# 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
#
@ -289,11 +289,14 @@ sub pkg_single {
# Done with all the packages that match command-line arguments.
# 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>) {
if ($oline =~ m/class="(even|odd)"/) {
$count++;
$oline =~ s/class="(even|odd)"/class="$parity{($count % 2)}"/;
print $nH $oline;
}
}
while ($firstrun{"PKGDEPS"}==0 and $oline = <$oD>) { print $nD $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);
foreach my $db (keys %firstrun) { rename("$pkgdir/$db.new", "$pkgdir/$db"); }
printfooter($count) if ($firstrun{"index.html"} == 1);
printfooter($count);
}
######################## full repository ########################
@ -383,57 +386,17 @@ run_script() {
######################## html index subs ########################
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");
print $ih <<EOH;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
EOH
open ($fS, $stylePage) or die "cannot find html template. Please install or update prt-utils.";
while (my $sline = <$fS>) {
if ($sline =~ m/<(title|h[1-3])>/) {
$sline =~ s/(title|h[1-3])>[^<]*</$1>$title</;
}
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) {
open(FILE, $header) or die "Couldn't open header file";
while (<FILE>) { print $ih " " . $_; }
@ -464,7 +427,7 @@ sub printfooter {
while (<FILE>) { print $ih " " . $_; }
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;
</body>
</html>
@ -477,7 +440,7 @@ sub htmldata {
my ($pver, $url) = ($p, $p);
$pver =~ s/.*\#//; $pver =~ s/\.pkg\.tar.*//;
$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}};
return $url, $pver, $desc, $date;
}
@ -493,12 +456,10 @@ sub repodata {
sub isotime {
my $time = (shift or time);
my $accuracy = (shift or 2);
my @t = gmtime ($time);
my $year = $t[5] + 1900;
my $month = sprintf("%02d", $t[4] + 1);
my $day = sprintf("%02d", $t[3]);
return "$year-$month-$day" if ($accuracy == 1);
return "$year-$month-$day " . sprintf("%02d:%02d:%02d UTC", $t[2], $t[1], $t[0]);
return "$year-$month-$day";
}