#!/usr/local/bin/perl # # OpenBSD Package to Web Page Converter # ------------------------------------- # # This script generates web pages by extracting the long and short # definitions from OpenBSD package files (.tgz files). # Info: Ryan Walker (walkerr@ssimicro.com) # Mangled by Bob Beck (beck@openbsd.org) # This file is in the public domain # # commited as working on ftp.openbsd.org (so /usr/local/bin/perl isn't a typo) # remember this has to work on non openbsd platforms. # # Define these variables to fit your config # $pkg_root -- root directory of packages to build, should contain arch # $web_root -- main web directory, index.html created in this directory # $tmp -- temporary directory, obviously must be writable # $version -- version number we are building for, ie "2.7" (only used for # ftp1 & 2 -- self explanatory, used for building FTP links $pkg_root="/afs/ualberta.ca/sunsite/ftp/pub/OpenBSD/2.8/packages"; $web_root="/usr/sunsite02/home/beck/www"; $tmp="/usr/sunsite02/home/beck/tmp"; $version="2.8"; $ftp1="ftp://ftp.openbsd.org/pub/OpenBSD/$version"; $ftp2="ftp://ftp1.usa.openbsd.org/pub/OpenBSD/$version"; # OK, let's get started. # verifyvars just checks to make sure all the variables specified # make sense. (In that the directories exist, are writable, etc.) &verifyvars; &getdata; system "rm -rf $web_root/*"; system "mv $tmp/build/* $web_root"; system "rm -rf $tmp/*"; sub getdata { opendir ROOT, "$pkg_root" or die "Could not open $pkg_root directory!"; @array=(readdir(ROOT)); open(INDEXFILE,">$tmp/build/index.html"); print INDEXFILE "OpenBSD Packages - Architecture Selection for OBSD $version

\

Packages - Architecture Selection for OpenBSD $version

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

"; foreach $dir (@array) { if ($dir ne ".." and $dir ne "." and $dir ne "index.txt") { print INDEXFILE "$dir\n"; system "mkdir $tmp/build/$dir"; opendir PACKAGES, "$pkg_root/$dir" or die "Could not open $dir dir."; @contents=(readdir(PACKAGES)); open (ARCHINDEX, ">$tmp/build/$dir.html"); &header; foreach $line (@contents) { if ($line ne ".." and $line ne ".") {&body;} } #FOOTER HERE print ARCHINDEX "
"; } } } #FOOTER HERE print INDEXFILE "


"; sub header {print ARCHINDEX "OpenBSD Packages ($version/$dir)\n

Packages

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


\n\n";} # This subroutine generates the HTML code (and yanks decription files) for # each per/arch package page.. sub body { # Extracting desc. files from each .tgz package if ($line =~ /\.tgz$/ ) { print "doing $dir/$line\n"; system "cp $pkg_root/$dir/$line $tmp/tar"; system "gunzip $tmp/tar/$line"; # Hack to get proper filename for tar.. $entrytar=$line; $entrytar=~s/.tgz/.tar/; # Extract our Description files.. system "tar xvf $tmp/tar/$entrytar -C $tmp/tar \"+DESC\" \"+COMMENT\""; open(LONGDESC, ">$tmp/build/$dir/$line-long.html"); print LONGDESC "OpenBSD Package Details - $line

Package Information for $line ($dir)

[ FTP 1 ]\n [ FTP 2 ] [ Package Contents ]



";close(LONGDESC);
    system "cat $tmp/tar/\"+DESC\" >>$tmp/build/$dir/$line-long.html";
    open(LONGDESC, ">>$tmp/build/$dir/$line-long.html");
    print LONGDESC "

"; print LONGDESC ""; close(LONGDESC); system "cp $tmp/tar/\"+COMMENT\" $tmp/build/$dir/$line-short.html"; # Generate a contents listing from the tar file, copy it to build open(CONT, ">$tmp/build/$dir/$line-contents.html"); print CONT "Package contents for $line ($dir)

Package contents for $line ($dir)


"; close(CONT);
    system "tar tf $tmp/tar/$entrytar >> $tmp/build/$dir/$line-contents.html";
    open(CONT, ">>$tmp/build/$dir/$line-contents.html"); print CONT
"

"; #FOOTER HERE close(CONT); # Toast the temporary tar directory for the next iteration system "rm -rf $tmp/tar/*"; open(SHORTDESC, "$tmp/build/$dir/$line-short.html"); print ARCHINDEX "\n"; } } sub verifyvars { system "clear"; print "OpenBSD PackageSucker\n*********************\n\n"; print "starting directory checks...\n\n"; if (-d $pkg_root) {print "ok - pkg_root exists\n";} else {die "ERROR pkg_root does not exist!;";} if (-w $tmp) {print "ok - tempdir is accessible\n";} else {die "ERROR tmp not writable!";} if (-w $web_root) {print "ok - webroot is accessible\n";} else {die "ERROR web_root is not writable!"} print "\ngo - toasting temp directory"; system "rm -rf $tmp/*"; print "\n"; system "mkdir $tmp/build"; system "mkdir $tmp/tar"; }
$line"; foreach $zz () {print ARCHINDEX "    $zz";} print ARCHINDEX "[ FTP Site 1 ] [ FTP Site 2 ]