Newer
Older
tmkproject / tmkproject.sh
#!/bin/sh
# tmkproject.sh - Create A New Project Skeleton
#
# Copyright (c) 2012, TundraWare Inc., Des Plaines, IL 60018 USA
# All Rights Reserved. For Terms Of Use, See: tmkproject-license.txt
# $Id: tmkproject.sh,v 1.112 2012/06/07 14:28:30 tundra Exp $

CVSID='$Id: tmkproject.sh,v 1.112 2012/06/07 14:28:30 tundra Exp $'


# If user just wants program version, display it and exit.

if [ _$1 = _-v ]
then

  echo ${CVSID}
  exit

fi

# Make sure we have a valid command line

if [ $# -ne 4 ]
    then
	echo "usage: tmkproject.sh name type cost 'Brief Description'"
	exit 1
fi

# Get the command line args into normal form

PROJECTNAME=$1
TYPE=$2
COST=$3
DESCRIPTION=$4

# Find out where we're installed

FULL=`readlink -f $0`
BASE=`dirname ${FULL}`

# Readin site-wide configuration

. ${BASE}/.tmkproject

# Readin the user's configuration if there is one

USERCONFIG=${USERCONFIGDIR}/.tmkproject

if [ -e ${USERCONFIG} ]
then
  . ${USERCONFIG}
fi

# We'll need some temporary files

TMPFILE=tmpfile
SEDRULES=sedrules

# Make sure requested language is supported and
# setup language-specific literals

# Note that the interpreter strings must
# escape all '/' characters because they
# will be used by 'sed' in substituion commands

case ${TYPE}
in

  "pl")
    INTERPRETER="\/usr\/bin\/env perl"
    LANGUAGE="perl"
  ;;

  "py")
    INTERPRETER="\/usr\/bin\/env python"
    LANGUAGE="python"
  ;;

  "sh")
    INTERPRETER="\/bin\/sh"
    LANGUAGE="the shell interpreter"
  ;;

  *)
    echo "'${TYPE}' Programs Not Supported (Yet)"
    exit 1
  ;;

esac

# Additional replacement strings

COPYDATE=`date +%Y`
COPYRIGHT="Copyright (c) ${COPYDATE} ${COPYOWNER}"
LICENSE="${PROJECTNAME}-license.txt"
RESERVED="All Rights Reserved. For Terms Of Use See: ${LICENSE}"
UPDATES="For Program Updates See: ${WEBSITE}"

# Make relevant directories and go to the working directory

RELEASES="Releases"
WRKDIR=${TMPDIR}/${PROJECTNAME}
mkdir -p  ${WRKDIR}/${RELEASES}
cd ${WRKDIR}

# Pre-process the token defintions 

touch ${SEDRULES}
while read tokdef
do
  rule="s/""`echo $tokdef | cut -d " " -f1`/`echo $tokdef | cut -d " " -f2-999`/g" 
  eval echo ${rule} >>${SEDRULES}
done < ${BASE}/tokens

# Copy project files, preserving permissions
# Substitute template tokens with actual values

for F in `find -H ${BASE}/common ${BASE}/${TYPE} -maxdepth 1 -type f `
do
  echo "Processing: ${F}"
  cp -p $F .
  sed -f ${SEDRULES} <$F >`basename $F`
done

# Combine the generic program template and the
# language-specific program template

cat program_header program.${TYPE} >${TMPFILE}
cat ${TMPFILE} >program.${TYPE}

# Clean up

rm ${SEDRULES} ${TMPFILE} program_header

# Set the project file names correctly

for file in *
do

  newname=`echo ${file} | sed -e s/program/${PROJECTNAME}/g \
                              -e s/license/${PROJECTNAME}-license/g \
                              -e s/manpage/${PROJECTNAME}/g`

  if [ ${newname} != ${file} ]
  then
    mv -v ${file} ${newname}
  fi

done

# Get everything under CVS control

cvs import -m "${DESCRIPTION}" ${PROJECTNAME} ${VENDORTAG} start 
cd ..
rm -rf ${PROJECTNAME}

# Instantiate the project in the projects directory

mkdir -p ${PROJECTSDIR}   # Make sure it exists
cd ${PROJECTSDIR}
cvs co ${PROJECTNAME}
cd ${PROJECTNAME}
cvs commit -r1.100 -m 'Initial CVS checkin to initialize version number'

# Get rid of sticky tags

for f in `find ./ -type f | grep -v CVS`
do
  cvs update -A $f
done

# Reminders

echo
echo
echo
echo
echo
echo "------------------------------------------------------------------------"
echo "Don't Forget To Manually Add Any Additional Files And Update makefile!!!"
echo "------------------------------------------------------------------------"
echo
echo
echo "-----------------------------------------------------------------------------------"
echo "Don't Forget To Verify That The  Mail Alias: ${EMAILSUPPORT} Is Active!!!"
echo "-----------------------------------------------------------------------------------"