#!/bin/sh
########################################################################
# Script to update a test release to a different version.
#
# 2000/08/04 CG
########################################################################
usage() {
echo "usage: `basename $0` [-h] [-nqv] [-t
] [-c ] [--] "
echo "Flags:
-h This help
-n Safe flag: don't actually change anything. Overridden by -c
option
-q Quiet: cvs doesn't announce every directory it enters
-v Verbose: more information
-t Operate on release in
-c Clone to a new release . For the nervous (or sensible).
Copies the test release to a new release and updates that
rather than the original
NOTE Updating a test release in this way is not foolproof: if you have
locally edited any files, there is a chance that the cvs update will encounter
conflicts. Even if this is not the case, there is always the chance that
changes to the Run2 software mean that code you have altered may not compile,
link, run or produce consistent results. You have been warned!"
}
####################################
# Process arguments
shift `expr $OPTIND - 1`
while getopts :nqvt:c:h OPT; do
case $OPT in
n)
safe=1
;;
q)
quiet=1
;;
v)
verbose=1
;;
t)
testRelease="$OPTARG"
;;
c)
clonedRelease="$OPTARG"
;;
h)
usage
exit 1
;;
*)
usage
exit 2
esac
done
shift `expr $OPTIND - 1`
####################################
# Check we can actually do what we need to, and set things up
if [ -n "${safe}" -a -n "${clonedRelease}" ]; then
echo "Safe flag overridden: cloning test release."
unset safe
fi
if [ -z "${testRelease}" ]; then
testRelease="`pwd`"
curdir=1
fi
if [ $# -ne 1 ] ;then
# Don't know how to execute this program
echo "Must specify required version!"
usage
exit 1
fi
version=$1
if [ -z "${version}" ]; then
# Don't know how to execute this program
echo "Null version given!"
exit 1
fi
if [ -n "${safe}" ]; then
# Coward
echo "Running in safe mode. cvs updates are '-n' and no files will be \
changed."
fi
# Have we specified somewhere to go?
if [ -z "${curdir}" -a ! -d "${testRelease}" ]; then
# Oops
echo "Problem! Specified release directory is either not a directory"
echo " or does not exist!"
exit 1
fi
# Are we actualy looking at a real test release?
if [ ! -f ${testRelease}/.base_release ]; then
# Oops
echo "${testRelease} does not appear to be a test release!"
exit 1
fi
# Decide how to update the release.
if [ "${version}" = "`cat ${testRelease}/.base_release`" ]; then
# Oops
echo "Release is already at version ${version}: nothing to do!"
exit 1
elif [ "${version}" = "development" ]; then
# Updating to the head. Need special treatment
head=1
else
# Obtain best release details from CVS
versionTagsFile=/tmp/updateRelease.$$
# remove file on exit
trap "rm $versionTagsFile 2>/dev/null" 0
if ! cvs co -p Release/Releases/${version}.newrel > ${versionTagsFile} \
2> /dev/null; then
# Either unrecognized release or cvs access failure
echo "Unable to obtain Release details for software version ${version}!"
exit 1
fi
fi
# Are we being nervous?
if [ -n "${clonedRelease}" ]; then
if [ -d "${clonedRelease}" ]; then
# Oops
echo "Clone release ${clonedRelease} already exists!"
exit 1
fi
if [ ! -d "`dirname ${clonedRelease}`" ]; then
# Oops
echo "Parent directory of ${clonedRelease} coes not appear to exist!"
exit 1
fi
# Extra info
if [ -n "${verbose}" ]; then
echo "Creating new test release ${clonedRelease}"
fi
# Create the new release
( cd `dirname ${clonedRelease}`; \
newrel -t `cat ${testRelease}/.base_release` \
`basename ${clonedRelease}` 2>&1 > /dev/null )
if [ ! -d "${clonedRelease}" ]; then
# Oops
echo "Unable to create cloned release ${clonedRelease}"
exit 1
fi
# Tell the user what we're doing:
echo "Cloning release in ${testRelease} to ${clonedRelease}"
# Change directory to original release, gather up the packages and transfer them
cd ${testRelease}
# Little bit of magic to make sure we're only tarring valid packages
packages=`( cd include ; find . -type l -exec basename {} \; ) \
| while read i; do if [ -d "${i}" ]; then echo $i; fi; done`
# Extra info
if [ -n "${verbose}" ]; then
echo "Transferring the following packages to cloned release ${clonedRelease}:"
for i in ${packages}; do
echo " $i"
done
fi
# Tar 'em up and ship 'em out
if ! find ${packages} include -depth -print | \
cpio -pmud ${clonedRelease} > /dev/null 2>&1 ; then
echo "Unable to packages to new test release ${clonedRelease}!"
exit 1
fi
# From now on, treat the cloned release as our test release.
origRelease=${testRelease}
testRelease=${clonedRelease}
fi
####################################
# Start updating the release
# Change directory to the test release we're going to update
cd ${testRelease}
# Base release tag file
if [ -z "${safe}" ]; then
echo "${version}" > .base_release
fi
echo "Updating all packages to Run2 sofware version ${version}."
# Extra info
if [ -n "${verbose}" ]; then
echo "Watch carefully for cvs conflicts and other indications that manual"
echo " intervention is required."
fi
echo " "
# Loop over valid packages
for package in `ls -1 include/`; do
if [ ! -d ${package} ]; then
# Polluted include directory
continue
fi
if [ -n "${safe}" ]; then
# Coward
safeFlag="-n "
fi
if [ -n "${quiet}" ]; then
# Nice
quietFlag="-q "
fi
if [ -n "${head}" ]; then
# Working from the head
if [ -n "${verbose}" ]; then
# Extra info
echo "** Updating ${package} to the head of development **"
fi
newTag=""
tagFlag=""
noStickFlag="-A"
else
# Standard release
newTag=`awk '$1 == "'"${package}"'" {print $2;}' ${versionTagsFile}`
tagFlag="-r "
noStickFlag=""
if [ -n "${verbose}" ]; then
# Extra info
echo "** Updating ${package} to version tag ${newTag} **"
fi
fi
# Do the dirty
if [ -n "${newTag}" -o -n "${head}" ]; then
cd ${package}
cvs ${safeFlag}${quietFlag}update ${tagFlag}${newTag} ${noStickFlag} -dP
cd - > /dev/null
fi
done
# Deal with that strange entity, the super environment
if [ -d ${testRelease}/super/include ]; then
echo "
Operating in a \`\`super''-capable environment
Issue the following commands to ensure super links are updated:
setup cdfsoft2 ${version}
cd ${testRelease}
srt_setup -aS
gmake super_refresh"
fi
# Show user how to recreate super environment in the new release
if [ -n "${origRelease}" -a -d "${origRelease}/super/include" ]; then
echo "Original test release ${origRelease} was \`\`super''-capable
Issue the following commands to make your new release\`\`super''-capable:
setup cdfsoft2 ${version}
cd ${testRelease}
srt_super_init
srt_setup -aS"
fi
# Finished. Extra info messages
echo "
Done. Execute a \`\`gmake clean'' before compiling your release."
if [ -n "${origRelease}" ]; then
echo "Test Release ${origRelease} cloned as ${testRelease} and
converted to version ${version}. Remember to copy all scripts, data
files and other required files not in packages directories over to
the new release and verify proper operation before removing the old
release."
fi
exit 0