#!/usr/bin/perl -w # $FabBSD$ # $OpenBSD: gen-package-pages,v 1.16 2008/05/01 00:54:54 pvalchev Exp $ # Copyright (c) 2004 Michael Coulter # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE OPENBSD PROJECT AND CONTRIBUTORS # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBSD # PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # Requires: # all packages under some $pkgpath, in /*.tgz # Outputs result in html/* use strict; use OpenBSD::PackageInfo; use OpenBSD::PackageName; use OpenBSD::PackageLocator; use OpenBSD::PackingList; use subs qw(dprint gen_arch_page gen_pkg_page gen_pkg_listing_page getfile htmlfile gen_index_page arch_body arch_foot arch_head index_head index_foot pkg_list pkg_long); our $osrev = "4.3"; our $debug = 0; our $html; my @arches = qw(alpha amd64 arm hppa i386 m68k m88k mips64 powerpc sh sparc sparc64 vax); my $pkgpath = "/ftp/os/FabBSD/$osrev/packages"; my $htmlbase = "html"; mkdir($htmlbase); foreach (@arches) { mkdir "$htmlbase/$_"; } gen_index_page(@arches); foreach (@arches) { gen_arch_page($_); } sub dprint { if($debug) { print @_; } } sub getdesc { my $fname = shift; local $_; open(my $f, '<', $fname) or die "No such file $fname\n"; $_ = <$f>; my $result = join('', <$f>); close($f); return $result; } sub getline { my $fname = shift; open(my $f, '<', $fname) or die "No such file $fname\n"; my $line = <$f>; chomp($line); close($f); return $line; } sub htmlfile { my $fname = "$htmlbase/".shift; open(my $f, '>', $fname) or die "Cannot write to $fname\n"; return $f; } sub gen_arch_page { my $arch = shift; print "generating page for $arch\n"; my $archfile = htmlfile("$arch.html"); print $archfile arch_head($arch); opendir(my $pkgs, "$pkgpath/$arch") || die "cannot get package listing for $arch: $!\n"; foreach my $file (sort(readdir($pkgs))) { next if ($file =~ /^\./); next if ($file =~ /^index.txt$/); next if ($file =~ /^pkglocatedb$/); dprint "generating package for $arch/$file\n"; my $package = OpenBSD::PackageLocator->find("$pkgpath/$arch/$file"); if(! $package) { die "package error: $pkgpath/$arch/$file $!\n"; } my $dir = $package->info(); $package->close(); print $archfile arch_body($arch,$file,getline($dir.DESC)); gen_pkg_page($arch,$file,$dir); $package->wipe_info(); } closedir($pkgs); print $archfile arch_foot(); close($archfile); } sub gen_pkg_page { my ($arch,$pkg, $dir) = @_; my $long = htmlfile("$arch/$pkg-long.html"); my $pkg_info = getdesc($dir.DESC); $pkg_info =~ s/\&/\&\;/g; $pkg_info =~ s/\/\>\;/g; print $long pkg_long($arch,$pkg,$pkg_info); close($long); gen_pkg_listing_page($arch,$pkg,$dir); } sub gen_pkg_listing_page { my ($arch,$pkg,$dir) = @_; my $cont = htmlfile("$arch/$pkg-contents.html"); my $pkg_info; my $plist = OpenBSD::PackingList->fromfile($dir.CONTENTS, \&OpenBSD::PackingList::FilesOnly); die "Bad packing list: $!\n" unless defined $plist; for my $item (@{$plist->{items}}) { next unless $item->IsFile(); $pkg_info .= $item->fullname() . "\n"; } if (!$pkg_info) { $pkg_info = "empty packing list"; } print $cont pkg_list($arch,$pkg,$pkg_info); close($cont); } sub gen_index_page { my @arches = @_; my $index = htmlfile("index.html"); print $index index_head(); foreach (@arches) { print $index "$_\n"; } print $index index_foot(); close($index); } exit(0); sub arch_body { my($arch,$file,$comment) = @_; return <<"EOF"; $file    $comment [ FTP Site1 ] EOF } sub arch_foot { return <<"EOF";
EOF } sub arch_head { my $arch = shift; return <<"EOF"; FabBSD Packages ($osrev/$arch)

Packages

The following table is a listing of the packages currently available for FabBSD $osrev on the $arch platform. Make sure you've got the right version and platform -- chaos will ensue if you are in the wrong area.


EOF } sub index_head { return <<"EOF"; FabBSD Packages - Architecture Selection for FabBSD $osrev

Packages - Architecture Selection for FabBSD $osrev

Please select the architecture for which you wish to download a package.

EOF } sub index_foot { return <<"EOF";


EOF } sub pkg_list { my ($arch,$pkg,$pkg_info) = @_; return <<"EOF"; FabBSD Package Details - $pkg

Package Information for $pkg ($arch)

[ FTP 1 ] [ Package Contents ]



$pkg_info

EOF } sub pkg_long { my ($arch,$pkg,$pkg_info) = @_; return <<"EOF"; FabBSD Package Details - $pkg

Package Information for $pkg ($arch)

[ FTP 1 ] [ Package Contents ]



$pkg_info

EOF }