#!/bin/sh
GCL=`pwd`
FTPDIR=math.utexas.edu:/home/ftp/pub/gcl

# done moving aside the .c files we don't want to ship.

OPT=-9

DNAME="gcl-`cat ${GCL}/majvers`.`cat ${GCL}/minvers`"
NAME="${DNAME}.tgz"
if [ $# -eq 1 ] ; then FILE=$1 ;
OPT=
else
FILE=/tmp/${NAME}
rcp ${GCL}/ChangeLog ${FTPDIR}/gcl-ChangeLog
rcp ${GCL}/README ${FTPDIR}/GCL.README
fi
moved=0 
nameNow=`basename ${GCL}`
cd ${GCL}/..
if [ "${DNAME}" != "${nameNow}" ] ;
 then 
   rm -f ${DNAME}
  if [ -d ${DNAME} ] ;then
     moved=1 
  mv -f ${DNAME} prev-${DNAME};
  fi
  echo mv -f ${GCL} ${DNAME}
  mv -f ${GCL} ${DNAME}
fi
tar cvf - `${DNAME}/xbin/new-files ${DNAME} ${DNAME}` | (cd ${DNAME} ; gzip -c ${OPT} > ${FILE} )

if [ "${DNAME}" != "${nameNow}" ] ; then
if [ "${moved}" = "1" ]  ; then
  echo   mv ${DNAME} ${GCL}
  mv -f prev-${DNAME}  ${DNAME}
fi
mv -f ${DNAME} ${GCL}
fi


if  [ $# -eq 0 ] ; then
rcp ${FILE} ${FTPDIR}/${NAME}
fi
if [ $# -eq 0 ] ; then
   echo wfs > tmpx
   echo binary >> tmpx
   echo send ${FILE} /cli/ftp/pub/gcl/${NAME} >> tmpx
   echo send README /cli/ftp/pub/gcl/GCL.README >> tmpx
   echo send ChangeLog /cli/ftp/pub/gcl/ChangeLog >> tmpx	
   cat tmpx | ftp ftp.cli.com
   rm -f tmpx 	

echo binary >tmpx
echo cd kcl/akcl >> tmpx
echo prompt >> tmpx
# echo 'mdel akcl-1*.Z gcl-*' >> tmpx
echo send ${FILE} ${NAME} >> tmpx
echo send README GCL.README >> tmpx
echo send ChangeLog ChangeLog >> tmpx
echo quit >> tmpx
cat tmpx | ftp 133.11.11.11
fi

rm -f tmpx


