#!/usr/bin/perl
#
# Create a page listing all my RPMS and SRPMS, with descriptions, docs, and
# links to them.
#
# By Joey Hess, <joey@kitenet.net> 
# 
# Distribute and modify freely.
#

$rpmdir="code/RPMS/i386/"; #where are our rpms? Must be both url and actual directory name..
$srpmdir="code/SRPMS/";
$basedir="/home/ftp/pub/"; #where's the base of the web server's document tree?

BEGIN { push (@INC,'../include/') }
require 'cgi-lib.pl';

print "Content-type: text/html\n\n",<<eof;

<html>
<head><title>RPMs by Joey Hess</title></head>
<body>
<h1 align=center>RPMs by Joey Hess</h1>
<p>I've deleted most of the RPMs that used to be here. They are available on
the Red Hat ftp site, unless someone else has released a newer version. I
quit making RPMs when I switched to debian, and these were eating up disk
space.</p>
<ul>
eof

open (RPM,"/usr/bin/rpm -qp $rpmdir/*.rpm --rcfile /etc/rpmrc --queryformat '
<A NAME=\"%{NAME}\">
<LI><b>%{NAME}</b>: %{DESCRIPTION}
	<UL>
	<LI><A HREF=\"$rpmdir%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}.rpm\">%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}.rpm</A>
	<LI><A HREF=\"$srpmdir%{SOURCERPM}\">%{SOURCERPM}</A>
	$rpmdir%{NAME}-%{VERSION}-%{RELEASE}.README
	</UL>
' |") || exit print "Can't run RPM!\n";

while (<RPM>) { 
	s/~(.*?)~/GetDoc($1)/eg;
	print $_ 
}

close RPM;

print "</ul>\n";
&PrintFooter;
print "</body></html>\n";

sub GetDoc { my $fn=shift;
	if (-e $basedir.$fn) {
		$ret="<LI><pre>";
		open (IN,"<$basedir$fn");
		while (<IN>) { $ret.=$_ }
		close IN;
		return $ret."</pre>";
	}
}
