#!/bin/ksh
#
# GenericDistrib -- generic lsof 4.x distribution gzip'd archive builder
# GenericDistrib2 -- generic lsof 4.x distribution bzip2'd archive builder
#
# Usage: GenericDistrib <dialect> [<suffix>]
#
#	<dialect>	dialect's subdirectory name
#
#	[<suffix>]	optional suffix for version number

cd $HOME/src/lsof4

# Get version number.

V=`sed '/VN/s/.ds VN \(.*\)/\1/' version`
if test $? -ne 0
then
  echo $V
  exit 1
fi

# Handle arguments.

if test $# -lt 1 -o $# -gt 2
then
  echo "Usage: <dialect> [<suffix>]"
  exit 1
fi
DIALECT=$1
if test $# -eq 2
then
  V=${V}$2
fi

# Set variable names.

DIR=lsof_${V}.${DIALECT}
TAR=${DIR}.tar
echo $0 | grep 2 > /dev/null
if test $? -eq 0
then
  TARC=${TAR}.bz2
  COMP=bzip2
else
  TARC=${TAR}.gz
  COMP=gzip
fi

# Prepare for premature exit.

trap 'rm -rf $DIR $TAR $TARC; exit' 1 2 3 15

# Make a temporary directory with the relevant files in it and
# create a gzip'd tar archive of it.

rm -rf $TAR $TARC
$HOME/src/lsof4/support/GenericSubdir $1 $2
echo "Making $TAR ...\c"
tar cf $TAR $DIR
echo " done"
ls -l $TAR
echo "Removing $DIR ...\c"
rm -rf $DIR
echo " done"
echo "$COMP $TAR ...\c"
$COMP -c $TAR > support/$TARC
echo " done"
ls -l support/$TARC
rm -f $TAR
