#! /bin/sh
#
#   bld_patchlog
#
#   Author: Kent Landfield
#
#  Abstract:  This script is used to create a patchlog issue article file.
#             It uses the .patchlog file that the rkive maintains via the
#             use of the Patch-To: auxiliary header.  Through the use of 
#             this script, the system's .patchlog does not need to be modified
#             each time a new, sorted patchlog is to be posted.
#
#	PLOG  - location of the archive's .patchlog file maintained by rkive.
#       TMPFL - location of the output file.
#
CSM=/u1/csm
VOLUME=`cat $CSM/.issue | awk '{ print $1 }'`
PLOG=/usenet/misc/.patchlog

if [ "$1" = "prepost" ]
then
    TMPFL=$CSM/queue/INF5
else
    TMPFL=$CSM/INF/inf5
fi

echo "Building patchlog INF posting in $TMPFL"

echo "From: kent@sparky.imd.sterling.com (Kent Landfield)" > $TMPFL
echo "Newsgroups: comp.sources.misc,comp.sources.d,comp.archives" >> $TMPFL
echo "Subject: Index of Patches posted to comp.sources.misc" >> $TMPFL
echo "Archive-name: patchlog??" >> $TMPFL
echo  >> $TMPFL
echo "This is the fifth introductory messages about comp.sources.misc." >> $TMPFL
echo "This posting is a listing of patches that have been posted in c.s.misc. " >> $TMPFL
echo  >> $TMPFL
echo "The patchfile column is the posted Archive-name: of the patch. The Patch " >> $TMPFL
echo "volume and issue columns indicate the Volume/Issue of the posted patch. " >> $TMPFL
echo "The Initial volume and issue columns indicate the Volume/Issue(s) of the " >> $TMPFL
echo "articles the patch applies to. If the Initial columns contain Not Posted, " >> $TMPFL
echo "the original sources for which the patch applies were not posted to this " >> $TMPFL
echo "newsgroup." >> $TMPFL
echo >> $TMPFL
echo "#" >> $TMPFL
echo "#       Patch log for comp.sources.misc (alphabetical by name)" >> $TMPFL
echo "#" >> $TMPFL
echo "#                            Patch       Package               Initial" >> $TMPFL
echo "# Patchfile             Volume  Issue     Name              Volume  Issue" >> $TMPFL
echo "#" >> $TMPFL

t1=/tmp/csm.out$$
t2=/tmp/csm2$$
t3=/tmp/csm3$$

cat $PLOG | grep -v "#" | grep -v "volume" > $t1
cat $PLOG | grep -v "#" | grep "volume" > $t2

#
#  Check to see if there is any volume issue to convert into
#  archive-name entries...
#
if [ -s $t2 ]
then
	cat $t2 | gawk '{ printf("echo \"`article -f'%a' /usenet/misc/%s.Z`\t\t%s\t%s\t\t%s  %s   %s\"\n",$1, $2, $3, $4, $5, $6) }' > $t3
	sh $t3 >> $t1
fi
#
# Put the patch information into the 
# patchlog index file to be posted.
#
cat $t1 | sort >> $TMPFL

#
# cleanup
#
rm -f $t1 $t2 $t3
exit 0
