#!/bin/sh # # This package is a generalization of the l3Setup.tcsh script # usage() { # $1 $2 $3 $4 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 exec_prefix="" if [ "$option" = '-n' ] ; then dependencies=no elif [ "$option" = '-t' ] ; then # test : do not execute exec_prefix='echo' 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=/dev/stdout # $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 #------------------------------------------------------------------------------ # read 'file_of_patches' #------------------------------------------------------------------------------ while read patch_string ; do # echo patch_string = $patch_string 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' is a full name of a file or a package (could be a subdirectory) #------------------------------------------------------------------------------ module=$1 cvs_key=$2 shift tag="$@" tag=`echo "$@" | awk '{print $2}'` echo tag=$tag cvs_key=$cvs_key package=`echo $module | cut -f1 -d'/'` if [ "$package" != "$opackage" ] ; then #------------------------------------------------------------------------------ # put CVSROOT into cvs_stuff - good intention, obviously didn't work! #------------------------------------------------------------------------------ if [ -f $BFDIST/releases/development/$package ] ; then cvsroot=`cat $BFDIST/releases/development/$package/CVS/Root` elif [ -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 new package #------------------------------------------------------------------------------ echo ADDING $package cvs_stuff=$cvs_stuff if [ ! -d $package ] ; then #------------------------------------------------------------------------------ # package doesn't exist in the test release, use addpkg #------------------------------------------------------------------------------ if [ "$package" != "$module" ] ; then #------------------------------------------------------------------------------ # a single file or a subpackage: first check out default version of a package, # put mods on top #------------------------------------------------------------------------------ echo addpkg -Q $cvs_stuff $package | tee -a $log_file $exec_prefix addpkg -Q $cvs_stuff $package 2>&1 | tee -a $log_file echo cvs $cvs_stuff co $cvs_key $tag $module | tee -a $log_file $exec_prefix cvs $cvs_stuff co $cvs_key $tag $module 2>&1 | tee -a $log_file elif [ "$package" == "$module" ] ; then #------------------------------------------------------------------------------ # a package, use addpkg #------------------------------------------------------------------------------ echo ....here.... echo addpkg -Q $cvs_stuff $package $tag | tee -a $log_file $exec_prefix addpkg -Q $cvs_stuff $package $tag 2>&1 | tee -a $log_file fi else #------------------------------------------------------------------------------ # package already exists, use 'cvs co' instead of addpkg #------------------------------------------------------------------------------ echo cvs $cvs_stuff co -P $cvs_key $tag $module | tee -a $log_file $exec_prefix cvs $cvs_stuff co -P $cvs_key $tag $module 2>&1 | tee -a $log_file fi #------------------------------------------------------------------------------ # now subdirectory should exist #------------------------------------------------------------------------------ if [ ! -d $package ] ; then echo " OOPS : addpkg failed - check log file " | tee -a $log_file fi opackage=$package continue fi if [ "$package" != "$module" ] ; then echo cvs $cvs_stuff co -r $tag $module | tee -a $log_file $exec_prefix cvs $cvs_stuff co -r $tag $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 #------------------------------------------------------------------------------ # done with primary patches, if needed, proceed with dependencies #------------------------------------------------------------------------------ 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 echo addpkg -Q $cvs_stuff $dep_pkg | tee -a $log_file $exec_prefix 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