home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / dbmalloc.zip / Buildpatch < prev    next >
Text File  |  1993-01-04  |  4KB  |  244 lines

  1. #
  2. # Buildpatch - shell script for automatically building patch files
  3. #
  4. # $Id: Buildpatch,v 1.12 1992/04/29 18:24:06 cpcahil Exp $
  5. #
  6. if [ $# = 0 ]; then
  7.     echo "usage: Buildpatch srcfiles..."
  8.     exit 1
  9. fi
  10.  
  11. #
  12. # see if any files are still locked.  If so, we cannot proceed (they must be
  13. # unlocked before a patch file can be built
  14. #
  15. if rlog -l $* 2>rlog.err | grep "locked by:" >/dev/null; then
  16.     echo "all files must be checked in before a patch file can be built"
  17.     exit 1
  18. fi
  19.  
  20. if [ -s rlog.err ]; then
  21.     echo "all files must be checked in before a patch file can be built"
  22.     exit 1
  23. fi
  24.  
  25. rm -f rlog.err
  26.  
  27. #
  28. # determine the old and new patch levels and name the patchfile
  29. #
  30. rm -f patchlevel    2> /dev/null
  31. co -q patchlevel     2> /dev/null
  32.  
  33. read title oldlevel < patchlevel
  34.  
  35. if [ "$oldlevel" -lt 10 ]; then
  36.     OPATCH=patch.0$oldlevel
  37.     ODIR=patches/p.0$oldlevel
  38. else
  39.     OPATCH=patch.$oldlevel
  40.     ODIR=patches/p.$oldlevel
  41. fi
  42.  
  43. #
  44. # if the old patch is still lying around, move it the the save directory
  45. #
  46. if [ -s "OPATCH" ]; then
  47.  
  48.     if [ ! -d "$ODIR" ]; then
  49.         mkdir $ODIR
  50.     fi
  51.  
  52.     mv ${OPATCH}* ${ODIR}
  53.  
  54.     echo "Saved ${OPATCH} to ${ODIR}"
  55. fi
  56.  
  57. level=`expr "$oldlevel" + 1`
  58.  
  59. if [ "$level" -lt 10 ]; then
  60.     PATCH=patch.0$level
  61. else
  62.     PATCH=patch.$level
  63. fi
  64.     
  65.  
  66. #
  67. # check out current version of all files
  68. #
  69. co -q -u $*
  70.  
  71. #
  72. # create the new patchlevel file
  73. #
  74. echo "Buillding patch number $level..."
  75. co -q -l patchlevel
  76. echo "$title $level" > patchlevel 
  77. ci -u -q -m"patch number $level" -t/dev/null patchlevel
  78.  
  79. #
  80. # create a new, empty patch file and empty directory for old versions of files
  81. # Note that if the patch file already exists, we assume it is special directions
  82. # for the patch and don't remove them.
  83. #
  84. if [ -s $PATCH.inst ]; then
  85.     cp $PATCH.inst $PATCH
  86.     chmod 644 $PATCH
  87. else
  88.     cp /dev/null $PATCH
  89.     chmod 644 $PATCH
  90. fi
  91.  
  92. if [ -d old ]; then
  93.     rm -rf old
  94. fi
  95. mkdir old
  96.  
  97. #
  98. # Unpack the old shar files into the old directory
  99. #
  100. (
  101.     echo "Building old directory for diff base"
  102.  
  103.     cd old
  104.     if [ "$oldlevel" -lt 10 ]; then
  105.         oldlevel=0$oldlevel
  106.     fi
  107.  
  108.     #
  109.     # if there isn't an oldshar directory, move them from the source
  110.     # directory to the oldshar directory
  111.     #
  112.     if [ !  -d ../oldshars/$oldlevel ]; then
  113.         mkdir ../oldshars/$oldlevel
  114.         mv ../mallocshar.* ../oldshars/$oldlevel
  115.     fi
  116.  
  117.     #
  118.     # unshar them into the current directory    
  119.     #
  120.     unshar -h /dev/null ../oldshars/$oldlevel/* > /dev/null 2>&1
  121.  
  122.     #
  123.     # if there are any commands to run before the patch is applied
  124.     # run them now so that they are used when the patch is generated
  125.     #
  126.     grep "^CMD:" ../$PATCH | sed -e "s/^CMD://" > commands
  127.  
  128.     if [ -s commands ]; then
  129.         sh -x commands
  130.     fi
  131. )
  132.  
  133. #
  134. # process each source file
  135. #
  136. echo "Generating diffs"
  137. for i in $*
  138. do
  139.     #
  140.     # if the file exists (then it has been changed and must be part of
  141.     # the patch file
  142.     #
  143.     if [ -s $i ]; then
  144.  
  145.         #
  146.         # if the file hasn't changed, skip it
  147.         #
  148.         if cmp -s $i old/$i ; then
  149.             continue;
  150.         fi
  151.  
  152.         #
  153.         # name the file
  154.         #
  155.         echo "\nIndex: $i" >> $PATCH
  156.  
  157.         #
  158.         # if there is an old version, add the prerequisite
  159.         #
  160.         if [ -s old/$i ]; then
  161.             
  162.             #
  163.             # get old rcs id
  164.             #
  165.             PREREQ="`rlog -rpatchlevel_$oldlevel $i |
  166.                  grep '^revision' | cut -f2 -d' ' 2>/dev/null`"
  167.  
  168.             #
  169.             # if the id is in the file, add the prereq line
  170.             #
  171.             if fgrep "$PREREQ" old/$i > /dev/null 2>&1; then
  172.  
  173.                 echo "Prereq: $PREREQ" >> $PATCH
  174.  
  175.             elif [ "$i" = "patchlevel" ]; then
  176.  
  177.                 echo "Prereq: $oldlevel" >> $PATCH
  178.  
  179.             fi
  180.         else
  181.             > old/$i
  182.         fi
  183.  
  184.         # 
  185.         # diff the file to generate the patch stuff
  186.         #
  187.         diff -c old/$i $i >> $PATCH
  188.  
  189.     fi
  190.  
  191. done
  192.  
  193. #
  194. # and now to check to verify that the patchfile correctly updates the
  195. # old code to the current version.  First apply the patch to the old
  196. # code and then see if there are any differences between the files.
  197. #
  198. echo "Verifying patch..."
  199. (
  200.     cd old
  201.  
  202.     patch < ../$PATCH > /dev/null 2>&1
  203. )
  204.  
  205. FILES="`
  206. for i in $*
  207. do
  208.     if cmp -s $i old/$i; then
  209.         continue;
  210.     fi
  211.  
  212.     echo file $i did not patch correctly > /dev/tty
  213.     echo $i
  214. done `"
  215.  
  216. if [ ! -z "$FILES" ]; then
  217.  
  218.     echo "patch file did not build correctly($FILES)."
  219.     exit 1
  220.  
  221. fi
  222.  
  223. rm -rf old
  224.  
  225. echo "Verification complete"
  226.  
  227. #
  228. # and now freeze all the files at this patchlevel, and checkout the current
  229. # versions of the files
  230. #
  231.  
  232. echo "freezing source at patch level $level"
  233. echo "." | rcsfreeze patchlevel_$level  > /dev/null 2>&1 
  234.  
  235. echo "checking out current version (unlocked)"
  236. co -q -u -rpatchlevel_$level $*
  237.  
  238. #
  239. # build patch shar files from patch file
  240. #
  241. shar3 -F -c -o$PATCH -L60 $PATCH
  242.  
  243. exit 0
  244.