#!/bin/sh # # This package is a generalization of the l3Setup.tcsh script # usage() { echo 'Usage: Apply_patches <-n> base_release base-directory test_releasename file_of_patches' echo " Where:" echo " o base_directory is the EXISTING directory below which the test release is to be built. o test_releasename is the name of the test release to be created - this is actually a directory created by relnew, if it doesn't already exist. o base_release is the release (development, or 3.8.0, or whatever) which is to be patched. o file_of_patches is the file, either full path or relative to the current directory, containing the list of updates to be applied. o The optional -n turns OFF the detection of dependent packages. If the patches exist in a repository package, and development does not contain an up-to-date copy of the package, it may be necessary to checkout the package so that the file_of_patches is as expected. CAUTION: This is a bourne shell script. USE \$HOME not '~'" echo "" } # # At this time only one option is supported, but # ---------------------------------------------- case $1 in -*) option=$1 shift ;; esac if [ "${option}" = '-n' ] then dependencies=no elif [ "${option}" != "" ] then echo "ERROR: option ${option} is not supported" Apply_patches_error=1 else dependencies=yes fi base_release=$1 base_directory=$2 test_release_name=$3 file_of_patches=$4 excluded_packages_file=$5 Apply_patches_error=0 old_cwd=`pwd` log_file=$HOME/patch.log if [ -f $log_file ] then rm -f $log_file fi if [ "${base_directory}" = "" ] then echo "ERROR: Base directory must be specified." Apply_patches_error=1 elif [ ! -d ${base_directory} ] then echo "ERROR: ${base_directory} does not exist" Apply_patches_error=1 else if [ "`echo ${base_directory}|cut -c1`" != '/' ] then if [ "`echo ${base_directory}|cut -c1-2`" = './' ] then base_directory=`echo ${base_directory}|cut -c3-` fi base_directory=${old_cwd}/${base_directory} fi log_file=$base_directory/patch.log if [ -f ${log_file} ] then rm ${log_file} fi fi if [ "${test_release_name}" = "" ] then echo "ERROR: A test release name is required." 2>&1 | tee -a ${log_file} Apply_patches_error=1 fi if [ "${UPS_DIR}" = "" ] then echo "ERROR: Ups is required." | tee -a ${log_file} Apply_patches_error=1 else UPS_SHELL=sh; export UPS_SHELL . `$UPS_DIR/bin/ups setup ups` fi if [ "${base_release}" = "" ] then echo "ERROR: A base release is required." | tee -a ${log_file} Apply_patches_error=1 elif [ ! -d ${BFDIST}/releases/${base_release} ] then echo "ERROR: Base release $BFDIST/releases/${base_release} does not exist." | \ tee -a ${log_file} Apply_patches_error=1 else setup cdfsoft2 ${base_release} if [ "`echo ${CDFSOFT2_DIR} | grep ${base_release}`" = "" ] then echo "ERROR: Failed to setup cdfsoft2 ${base_release}." | tee -a ${log_file} Apply_patches_error=1 fi fi if [ "${file_of_patches}" = "" ] then echo "ERROR: A file of patches must be specified." | tee -a ${log_file} Apply_patches_error=1 elif [ ! -f ${file_of_patches} ] then echo "ERROR: Cannot find ${file_of_patches}." | tee -a ${log_file} Apply_patches_error=1 fi if [ ${Apply_patches_error} -eq 1 ] then usage exit 1 fi if [ "${excluded_packages_file}" = "" ] then excluded_packages_file="/There_are/no/Excluded/pacKages/for/this/patch.$$" fi if [ "`echo ${excluded_packages_file}|cut -c1`" != '/' ] then if [ "`echo ${excluded_packages_file}|cut -c1-2`" = './' ] then excluded_packages_file=`echo ${excluded_packages_file}|cut -c3-` fi excluded_packages_file=${old_cwd}/${excluded_packages_file} fi if [ "`echo ${file_of_patches}|cut -c1`" != '/' ] then if [ "`echo ${file_of_patches}|cut -c1-2`" = './' ] then file_of_patches=`echo ${file_of_patches}|cut -c3-` fi file_of_patches=${old_cwd}/${file_of_patches} fi # Setup for test release # ---------------------- cd ${base_directory} if [ ! -d ${test_release_name} ] then newrel -t ${base_release} ${test_release_name} cd ${test_release_name}; srt_setup SRT_BASE_RELEASE=${base_release} if [ ! -f ${base_directory}/${test_release_name}/.base_release ] then echo "ERROR: newrel ${test_release_name} failed." | tee -a ${log_file} exit fi fi cd ${base_directory}/${test_release_name} if [ ! -f .base_release ] then echo "ERROR: ${base_directory}/${test_release_name} is NOT a test release." | \ tee -a ${log_file} echo " Please ensure that test release area is set up by newrel, or" | \ tee -a ${log_file} echo " remove ${base_directory}/${test_release_name} before attempting." | \ tee -a ${log_file} exit 1 elif [ "`cat .base_release`" != "${base_release}" ] then echo "" | tee -a ${log_file} echo "ERROR: ${base_directory}/${test_release_name} refers to" | \ tee -a ${log_file} echo " base release `cat .base_release` NOT ${base_release}" | \ tee -a ${log_file} exit 1 fi UNNEEDEDPACKAGES=":" if [ -f ${excluded_packages_file} ] then echo "The following packages, if dependent, will be excluded:" while read pack do if [ "$pack" = "" ] then continue fi if [ `echo ${pack}|cut -c1` = '#' ] then continue fi echo ' ' ${pack} UNNEEDEDPACKAGES="${UNNEEDEDPACKAGES}:`echo ${pack}|sed 's% %:%g'`" done < ${excluded_package_file} echo '' UNNEEDEDPACKAGES="${UNNEEDEDPACKAGES}:" fi echo "Importing patches from ${file_of_patches} for ${base_release}" | \ tee -a ${log_file} echo '-------------------------------------------------------' | tee -a ${log_file} echo "" | tee -a ${log_file} if [ -f /tmp/$$.dependents ] then rm -f /tmp/$$.dependents fi while read patch_string do echo "${patch_string}" | tee -a ${log_file} if [ "${patch_string}" = "" ] then continue fi if [ "`echo ${patch_string} | cut -c1`" = '#' ] then continue fi set ${patch_string} module=$1 shift cvs_update_options="$@" package=`echo ${module}|cut -f1 -d'/'` if [ "${package}" != "${opackage}" ] then # Put CVS root into cvs_stuff # cvsroot=`$HOME/work/Release/Scripts/Find_cvs_root ${package}` if [ -f ${BFDIST}/releases/development/Release/Scripts/Find_cvs_root ] then cvsroot=`${BFDIST}/releases/development/Release/Scripts/Find_cvs_root \ ${package}` else cvsroot=":pserver:anonymous@cdfcvs.fnal.gov:/cdf/code/cdfcvs/run2" fi if [ "${cvsroot}" != "" ] then cvs_stuff="-d `echo ${cvsroot}|cut -f1 -d','`" else cvs_stuff="" fi # Add the new package if [ ! -d ${package} -a "${package}" != "${module}" ] # File then echo addpkg ${cvs_stuff} ${package} | tee -a ${log_file} addpkg -Q ${cvs_stuff} ${package} 2>&1 | tee -a ${log_file} opackage=${package} elif [ ! -d ${package} -a "${package}" = "${module}" ] # Package then echo addpkg ${cvs_stuff} ${package} ${cvs_update_options} | \ tee -a ${log_file} addpkg -Q ${cvs_stuff} ${package} 2>&1 | \ tee -a ${log_file} if [ -d ${package} ] then echo cvs ${cvs_stuff} update ${package} ${cvs_update_options} | \ tee -a ${log_file} cvs ${cvs_stuff} update -Pd ${cvs_update_options} ${package} 2>&1 | \ tee -a ${log_file} else echo "" echo " OOPS : addpkg failed - attempting recovery " | \ tee -a ${log_file} echo cvs ${cvs_stuff} checkout ${package} ${cvs_update_options} | \ tee -a ${log_file} cvs ${cvs_stuff} checkout -Pd ${cvs_update_options} ${package} \ 2>&1 | tee -a ${log_file} [ -d ${package} ] && echo " OK : Recovery Successful" | \ tee -a ${log_file} fi opackage=${package} continue fi fi if [ "${package}" != "${module}" ] then echo cvs ${cvs_stuff} update ${cvs_update_options} ${module} | \ tee -a ${log_file} cvs ${cvs_stuff} update ${cvs_update_options} ${module} 2>&1 | tee -a ${log_file} fi if [ "${dependencies}" != "yes" ] then continue else filetype=`echo ${module}|cut -f2 -d'.'` if [ "${filetype}" = "hh" -o "${filetype}" = "h" -o "$filetype}" = "inc" ] then file=`basename ${module}` depend -q -f ${file} | cut -f1 -d'/' >> /tmp/$$.dependents elif [ "${package}" = "${module}" ] then depend -q ${package} | cut -f1 -d'/' >> /tmp/$$.dependents fi fi done < ${file_of_patches} echo "" | tee -a ${log_file} echo "Finished with primary patches" | tee -a ${log_file} if [ -f /tmp/$$.dependents ] then echo "" | tee -a ${log_file} echo "Retrieving dependent packages" | tee -a ${log_file} echo '-----------------------------' | tee -a ${log_file} sort -u -o /tmp/$$.sorted_dependents /tmp/$$.dependents while read dep_pkg do if [ "`echo ${UNNEEDEDPACKAGES}|grep :${dep_pkg}:`" != "" ] then continue fi echo Read ${dep_pkg} if [ ! -d ${dep_pkg} ] then cvsroot=`${BFDIST}/releases/development/Release/Scripts/Find_cvs_root ${package}` if [ "${cvsroot}" != "" ] then cvs_stuff="-d `echo ${cvsroot}|cut -f1 -d','`" else cvs_stuff="" fi addpkg -Q ${cvs_stuff} ${dep_pkg} | tee -a ${log_file} fi done < /tmp/$$.sorted_dependents fi exit # 20001030 kreymer Corrected cd into test release from base_release to test_relase_name # 20001208 debaun Added exclusion list processing to ignore some dependencies