home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1999 March B / SCO_CASTOR4RRT.iso / base / root.18 / usr / sbin / pkginst / up_merge / up_merge~
Text File  |  1998-08-19  |  4KB  |  184 lines

  1. #!/sbin/sh
  2.  
  3. # Copyright (c) 1998 The Santa Cruz Operation, Inc.. All Rights Reserved. 
  4. #                                                                         
  5. #        THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF THE               
  6. #                   SANTA CRUZ OPERATION INC.                             
  7. #                                                                         
  8. #   The copyright notice above does not evidence any actual or intended   
  9. #   publication of such source code.                                      
  10.  
  11.  
  12. #ident    "@(#)up_merge.sh    15.1"
  13. #ident    "$Header: $"
  14.  
  15. ## This script merges changes in UnixWare 1.1 files from the original
  16. ## installed files.
  17. ## The merging is done using the "patch" command. 
  18. ## The patch command, a patch file as its input, when applied on a 
  19. ## file will result in a merged file.
  20. ##
  21. ## patch returns 0 if everything is OK; non-zero, otherwise.
  22. ## If patch fails it tells which hunk failed and the failed hunk(s)
  23. ## are saved in reject files.
  24. ##
  25. ## upgrade_merge return codes:
  26. ##
  27. ##    0    Success
  28. ##    2    Failure
  29. ##    3    Usage Error
  30. ##    
  31. ## USAGE=upgrade_merge     <file>
  32.  
  33. process_merge() {
  34.  
  35.     [ "$UPDEBUG" = "YES" ] && set -x
  36.  
  37.     while read FILENAME CONV CONV_CMD PATCH
  38.     do
  39.         echo $FILENAME $CONV $CONV_CMD $PATCH
  40.         [ "$UPDEBUG" = "YES" ] && goany 
  41.  
  42.         USERFILE=${UP_USER}/${FILENAME}
  43.         SVR4_2FILE=${SVR4_2DIR}/${FILENAME}
  44.         MERGEDFILE=${MERGEDIR}/${FILENAME}
  45.         REJECTFILE=${REJECTDIR}/${FILENAME}
  46.         RTNCODE1=0
  47.         RTNCODE2=0
  48.  
  49.         rm -f ${MERGEDFILE}* ${REJECTFILE}*
  50.  
  51.         # Check if the (saved) file exists; Also check if saved 
  52.         # file is not a symbolic link
  53.  
  54.         [ ! -f ${USERFILE} -o -h ${USERFILE} ] && {
  55.             continue
  56.         }
  57.  
  58.         case ${FILENAME} in
  59.  
  60.         [a-zA-Z]*)
  61.  
  62.             mkdir -p `dirname ${MERGEDFILE}` 2>/dev/null
  63.  
  64. # If special merge script indicated, run it and continue to next file
  65.  
  66.             if [ "${CONV}" = "Y" ]
  67.             then
  68.                 export ROOT FILENAME UP_ORIG UP_USER MERGEDFILE
  69.                 $CONV_CMD 
  70.                 RTNCODE1=${?}
  71.  
  72.             elif [ "${PATCH}" = "Y" ]
  73.             then
  74.  
  75.         # If there is no original file, restore the saved version
  76.                 [ ! -f ${UP_ORIG}/${FILENAME} ] && {
  77.                     cp $UP_USER/$FILENAME ${ROOT}/${FILENAME} 2>> ${UPERR}
  78.                     [ ${?} -ne 0 ] && RTNCODE=1
  79.                     continue
  80.                 }
  81.  
  82.  
  83.             # Certain files are considered special: these files will not
  84.             # be merged; they will be saved at a standard place.
  85.  
  86.                 diff -e $UP_ORIG/$FILENAME $UP_USER/$FILENAME >/tmp/patchfile
  87.                 if [ ${?} -ne 0 ]
  88.                 then
  89.                     # merge needed.
  90.  
  91.                     [ "$UPDEBUG" = "YES" ] && goany 
  92.  
  93.                     if [ "${PATCH}" = "Y" ]
  94.                     then
  95.                         mkdir -p `dirname ${REJECTFILE}` 2>/dev/null
  96.                         ${PATCHCMD} ${OPTIONS} -i /tmp/patchfile -o ${MERGEDFILE} -r ${REJECTFILE}  /${FILENAME} 2>> ${UPERR}
  97.                     fi
  98.                     RTNCODE2=${?}
  99.  
  100.                 fi
  101.             fi
  102.             ;;
  103.  
  104.         *) continue ;;
  105.         esac
  106.  
  107.         if [ ${RTNCODE1} -ne 0  -o ${RTNCODE2} -ne 0 ]
  108.         then
  109.             echo ${FILENAME} >> ${REJECTFILE_LIST}
  110.         else
  111.  
  112.             # copy merged file to appropriate place
  113.             # cp does preserve modes/owner/group
  114.  
  115.             cp ${MERGEDFILE} ${ROOT}/${FILENAME} 2>> ${UPERR}
  116.         fi
  117.     done < ${1}
  118.  
  119.     
  120. }
  121.  
  122. ########################################################
  123. ## MAIN starts here
  124.  
  125. SBINPKGINST=/usr/sbin/pkginst
  126.  
  127. . $SBINPKGINST/updebug
  128.  
  129. [ "$UPDEBUG" = "YES" ] && set -x
  130.  
  131. OPTIONS="-e"     ## options to patch tool
  132. PATCHCMD=$SBINPKGINST/patch     ## path for PATCH command 
  133. TMP=/tmp
  134. ROOT=/
  135.  
  136. UPGRADEDIR=${ROOT}/etc/inst
  137. SVR4_2DIR=${UPGRADEDIR}/SVR4.2
  138. REJECTDIR=${UPGRADEDIR}/reject
  139. MERGEDIR=${UPGRADEDIR}/merge
  140. UP_ORIG=$UPGRADEDIR/save.orig
  141. UP_USER=$UPGRADEDIR/save.user
  142. FILE_LIST=${1}
  143. REJECTFILE_LIST=${1}.rej
  144. rm -f ${REJECTFILE_LIST}
  145.  
  146. [ "$UPDEBUG" = "YES" ] && goany
  147.  
  148. for i in ${REJECTDIR} ${MERGEDIR} 
  149. do
  150.     if [ ! -d ${i} ]
  151.     then mkdir -p ${i}
  152.     fi
  153. done
  154.  
  155. USAGE="\nupgrade_merge usage: \tupgrade_merge <file>"
  156.  
  157. # Remove comments and blank lines
  158.  
  159. cat $FILE_LIST |
  160.     grep -v '^[     ]*#' |
  161.     grep -v '^[     ]*$' >/tmp/merge.$$
  162.  
  163. [ "$UPDEBUG" = "YES" ] && goany
  164.  
  165. if [ ${#} -eq 1  ]
  166. then
  167.     process_merge /tmp/merge.$$
  168. else
  169.     echo ${USAGE}
  170.        exit 3
  171. fi
  172.  
  173. rm -f /tmp/merge.$$            # clean up /tmp
  174.  
  175. [ "$UPDEBUG" = "YES" ] && goany
  176.  
  177. if [ -f ${REJECTFILE_LIST} ]
  178. then
  179.     exit 2        # at least one failure
  180. else
  181.     exit 0        # succcess
  182. fi
  183.  
  184.