#!/bin/ksh
#
# This script is used to initialize a new volume in comp.sources.misc
# and post the INFormational posting.
#
# For BSD Based system whose echo command does not support
# the \c formating characteristics...
FMTCHAR=""                # no format character capabilities
NONL=-n                   # BSD's echo "no newline" flag
#BEEP=^G                   # bell.
#
# For System V type echo commands capable of supporting
# the \c formating characteristics...
#FMTCHAR="\c"                # format character for SYSV no-newline
#NONL=                       # echo's no newline flag not needed in SYSV
#BEEP=\007                   # bell.

#
# Comp.sources.misc moderator posting directory structure.
#
CSM=/u1/csm
QUEUE=${CSM}/queue
ISSUE=${CSM}/.issue
OLDISSUE=${CSM}/.issue.old
INDEX=${CSM}/.index
LODINDEX=${CSM}/.index.old
INF1=${CSM}/INF/inf1
INF2=${CSM}/INF/inf2
INF3=${CSM}/INF/inf3
INF4=${CSM}/INF/inf4
INF5=${CSM}/INF/inf5

#
# Comp.sources.misc moderator posting software.
#
POST=/u1/csm/bin/postit

#
# Ye olde main
#
PATH=${CSM}/bin:$PATH

if [ ! -w $ISSUE ]
then
	echo "$ISSUE file is missing... correct and restart..."
	exit 1
fi

cd ${CSM}

#
# First lets get the volume information and
# increment the volume and rewrite the .issue
# file with the correct values to begin posting.
#

Lastvol=`cat $ISSUE | awk '{print $1}'`
Volume=`expr $Lastvol + 1 2> /dev/null`
if [  "$Volume" = "" ]
then
	echo "$0: bad volume info, aborting" >&2
	exit 1
fi
Issue=`cat $ISSUE | awk '{print $2}'`
Info=`cat $ISSUE | awk '{print $3}'`

#
echo 
echo "   The following is a mini checklist of needed changes prior "
echo "   to posting these files as the initial articles. "
echo 
echo "    1. Review the address for submissions and for general mail"
echo "       in inf1 and assure it is correct."
echo "    2. Add or update any information sent about new archive sites"
echo "       or site policies in inf1."
echo "    3. Were there any suggestions or policy changes that need to"
echo "       be discussed ? If so, update the appropriate data file."
echo "    4. Add the last volume's index information to inf4."
echo "    5. Generate an up-to-date patchlog."
echo "    6. Spell check and post.. "
echo 

# Check if Volume information is correct 
# Permit to change if not
#
REPLY=
until test $REPLY
do
   echo 
   echo $NONL "New volume is $Volume. Is this correct ? (y/n/q) $FMTCHAR"
   read REPLY
   case "$REPLY" in
	y) break ;;
	n) echo 
           echo $NONL "Enter the correct volume number please: $FMTCHAR"
           read Volume
           REPLY= ;;
	q) echo "Terminating $0"
           exit 1 ;;
        *) echo 
           echo "${BEEP}Please enter y (yes), n (no), or q (quit)."
           REPLY= ;;
   esac
done

#
# Build the first posting, the intro posting.
#
echo "Building Introduction 		(INF1) issue..."
cat $INF1 |
sed "s/Archive-name: intro??/Archive-name: intro${Volume}/" \
> $QUEUE/INF1

#
# Build the second posting, the index volumes 1-7 posting.
#
echo "Building index volume 1-7 	(INF2) issue..."
cat $INF2 |
sed "s/Archive-name: indx??v1-7/Archive-name: indx${Volume}v1-7/" \
> $QUEUE/INF2

#
# Build the third posting, the index volumes 8-14 posting.
#
echo "Building index volume 8-14 	(INF3) issue..."
cat $INF3 |
sed "s/Archive-name: indx??v8-14/Archive-name: indx${Volume}v8-14/" \
> $QUEUE/INF3

#
# Build the fourth posting, the index volumes 15-19 posting.
#
echo "Building index volume 15-19	(INF4) issue..."
cat $INF4 |
sed "s/Archive-name: indx??v15-19/Archive-name: indx${Volume}v15-19/" \
> $QUEUE/INF4

#
# Build the fifth posting, the index of patches posted.
#
echo "Building patchlog 		(INF5) issue..."
cat $INF5 |
sed "s/Archive-name: patchlog??/Archive-name: patchlog${Volume}/" \
> $QUEUE/INF5

for i in $QUEUE/INF[1-5]
do
    #
    #  Allow the user to edit the file
    #
    REPLY=
    until test $REPLY
    do
       echo 
       echo $NONL "Edit $i ? (y/n/q) [y] $FMTCHAR"
       read REPLY
       case "$REPLY" in
	    ""|y) $EDITOR $i
                  break
		  ;;
	    n) break ;;
	    q) echo "Terminating $0"
               exit 1 ;;
            *) echo 
               echo "${BEEP}Please enter y (yes), n (no), or q (quit)."
               REPLY= ;;
       esac
    done
done

#
# Check if the moderator is ready to reinitialize 
# the .issue and .index files.
#
REPLY=
until test $REPLY
do
   echo 
   echo $NONL "Time to increment the .issue file information ? (y/n/q) $FMTCHAR"
   read REPLY
   case "$REPLY" in
	y) #
           # Rewrite the .issue file
           #
           mv $ISSUE ${ISSUE}.${Lastvol}
           echo "$Volume 0 0" > $ISSUE
           echo "$ISSUE: `cat $ISSUE`"
           mv $INDEX ${INDEX}.${Lastvol}
           > $INDEX
           break
           ;;
	n) echo 
           echo "Skipping..."
           break 
           ;;
	q) echo "Terminating $0"
           exit 1 
           ;;
        *) echo 
           echo "${BEEP}Please enter y (yes), n (no), or q (quit)."
           REPLY= 
           ;;
   esac
done

#
# Check if the moderator is ready to 
# start posting of the INF files.
#
REPLY=
until test $REPLY
do
   echo 
   echo $NONL "Post INF files ? (y/n/q) $FMTCHAR"
   read REPLY
   case "$REPLY" in
	y) #
           # DoIt...
           #
           cd $QUEUE
           $POST INF1 INF2 INF3 INF4 INF5
           break
           ;;
	n) echo 
           echo "Skipping INF postings..."
           break
           ;;
	q) echo "Terminating $0"
           exit 1 
           ;;
        *) echo 
           echo "${BEEP}Please enter y (yes), n (no), or q (quit)."
           REPLY= 
           ;;
   esac
done
exit 0
