From deaa06e52c73f24c194259296964ebfe6d1605b7 Mon Sep 17 00:00:00 2001 From: John McQuah Date: Mon, 22 Apr 2024 20:53:01 +0000 Subject: [PATCH] pkg-repgen: use the html template installed by portspage pkg-get: infer compression mode from the remote filename, not from the local pkgmk.conf --- scripts/pkg-get.pl | 31 +++------ scripts/pkg-repgen.pl | 153 ++++++++++++++++-------------------------- 2 files changed, 68 insertions(+), 116 deletions(-) diff --git a/scripts/pkg-get.pl b/scripts/pkg-get.pl index 5375aca..4c235a7 100755 --- a/scripts/pkg-get.pl +++ b/scripts/pkg-get.pl @@ -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 () { - $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); } diff --git a/scripts/pkg-repgen.pl b/scripts/pkg-repgen.pl index 7bbad0e..1334927 100755 --- a/scripts/pkg-repgen.pl +++ b/scripts/pkg-repgen.pl @@ -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 # @@ -32,18 +32,18 @@ $prtget .= " --no-std-config --config-set=\"prtdir $prtdir\"" if ($prtdir); my @packages; my %isDup; sub pkg_mtime { - my $aName = $a; my $bName = $b; - my $aTime; my $bTime; - $aName =~ s/#.*//; - $bName =~ s/#.*//; - if ($aName lt $bName) { return -1; } - elsif ($aName gt $bName) { return 1; } - else { - $aTime = (stat $a)[9]; - $bTime = (stat $b)[9]; - } - if ($aTime le $bTime) { return -1; } - else { return 1; } + my $aName = $a; my $bName = $b; + my $aTime; my $bTime; + $aName =~ s/#.*//; + $bName =~ s/#.*//; + if ($aName lt $bName) { return -1; } + elsif ($aName gt $bName) { return 1; } + else { + $aTime = (stat $a)[9]; + $bTime = (stat $b)[9]; + } + if ($aTime le $bTime) { return -1; } + else { return 1; } } my $pkgdir = shift @ARGV; my $quickMode=0; @@ -132,19 +132,19 @@ sub pkg_single { print $nR "$oline\n" if ($oname lt $pname{$p}); # 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. - 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; + 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 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); - } + } } # 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}}; next RPKG; } else { - print $nR $followR{$pname{$p}}; + print $nR $followR{$pname{$p}}; } # Shift another package from the queue @@ -180,7 +180,7 @@ sub pkg_single { if ($firstrun{"index.html"} == 1) { $count++; htmlrow($nH,$count,$pname{$p},$url,$pver,$desc,$date); - next HPKG; + next HPKG; } # Shift entries from the old html index until we find # a successor to the current package. @@ -194,19 +194,19 @@ sub pkg_single { 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 + # 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; + 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. + # 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, @@ -252,17 +252,17 @@ sub pkg_single { chomp($oline); $oname = $oline; $oname =~ s/\s*\:.*//; print $nD "$oline\n" if ($oname lt $pname{$p}); - while ($pname{$p} le $oname) { - if (! $isDup{$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; + $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. + # 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 @@ -278,10 +278,10 @@ sub pkg_single { # 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; + $followD{$pname{$packages[0]}} = $followD{$pname{$p}}; + next DPKG; } else { - printf $nD $followD{$pname{$p}}; + printf $nD $followD{$pname{$p}}; } # Shift another package from the queue @@ -289,10 +289,13 @@ 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>) { - $count++; - $oline =~ s/class="(even|odd)"/class="$parity{($count % 2)}"/; - print $nH $oline; + 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 ######################## @@ -319,7 +322,7 @@ sub pkg_dir { open (my $ih, ">>$pkgdir/index.html"); foreach my $p (@packages) { 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}) or printf $iD "%-30s : %-s\n", $pname{$p}, $depends{$pname{$p}}; printf $iR "%-s:%-s:%-s:%-s:%-s\n", $basename,$du,$md5,$desc,$ppr; @@ -351,9 +354,9 @@ run_script() { my %seen; foreach my $name (@dirlist) { $name =~ s/\#.*//; $name = (split /\//, $name)[-1]; - next if ($seen{$name}); + next if ($seen{$name}); $seen{$name} = 1; - next if (! $path{$name}); + next if (! $path{$name}); if (-f "$path{$name}/README"){ print $fR "##### PKGREADME: $name\n"; open(my $readme, "$path{$name}/README"); @@ -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 + 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])>[^<]*$title$title\n"; - - print $ih < - 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; - } - - - - -EOH - - print $ih "

$title

\n"; if ($header) { open(FILE, $header) or die "Couldn't open header file"; while () { print $ih " " . $_; } @@ -464,7 +427,7 @@ sub printfooter { while () { print $ih " " . $_; } close(FILE); } - print $ih "

Generated by pkg-repgen on " . isotime() . ".

\n"; + print $ih "

Generated by pkg-repgen on " . isotime() . ".

\n"; print $ih < @@ -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"; }