2006-07-12 22:21:42 -04:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
#
|
|
|
|
# pkg-repgen: generates a binary repository for pkg-get
|
|
|
|
#
|
|
|
|
# requires prt-get
|
|
|
|
#
|
|
|
|
# html index generation code adapted from Jukka Heino's portspage
|
|
|
|
#
|
|
|
|
# usage: pkg-repgen [<pkgname1>..<pkgnameN>]
|
|
|
|
#
|
|
|
|
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
|
|
|
use Getopt::Long;
|
2023-06-17 11:24:34 -04:00
|
|
|
use Digest::file qw(digest_file_hex);
|
2006-07-12 22:21:42 -04:00
|
|
|
|
2013-08-20 06:55:15 -04:00
|
|
|
our $prtget = "/usr/bin/prt-get"; our $prtdir;
|
2006-07-12 22:21:42 -04:00
|
|
|
our $title = "CRUX Packages"; our $header; our $footer;
|
2013-08-20 06:55:15 -04:00
|
|
|
GetOptions("prtdir=s"=>\$prtdir, "title=s"=>\$title, "header=s"=>\$header, "footer=s"=>\$footer);
|
2006-07-12 22:21:42 -04:00
|
|
|
|
2013-07-04 11:39:58 -04:00
|
|
|
# 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>) {
|
2023-06-18 18:25:55 -04:00
|
|
|
$compress = $1 if m/^PKGMK_COMPRESSION_MODE=(.*)(\#|$)/;
|
2013-07-04 11:39:58 -04:00
|
|
|
}
|
|
|
|
close CONFIG;
|
2023-06-17 11:24:34 -04:00
|
|
|
$compress =~ s/["' ]//g;
|
2013-07-04 11:39:58 -04:00
|
|
|
|
2023-06-17 11:24:34 -04:00
|
|
|
$prtget .= " --no-std-config --config-set=\"prtdir $prtdir\"" if ($prtdir);
|
|
|
|
|
|
|
|
my @dirlist = glob("*#*.pkg.tar.$compress"); my @packages;
|
2006-07-12 22:21:42 -04:00
|
|
|
if ($#ARGV >= 0) { # single packages
|
2023-06-17 11:24:34 -04:00
|
|
|
foreach my $pkgname (@ARGV) {
|
2023-06-18 18:25:55 -04:00
|
|
|
my @hits = sort grep { /^$pkgname\#/ } @dirlist;
|
|
|
|
push(@packages,$hits[-1]) if (@hits);
|
2013-08-20 06:55:15 -04:00
|
|
|
}
|
2023-06-17 11:24:34 -04:00
|
|
|
} else {
|
|
|
|
@packages = @dirlist;
|
2006-07-12 22:21:42 -04:00
|
|
|
}
|
|
|
|
|
2023-06-18 18:25:55 -04:00
|
|
|
# Populate hashes using a single run of prt-get
|
2023-06-17 11:24:34 -04:00
|
|
|
our %path; our %depends; our %descrip; our %flags;
|
2023-06-18 18:25:55 -04:00
|
|
|
my @validkeys = @dirlist;
|
|
|
|
map { s/\#.*// } @validkeys;
|
|
|
|
my %printme = map { $_ => 1 } @validkeys;
|
|
|
|
open (my $ppf, "$prtget printf '%n^%p^%e^%d^%E:%O:%R\n' |");
|
|
|
|
while (<$ppf>) {
|
|
|
|
chomp;
|
|
|
|
my ($name,$repo,$deps,$desc,$prepostread) = split /\^/;
|
|
|
|
next if (! $printme{$name});
|
|
|
|
$path{$name} = $repo . "/" . $name;
|
|
|
|
$depends{$name} = $deps;
|
|
|
|
$desc =~ s/\:/ /g;
|
|
|
|
$descrip{$name} = $desc;
|
|
|
|
$flags{$name} = $prepostread;
|
2023-06-17 11:24:34 -04:00
|
|
|
}
|
2023-06-18 18:25:55 -04:00
|
|
|
close ($ppf);
|
2023-06-17 11:24:34 -04:00
|
|
|
|
2023-06-18 18:25:55 -04:00
|
|
|
# Needed for alternating colors in the html index
|
|
|
|
my %parity = ( 0 => "even", 1 => "odd" );
|
2023-06-17 11:24:34 -04:00
|
|
|
|
2023-06-18 18:25:55 -04:00
|
|
|
# Generate the metadata files
|
|
|
|
($#ARGV >= 0) ? pkg_single() : pkg_dir();
|
2023-06-17 11:24:34 -04:00
|
|
|
|
2023-06-18 18:25:55 -04:00
|
|
|
# Generate README and PKGINST
|
|
|
|
pkgreadscripts();
|
2006-07-12 22:21:42 -04:00
|
|
|
|
2023-06-18 18:25:55 -04:00
|
|
|
######################## individual packages ########################
|
2023-06-17 11:24:34 -04:00
|
|
|
sub pkg_single {
|
2023-06-18 18:25:55 -04:00
|
|
|
my ($pname, $dbO, $oname, $pdeps, $desc, $du, $md5, $ppr);
|
|
|
|
my $count = 0; my ($pver, $url, $date); # needed for the html index
|
|
|
|
|
|
|
|
foreach my $db ("PKGREPO", "PKGDEPS", "index.html") {
|
|
|
|
my $firstrun = 0; my $dbNew;
|
2023-06-17 11:24:34 -04:00
|
|
|
my $status = "+ Generating ";
|
2023-06-18 18:25:55 -04:00
|
|
|
if ($db eq "PKGREPO") {
|
|
|
|
$status .= "repository\n";
|
|
|
|
} elsif ($db eq "PKGDEPS") {
|
|
|
|
$status .= "dependencies\n";
|
|
|
|
} else {
|
|
|
|
$status .= "html index\n";
|
|
|
|
}
|
2023-06-17 11:24:34 -04:00
|
|
|
print $status;
|
2023-06-18 18:25:55 -04:00
|
|
|
open (my $dbOld, "$db") or $firstrun=1;
|
|
|
|
if ( ($firstrun == 1) and ($db eq "index.html") ) {
|
|
|
|
printheader();
|
|
|
|
rename($db, "$db.new");
|
|
|
|
open ($dbNew, ">>$db.new");
|
|
|
|
} else {
|
|
|
|
open ($dbNew, ">$db.new");
|
|
|
|
}
|
|
|
|
|
|
|
|
PACKAGE: foreach my $p (sort @packages) {
|
|
|
|
$count++ if ($db eq "index.html");
|
|
|
|
$pname = $p; $pver = $p;
|
|
|
|
$pname =~ s/#.*//; $pver =~ s/.*#(.*)\.pkg\.tar\.*/$1/;
|
|
|
|
if ($db eq "PKGREPO") {
|
|
|
|
$du = (-s $p);
|
|
|
|
$md5 = digest_file_hex($p,"MD5");
|
|
|
|
$desc = (! $descrip{$pname}) ? "N.A." : $descrip{$pname};
|
|
|
|
$ppr = (! $flags{$pname}) ? "no:no:no" : $flags{$pname};
|
|
|
|
printf $dbNew "%-s:%-s:%-s:%-s:%-s\n",
|
|
|
|
$p, $du, $md5, $desc, $ppr if ($firstrun == 1);
|
|
|
|
} elsif ($db eq "PKGDEPS") {
|
|
|
|
$pdeps = (! $depends{$pname}) ? "" : $depends{$pname};
|
|
|
|
printf $dbNew "%-30s:%s\n", $pname, $pdeps if ($firstrun == 1);
|
|
|
|
} else {
|
|
|
|
$date = isotime( (stat($p))[9], 1);
|
|
|
|
$url = $p;
|
|
|
|
$url =~ s/\#/\%23/;
|
|
|
|
htmlrow($dbNew,$parity{($count % 2)},$pname,$url,$pver,
|
|
|
|
$descrip{$pname},$date) if ($firstrun == 1);
|
|
|
|
}
|
|
|
|
next PACKAGE if ($firstrun == 1);
|
|
|
|
while ($dbO = <$dbOld>) {
|
|
|
|
chomp($dbO);
|
|
|
|
if (($db eq "index.html") and ($dbO !~ m/^<tr class/)) {
|
|
|
|
# Try to ensure that header lines are copied verbatim,
|
|
|
|
# by exploiting the alphabetical sorting below.
|
|
|
|
# Not guaranteed to work with every locale!
|
|
|
|
$oname = " 0";
|
|
|
|
} else {
|
|
|
|
# should be able to extract the old pkg name from this line
|
|
|
|
$oname = $dbO;
|
|
|
|
$oname =~ s/\s*\:.*// if ($db eq "PKGDEPS");
|
|
|
|
$oname =~ s/(.*)\#.*pkg\.tar.*/$1/ if ($db eq "PKGREPO");
|
|
|
|
$oname =~ s/.*a href="(.*)\%23.*/$1/ if ($db eq "index.html");
|
|
|
|
$count++ if ($db eq "index.html");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($oname lt $pname) {
|
|
|
|
print $dbNew "$dbO\n";
|
|
|
|
} elsif (($oname ge $pname) and ($db eq "PKGREPO")) {
|
|
|
|
printf $dbNew "%-s:%-s:%-s:%-s:%-s\n", $p, $du, $md5, $desc, $ppr;
|
|
|
|
} elsif (($oname ge $pname) and ($db eq "PKGDEPS")) {
|
|
|
|
printf $dbNew "%-30s:%s\n", $pname, $pdeps
|
|
|
|
} else {
|
|
|
|
# either overwrite the old entry in the html index,
|
|
|
|
# or insert this entry before the first line that
|
|
|
|
# would come after $p when sorted alphabetically.
|
|
|
|
htmlrow($dbNew,$parity{($count % 2)},$pname,$url,$pver,
|
|
|
|
$descrip{$pname},$date);
|
2023-06-17 11:24:34 -04:00
|
|
|
}
|
2023-06-18 18:25:55 -04:00
|
|
|
print $dbNew "$dbO\n" if ($oname gt $pname);
|
|
|
|
last if ($oname ge $pname);
|
2006-07-12 22:21:42 -04:00
|
|
|
}
|
|
|
|
}
|
2023-06-18 18:25:55 -04:00
|
|
|
while ( ($firstrun != 1) and ($dbO = <$dbOld>) ) {
|
|
|
|
if ($db eq "index.html") {
|
|
|
|
$count++;
|
|
|
|
$dbO =~ s/class="(even|odd)"/class="$parity{($count % 2)}"/;
|
2023-06-17 11:24:34 -04:00
|
|
|
}
|
2023-06-18 18:25:55 -04:00
|
|
|
print $dbNew $dbO;
|
2023-06-17 11:24:34 -04:00
|
|
|
}
|
2023-06-18 18:25:55 -04:00
|
|
|
|
|
|
|
close($dbNew);
|
|
|
|
($firstrun == 1) or close($dbOld);
|
|
|
|
|
|
|
|
rename("$db.new", "$db");
|
|
|
|
printfooter($count) if (($firstrun == 1) and ($db eq "index.html"));
|
|
|
|
}
|
2023-06-17 11:24:34 -04:00
|
|
|
}
|
2006-07-12 22:21:42 -04:00
|
|
|
|
|
|
|
######################## full repository ########################
|
2023-06-17 11:24:34 -04:00
|
|
|
sub pkg_dir {
|
2023-06-18 18:25:55 -04:00
|
|
|
print "+ Generating dependencies\n";
|
|
|
|
open (my $iD, ">PKGDEPS");
|
|
|
|
print "+ Generating repository\n";
|
|
|
|
open (my $iR, ">PKGREPO");
|
|
|
|
printheader();
|
|
|
|
my $count = 0;
|
|
|
|
open (my $ih, '>>index.html');
|
|
|
|
foreach my $p (@packages) {
|
|
|
|
chomp($p);
|
|
|
|
my $date = isotime( (stat($p))[9], 1);
|
|
|
|
$count++;
|
|
|
|
my ($name, $version, $url) = ($p, $p, $p);
|
|
|
|
$name =~ s/\#.*//;
|
|
|
|
$version =~ s/^.*\#//;
|
|
|
|
$version =~ s/\.pkg\.tar\.[gbx]z*//;
|
|
|
|
$url =~ s/\#/\%23/;
|
|
|
|
if (($depends{$name}) and ($depends{$name} ne "")) {
|
|
|
|
printf $iD "%-30s : %-s\n", $name, $depends{$name};
|
2023-06-17 11:24:34 -04:00
|
|
|
}
|
2023-06-18 18:25:55 -04:00
|
|
|
my $du = (-s $p);
|
|
|
|
my $md5 = digest_file_hex($p,"MD5");
|
|
|
|
if (! $descrip{$name}) {$descrip{$name} = "N.A.";}
|
|
|
|
if (! $flags{$name}) { $flags{$name} = "no:no:no"; }
|
|
|
|
printf $iR "%-s:%-s:%-s:%-s:%-s\n", $p,$du,$md5,$descrip{$name},$flags{$name};
|
|
|
|
htmlrow($ih,$parity{($count % 2)},$name,$url, $version,$descrip{$name},$date);
|
2006-07-12 22:21:42 -04:00
|
|
|
}
|
2023-06-18 18:25:55 -04:00
|
|
|
close($ih);
|
|
|
|
printfooter($count);
|
|
|
|
close($iR);
|
|
|
|
close($iD);
|
2006-07-12 22:21:42 -04:00
|
|
|
}
|
|
|
|
|
2023-06-18 18:25:55 -04:00
|
|
|
# consolidate all the README and install scripts for the available packages
|
|
|
|
sub pkgreadscripts {
|
2006-07-12 22:21:42 -04:00
|
|
|
print "+ Generating README\n";
|
2023-06-18 18:25:55 -04:00
|
|
|
open (my $fR, '>PKGREAD');
|
|
|
|
print $fR "# README files for repository. Do NOT remove this line.\n";
|
2006-07-12 22:21:42 -04:00
|
|
|
|
|
|
|
print "+ Generating scripts\n";
|
2023-06-18 18:25:55 -04:00
|
|
|
open (my $fS, '>PKGINST');
|
|
|
|
print $fS '#!/usr/bin/env bash
|
2006-07-12 22:21:42 -04:00
|
|
|
#
|
2023-06-17 11:24:34 -04:00
|
|
|
# PKGINST: pre- and post-install scripts for CRUX packages
|
|
|
|
#
|
|
|
|
run_script() {
|
2023-06-18 18:25:55 -04:00
|
|
|
case "$1" in
|
2023-06-17 11:24:34 -04:00
|
|
|
';
|
2023-06-18 18:25:55 -04:00
|
|
|
|
|
|
|
foreach my $name (sort @dirlist) {
|
|
|
|
$name =~ s/\#.*//;
|
|
|
|
if (-f "$path{$name}/README"){
|
|
|
|
print $fR "##### PKGREADME: $name\n";
|
|
|
|
open(my $readme, "$path{$name}/README");
|
|
|
|
while (<$readme>){ print $fR $_; }
|
|
|
|
close($readme);
|
2006-07-12 22:21:42 -04:00
|
|
|
}
|
2023-06-18 18:25:55 -04:00
|
|
|
foreach my $when ("pre", "post") {
|
|
|
|
if (-f "$path{$name}/${when}-install"){
|
|
|
|
print $fS " $name.$when)\n";
|
|
|
|
open(my $rs, "$path{$name}/${when}-install");
|
|
|
|
while (<$rs>){
|
|
|
|
chomp;
|
|
|
|
print $fS " $_\n"
|
|
|
|
unless (m/^\#(!.*sh|\s*EOF|\s*End)/);
|
|
|
|
}
|
|
|
|
close($rs);
|
|
|
|
print $fS " ;;\n";
|
|
|
|
}
|
2006-07-12 22:21:42 -04:00
|
|
|
}
|
|
|
|
}
|
2023-06-18 18:25:55 -04:00
|
|
|
print $fS " esac\n}\n\n";
|
|
|
|
print $fS '[ "$1" ] && [[ "$2" == @(pre|post) ]] && run_script "$1.$2"';
|
|
|
|
print $fS "\n";
|
|
|
|
close $fS;
|
|
|
|
close $fR;
|
2006-07-12 22:21:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
######################## html index subs ########################
|
|
|
|
|
|
|
|
sub printheader {
|
|
|
|
open (my $ih, '>index.html');
|
2023-06-17 11:24:34 -04:00
|
|
|
print $ih <<EOH;
|
2006-07-12 22:21:42 -04:00
|
|
|
<!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
|
|
|
|
|
2023-06-17 11:24:34 -04:00
|
|
|
print $ih " <title>$title</title>\n";
|
2006-07-12 22:21:42 -04:00
|
|
|
|
2023-06-17 11:24:34 -04:00
|
|
|
print $ih <<EOH;
|
2006-07-12 22:21:42 -04:00
|
|
|
<style type="text/css">
|
|
|
|
body
|
|
|
|
{
|
|
|
|
font-family: Verdana, sans-serif;
|
|
|
|
font-size: 85%;
|
|
|
|
padding: 2em;
|
|
|
|
}
|
|
|
|
a
|
|
|
|
{
|
|
|
|
color: #67550d;
|
|
|
|
}
|
|
|
|
table
|
|
|
|
{
|
2013-07-04 11:39:58 -04:00
|
|
|
border: solid #e5dccf 1px;
|
2006-07-12 22:21:42 -04:00
|
|
|
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
|
|
|
|
|
2023-06-17 11:24:34 -04:00
|
|
|
print $ih " <h2>$title</h2>\n";
|
|
|
|
if ($header) {
|
|
|
|
open(FILE, $header) or die "Couldn't open header file";
|
2023-06-18 18:25:55 -04:00
|
|
|
while (<FILE>) { print $ih " " . $_; }
|
2023-06-17 11:24:34 -04:00
|
|
|
close(FILE);
|
|
|
|
}
|
2006-07-12 22:21:42 -04:00
|
|
|
|
2023-06-17 11:24:34 -04:00
|
|
|
print $ih " <table width=\"100%\" cellspacing=\"0\">\n";
|
|
|
|
print $ih " <tr class=\"header\"><td><b>Port</b></td><td><b>Version</b></td><td><b>Description</b></td>";
|
|
|
|
print $ih "<td><b>Last modified</b></td>";
|
|
|
|
print $ih "</tr>\n";
|
|
|
|
close($ih);
|
2006-07-12 22:21:42 -04:00
|
|
|
}
|
|
|
|
|
2023-06-18 18:25:55 -04:00
|
|
|
sub htmlrow {
|
|
|
|
my ($ih, $odd, $name, $url, $version, $desc, $date) = @_;
|
|
|
|
print $ih "<tr class=\"$odd\"><td>$name</td>";
|
|
|
|
print $ih "<td><a href=\"$url\">$version</a></td>";
|
|
|
|
print $ih "<td>$desc</td><td>$date</td></tr>\n";
|
|
|
|
}
|
|
|
|
|
2006-07-12 22:21:42 -04:00
|
|
|
sub printfooter {
|
2023-06-17 11:24:34 -04:00
|
|
|
my $count = $_[0];
|
2006-07-12 22:21:42 -04:00
|
|
|
open (my $ih, '>>index.html');
|
2023-06-17 11:24:34 -04:00
|
|
|
print $ih " </table>\n";
|
|
|
|
print $ih " <p><b>$count packages</b></p>\n";
|
|
|
|
if ($footer) {
|
|
|
|
open(FILE, $footer) or die "Couldn't open footer file";
|
2023-06-18 18:25:55 -04:00
|
|
|
while (<FILE>) { print $ih " " . $_; }
|
2023-06-17 11:24:34 -04:00
|
|
|
close(FILE);
|
|
|
|
}
|
|
|
|
print $ih " <p><i>Generated by <a href=\"http://www.varlock.com\">pkg-repgen</a> on " . isotime() . ".</i></p>\n";
|
|
|
|
print $ih <<EOH;
|
2006-07-12 22:21:42 -04:00
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
EOH
|
2023-06-17 11:24:34 -04:00
|
|
|
close($ih);
|
2006-07-12 22:21:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
sub isotime {
|
2023-06-17 11:24:34 -04:00
|
|
|
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]);
|
2006-07-12 22:21:42 -04:00
|
|
|
|
2023-06-17 11:24:34 -04:00
|
|
|
return "$year-$month-$day" if ($accuracy == 1);
|
|
|
|
return "$year-$month-$day " . sprintf("%02d:%02d:%02d UTC", $t[2], $t[1], $t[0]);
|
2006-07-12 22:21:42 -04:00
|
|
|
}
|