#!/bin/ksh
#
# $Id: gencatalog 2484 2008-12-09 10:20:31Z dmichelsen $
#
# Copyright 2006 Cory Omand <comand@blastwave.org>
# All rights reserved.  Use is subject to license terms.
#
# Redistribution and/or use, with or without modification, is
# permitted.  This software is without warranty of any kind.  The
# author(s) shall not be liable in the event that use of the
# software causes damage.
#
# gencatalog - generate a v1 style catalog and description file.
#

cp catalog catalog.old
cp descriptions descriptions.old

for pkg in `ls -1 *.pkg *.pkg.gz 2>/dev/null`  ; do
    eval `gzcat $pkg | perl -lne '
        if    (/PKG=(\S+)/)       { print "PKG=$1" }
        elsif (/NAME=((\S+).+$)/) { print "NAME=$2\nDESC=\"$1\"" }
        elsif (/VERSION=(\S+)/)   { print "VERSION=$1" ; exit }'`

    print "$DESC"
    print "$NAME $VERSION $PKG $pkg $(md5sum $pkg | awk '{print $1}')" >> catalog.new
    print "$DESC" >> descriptions.new 
done

if [ -f catalog.new ]; then
    mv catalog.new catalog
else
    cp /dev/null catalog
fi

if [ -f descriptions.new ]; then
    mv descriptions.new descriptions
else
    cp /dev/null descriptions
fi

rm -f catalog.old descriptions.old

