#!/usr/bin/perl -w # $OpenBSD: gen-package-pages,v 1.1 2004/02/20 23:47: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: # ./INDEX # all packages under some path, /*.tgz # Outputs result in html/* use strict; use OpenBSD::PackageInfo; use OpenBSD::PackageName; use OpenBSD::PackageLocator; use OpenBSD::PackingList; our $osrev = "3.4"; our $debug = 0; our $html; my @arches = qw(alpha hppa i386 m68k powerpc sparc sparc64 vax); my $pkgpath = "/home/ftp/pub/OpenBSD/$osrev/packages"; mkdir("html"); map { mkdir("html/$_") } @arches; gen_index_page(@arches); foreach (@arches) { gen_arch_page($_); } sub dprint { if($debug) { print @_; } } sub gen_arch_page { my $arch = shift; print "generating page for $arch\n"; open(ARCH,"> html/$arch.html") || die "cannot open file $arch.html: $!\n"; &arch_head($arch); print ARCH $html; opendir(PKGS, "$pkgpath/$arch") || die "cannot get package listing for $arch: $!\n"; while (my $file = readdir(PKGS)) { next if ($file =~ /^\./); dprint "generating package for $arch/$file\n"; my $package = OpenBSD::PackageLocator->find("$pkgpath/$arch/$file"); if(! $package) { die "package error: $!\n"; } my $dir = $package->info; $package->close(); my $comment = ""; open(IN,"<",$dir.COMMENT) or die "cannot get comment: $!\n"; while() { $comment .= $_ } close(IN); arch_body($arch,$file,$comment); print ARCH $html; gen_pkg_page($arch,$file,$dir); } closedir(PKGS); &arch_foot; print ARCH $html; close(ARCH); } sub gen_pkg_page { my ($arch,$pkg, $dir) = @_; open(LONG, "> html/$arch/$pkg-long.html"); my $pkg_info; open(IN,"<",$dir.DESC) or die "cannot get description: $!\n"; while() { $pkg_info .= $_ } close(IN); $pkg_info =~ s/\&/\&\;/g; $pkg_info =~ s/\/\>\;/g; &pkg_long($arch,$pkg,$pkg_info); print LONG $html; close(LONG); gen_pkg_listing_page($arch,$pkg,$dir); } sub gen_pkg_listing_page { my ($arch,$pkg,$dir) = @_; open(CONT, "> html/$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"; } &pkg_list($arch,$pkg,$pkg_info); print CONT $html; close(CONT); } sub gen_index_page { my @arches = @_; open(INDEX,"> html/index.html") || die "cannot open file INDEX: $!\n"; &index_head; print INDEX $html; map { $html .= "$_\n" } @arches; print INDEX $html; &index_foot; print INDEX $html; close(INDEX); } exit(0); sub arch_body { my($arch,$file,$comment) = @_; $html =<<"EOF"; $file    $comment [ FTP Site1 ] [ FTP Site 2 ] EOF } sub arch_foot { $html= <<"EOF";
EOF } sub arch_head { my $arch = shift @_; $html =<<"EOF"; OpenBSD Packages ($osrev/$arch)

Packages

The following table is a listing of the packages currently available for OpenBSD $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 { $html =<<"EOF"; OpenBSD Packages - Architecture Selection for OpenBSD $osrev

Packages - Architecture Selection for OpenBSD $osrev

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

EOF } sub index_foot { $html =<<"EOF";


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

Package Information for $pkg ($arch)

[ FTP 1 ] [ FTP 2 ] [ Package Contents ]



$pkg_info

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

Package Information for $pkg ($arch)

[ FTP 1 ] [ FTP 2 ] [ Package Contents ]



$pkg_info

EOF }