Hi Doug and all others.

here is a first version of the MD5 mergemaster. It works like this:

No checksum in existing /etc file
---------------------------------

-  If a installed version of a /etc file is the same as the temproot
   version, we add a md5 checksum to the cvs-header of the file and
   install it again.

-  If it differs from from the temproot version, we show as usual
   the merge/install page, and when we do the install, we add the
   md5 checksum.


Checksum already in /etc file:
------------------------------

-  If the checksum of the /etc file is the as the fresh file, we do
   nothing and skip.

-  If the checksum of header of the /etc file is the same as the generated
   from /etc, we let it install the new version, if there is any, else we
   skip.

-  If these checks are unsucessfull, we just hand it to the diff routine
   and let diplay the changes you made in the /etc files.

I think there may be some things to change, but it works for me at the
moment. Fixes are welcome. Maybe it's also a good thing to add a flag
for these checks, so you can turn off and on the new behaviour.

Martin

Martin Blapp, [EMAIL PROTECTED]
------------------------------------------------
Improware AG, UNIX solution and service provider
Zurlindenstrasse 29, 4133 Pratteln, Switzerland
Phone: +41 79 370 26 05, Fax: +41 61 826 93 01
------------------------------------------------
--- /usr/sbin/mergemaster       Fri Mar 16 08:01:20 2001
+++ mergemaster Sun Mar 18 20:25:11 2001
@@ -8,7 +8,7 @@
 # Copyright 1998-2001 Douglas Barton
 # [EMAIL PROTECTED]
 
-# $FreeBSD: src/usr.sbin/mergemaster/mergemaster.sh,v 1.17 2001/03/05 10:13:21 dougb 
Exp $
+# $FreeBSD: src/usr.sbin/mergemaster/mergemaster.sh,v 1.6.2.6 2001/03/05 20:33:28 
+dougb Exp $
 
 PATH=/bin:/usr/bin:/usr/sbin
 
@@ -112,7 +112,9 @@
           echo ''
           echo "  *** Displaying differences between ${COMPFILE} and installed 
version:"
           echo ''
-          diff "${DIFF_FLAG}" "${DESTDIR}${COMPFILE#.}" "${COMPFILE}"
+          /usr/bin/sed -E -e 's%MD5=*.{32} %%' < "${DESTDIR}${COMPFILE#.}" > 
+"${COMPFILE}.orig"
+          diff "${DIFF_FLAG}" "${COMPFILE}.orig" ${COMPFILE}
+         rm "${COMPFILE}.orig"
         ) | ${PAGER}
         echo ''
       fi
@@ -490,11 +492,6 @@
      ;;
   esac
 
-  # Avoid trying to update MAKEDEV if /dev is on a devfs
-  if /sbin/sysctl vfs.devfs.generation > /dev/null 2>&1 ; then
-    rm ${TEMPROOT}/dev/MAKEDEV ${TEMPROOT}/dev/MAKEDEV.local
-  fi
-
   ;; # End of the "RERUN" test
 esac
 
@@ -643,7 +640,12 @@
 
     case "${DONT_INSTALL}" in
     '')
+      /bin/cp ${1} ${1}.orig
+      GENMD5=`/usr/bin/grep -v "[$]${CVS_ID_TAG}:" "${1}" | /sbin/md5`
+      SEDSTRING="'s%Exp \\\$\$%Exp MD5=${GENMD5} \\\$%'"
+      eval "/usr/bin/sed -E -e ${SEDSTRING} < \"${1}.orig\" > \"${1}\""
       install -m "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}"
+      rm ${1}.orig
       ;;
     *)
       unset DONT_INSTALL
@@ -676,6 +678,69 @@
 #
 for COMPFILE in `find . -type f -size +0`; do
 
+  # get the MD5 checksum of the CVS header of ${DESTDIR}${COMPFILE#.}
+  MD5ID_OLD=`/usr/bin/grep "[$]${CVS_ID_TAG}:" ${DESTDIR}${COMPFILE#.} 2>&1 | 
+/usr/bin/sed -E -e 's%^.*MD5=(.{32}).*$%\1%' 2>&1`
+
+  # Generate the MD5 checksum of the installed file
+  GENMD5_OLD=`/usr/bin/grep -v "[$]${CVS_ID_TAG}:" ${DESTDIR}${COMPFILE#.} | 
+/sbin/md5`
+
+  # Generate the MD5 checksum of ${COMPFILE}
+  GENMD5_NEW=`/usr/bin/grep -v "[$]${CVS_ID_TAG}:" ${COMPFILE} | /sbin/md5`
+
+  # Get the CVS_ID lines without MD5 checksum
+  CVSID_OLD=`/usr/bin/grep "[$]${CVS_ID_TAG}:" ${DESTDIR}${COMPFILE#.} | /usr/bin/sed 
+-E -e 's%MD5=.{32}%%' 2>/dev/null`
+  CVSID_NEW=`/usr/bin/grep "[$]${CVS_ID_TAG}:" ${COMPFILE} 2>/dev/null | /usr/bin/sed 
+-E -e 's%MD5=.{32}%%' 2>/dev/null`
+
+  #
+  # Check if no MD5 checksum exits in the installed version.
+  #
+  case "${MD5ID_OLD}" in
+  "${CVSID_NEW}")
+       #
+       # No MD5 checksum available, if the files are exactly the
+       # same we can add a MD5 checksum to the cvs header.
+       #
+       case "${GENMD5_OLD}" in
+       "${GENMD5_NEW}")
+               #
+               # New File is the same as the installed version
+               # so we can savly install the new version with
+               # generated md5 checksum.
+               #
+               mm_install "${COMPFILE}"
+               continue
+               ;;
+       esac
+       ;;
+  *)
+       #
+       # MD5 checksum available
+       #
+       case "${MD5ID_OLD}" in
+       "${GENMD5_NEW}")
+               #
+               # New and old file are exactly the same, MD5 checksum
+               # is available, so skip the file.
+               #
+               continue
+               ;;
+       *)
+               case "${GENMD5_OLD}" in
+               "${MD5ID_OLD}")
+                       #
+                       # New and old file are different and the installed
+                       # version has not been changed in any way, so we
+                       # can install a new version without problems.
+                       #
+                       mm_install "${COMPFILE}"
+                       continue
+                       ;;
+               esac
+               ;;
+       esac
+       ;;
+  esac
+
   # First, check to see if the file exists in DESTDIR.  If not, the
   # diff_loop function knows how to handle it.
   #
@@ -691,11 +756,9 @@
     # If the files have the same $Id, delete the one in temproot so the
     # user will have less to wade through if files are left to merge by hand.
     #
-    CVSID1=`grep "[$]${CVS_ID_TAG}:" ${DESTDIR}${COMPFILE#.} 2>/dev/null`
-    CVSID2=`grep "[$]${CVS_ID_TAG}:" ${COMPFILE} 2>/dev/null`
 
-    case "${CVSID2}" in
-    "${CVSID1}")
+    case "${CVSID_OLD}" in
+    "${CVSID_NEW}")
       echo " *** Temp ${COMPFILE} and installed have the same CVS Id, deleting"
       rm "${COMPFILE}"
       ;;

Reply via email to