#!/bin/ksh # Check in a new baseline project or changes to an "existing" baseline # WEPS project with the "latest" run (also specified on the cmdline) # and update the "current" run directory with the contents # of the "latest" run as well. USAGE0="Usage: `basename $0` [-u] [-c] proj_dir/run_dir" USAGE1=" where: -u Update existing project with latest run" USAGE2=" -c Create new project with latest run" USAGE3=" proj_dir WEPS project dir with ext." USAGE4=" run_dir WEPS run dir with ext." # echo "before getopts loop, command line has: $*" # Extract any commandline args and options, if any while getopts "uco:?" c do case $c in u) : ;; # Do nothing - we can't define NEW_PROJ c) NEW_PROJ=1 ;; o) OARG=$OPTARG ;; \?) echo "$USAGE0" 1>&2 echo "$USAGE1" 1>&2 echo "$USAGE2" 1>&2 echo "$USAGE3" 1>&2 echo "$USAGE4" 1>&2 exit 2 ;; esac done shift `expr $OPTIND - 1` # echo "after getopts loop, command line has: $*" # echo "NEW_PROJ=$NEW_PROJ : OARG=$OARG : Files are $*" # echo "$0 : $1 : $2 : $3 : $4" #--------------------------------------------------------------------- # Obtain WEPS "Project" and "Run" directory names (with extensions) proj_name=`dirname $1` run_name=`basename $1` # Specify the default "current" Run directory basename cur_name="current.wjr" # WEPS "Project" and "Run" directory extensions proj_ext=".wpj" run_ext=".wjr" # Might be nice to ensure that the specified project and run names have the correct extensions # echo "$proj_name : $run_name : $cur_name" #--------------------------------------------------------------------- # We need to check for existance of these directories #--------------------------------------------------------------------- # Check to see if we specified an existing proj_pdir on cmdline if [ ! -d ${proj_name} ] then echo "Directory ${proj_name} does not exist - Aborting" exit 1 fi # Check to see if we specified an existing proj_name}/${run_name on cmdline if [ ! -d ${proj_name}/${run_name} ] then echo "Directory ${proj_name}/${run_name} does not exist - Aborting" exit 1 fi #--------------------------------------------------------------------- # We need to check for existance of these directories #--------------------------------------------------------------------- # Check to see if proj_name exists in cvs repository (and if not, add it) if [ ! ${NEW_PROJ} ] then if [ -d ${proj_name}/CVS ] then : # echo "${proj_name} already been checked into cvs repository (expected)" else echo "${proj_name} apparently not checked into cvs repository ..." echo "No CVS subdirectory exists - Aborting" exit 1 fi else # We have a new project # Checking for expected non-existance of "CVS" subdirectory # when we are trying to commit a new WEPS baseline project if [ -d ${proj_name}/CVS ] then echo "${proj_name} apparently already been checked into cvs repository!" echo "Aborting" exit 1 else # echo "${proj_name} apparently not been checked into cvs repository (expected)" # echo "We will 'cvs add' ${proj_name} into repository..." if cvs add ${proj_name} 2>&1 > /dev/null then : # echo "${proj_name} added to cvs repository" else echo "Can't add ${proj_name} to cvs repository!" echo "Aborting" exit 1 fi fi fi # Checking for "current" run directory depends upon whether we are doing # a "check in" of a new project or an update of an existing project. # (Depends on whether the "-c" commandline option is specified) if [ ! ${NEW_PROJ} ] then if [ ! -d ${proj_name}/${cur_name} ] then echo "Directory ${proj_name}/${cur_name} does not exist and it should - Aborting" exit 1 else : # echo "${proj_name}/${cur_name} exists as expected" fi if [ -d ${proj_name}/${cur_name}/CVS ] then : # echo "${proj_name}/${cur_name} already exists in cvs repository (expected)" else echo "${proj_name}/${cur_name} apparently not checked into cvs repository ..." echo "No CVS subdirectory exists - Aborting" exit 1 fi else # We have a new project # Checking for expected non-existance of "current" run directory # when we are trying to commit a new WEPS baseline project if [ ! -d ${proj_name}/${cur_name} ] then # echo "Directory ${proj_name}/${cur_name} does not exist (expected)" # echo "We will try and create it..." if ! mkdir ${proj_name}/${cur_name} then echo "Directory ${proj_name}/${cur_name} still does not exist" echo "Evidently we can't create it - Aborting" exit 1 fi # We need to copy contents of "${proj_name}/${run_name}" into "cur_dir" # and then "cvs add" "cur_dir" (should we "cvs add" contents here or later?) # (we will definitely "cvs commit" everything at once later) if cvs add ${proj_name}/${cur_name} 2>&1 > /dev/null then : # echo "${proj_name}/${cur_name} added to cvs repository" else echo "Directory ${proj_name}/${cur_name}/CVS still does not exist" echo "Evidently we can't add it to cvs repository - Aborting" exit 1 fi else echo "Why do we have a ${proj_name}/${cur_name} for a new project?" echo "Aborting new project check in because ${proj_name}/${cur_name} already exists!" exit 1 fi fi # We should do copying of files between "${proj_name}/${run_name}" and "${proj_name}/${cur_name}" # here before we start to do any "cvs add" of the "${proj_name}/${run_name}" # echo "Copying 'latest_run' data into 'current_run' subdirectory" cp -r ${proj_name}/${run_name}/*.ifc ${proj_name}/${cur_name} 2>&1 > /dev/null || { echo "Couldn't copy ${proj_name}/${run_name}/*.ifc contents to ${proj_name}/${cur_name} - Aborting" exit 1 } cp -r ${proj_name}/${run_name}/*.man ${proj_name}/${cur_name} 2>&1 > /dev/null || { echo "Couldn't copy ${proj_name}/${run_name}/*.man contents to ${proj_name}/${cur_name} - Aborting" exit 1 } cp -r ${proj_name}/${run_name}/*.run ${proj_name}/${cur_name} 2>&1 > /dev/null || { echo "Couldn't copy ${proj_name}/${run_name}/*.run contents to ${proj_name}/${cur_name} - Aborting" exit 1 } cp -r ${proj_name}/${run_name}/*.txt ${proj_name}/${cur_name} 2>&1 > /dev/null || { echo "Couldn't copy ${proj_name}/${run_name}/*.txt contents to ${proj_name}/${cur_name} - Aborting" exit 1 } cp -r ${proj_name}/${run_name}/*.out ${proj_name}/${cur_name} 2>&1 > /dev/null || { echo "Couldn't copy ${proj_name}/${run_name}/*.out contents to ${proj_name}/${cur_name} - Aborting" exit 1 } # Need to reverse checking for "proj_name}/${run_name" directory (shouldn't be in CVS) # Will be harder to verify because user likely will not have checked it out. # Regardless of whether it is a new project or not, the "proj_name}/${run_name" directory # will be a new directory added to CVS. The only way I can think of verifying # that we aren't trying to "add" a "proj_name}/${run_name" directory name that already exists # in the repository is to try and "cvs add" it and check the error response back # from CVS. If the "cvs add" succeeds, that is fine because we need the directory # added anyway. if [ -d ${proj_name}/${run_name}/CVS ] then echo "${proj_name}/${run_name} apparently already been checked into cvs repository!" echo "CVS subdirectory exists, it shouldn't be there - Aborting" exit 1 else # echo "${proj_name}/${run_name} doesn't appear to be checked into cvs repository (expected)" # echo "Will 'cvs add' ${proj_name}/${run_name} to repository" if cvs add ${proj_name}/${run_name} 2>&1 > /dev/null then : # echo "${proj_name}/${run_name} apparently successfully added cvs repository" else echo "${proj_name}/${run_name} apparently not successfully added to cvs repository - Aborting" exit 1 fi fi # Time to "cvs add" all required files in new project if [ ${NEW_PROJ} ] then cvs add ${proj_name}/weps.ini 2>&1 > /dev/null || { echo "Couldn't 'cvs add' ${proj_name}/weps.ini - Aborting" exit 1 } fi # Time to "cvs add" all files from "latest_run" # 'cvs add' complains and returns an error code if one attempts to check in a "CVS" # directory or a file that has already been checked in. We will simply ignore all # return errors here then (Note: looping one file at a time is too slow) # cvs add ${proj_name}/${run_name}/* 2>&1 > /dev/null || { # echo "Couldn't 'cvs add' all files in ${proj_name}/${run_name} - Aborting" # exit 1 # } cvs add ${proj_name}/${run_name}/* 2>&1 > /dev/null # Add all files required in current run directory if [ ${NEW_PROJ} ] then cvs add ${proj_name}/${cur_name}/* 2>&1 > /dev/null fi # echo "I AM NOW READY TO 'COMMIT' all the files" 1>&2 cvs commit ${proj_name} || { echo "Tried to 'commit' everything but failed - Aborting" exit 1 } if [ ${NEW_PROJ} ] then Echo "COMPLETED 'check in' of new WEPS project '${proj_name}' with run '${run_name}'" else Echo "COMPLETED 'update' of existing WEPS project '${proj_name}' with run '${run_name}'" fi