[Midnightbsd-cvs] src: usr.sbin/mergemaster: Add an autoupgrade feature to mergemaster

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sun Apr 27 23:53:47 EDT 2008


Log Message:
-----------
Add an autoupgrade feature to mergemaster

Obtained from FreeBSD

Modified Files:
--------------
    src/usr.sbin/mergemaster:
        mergemaster.8 (r1.2 -> r1.3)
        mergemaster.sh (r1.2 -> r1.3)

-------------- next part --------------
Index: mergemaster.8
===================================================================
RCS file: /home/cvs/src/usr.sbin/mergemaster/mergemaster.8,v
retrieving revision 1.2
retrieving revision 1.3
diff -L usr.sbin/mergemaster/mergemaster.8 -L usr.sbin/mergemaster/mergemaster.8 -u -r1.2 -r1.3
--- usr.sbin/mergemaster/mergemaster.8
+++ usr.sbin/mergemaster/mergemaster.8
@@ -22,7 +22,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD: src/usr.sbin/mergemaster/mergemaster.8,v 1.32.2.2 2006/02/13 23:47:48 rwatson Exp $
+.\" $FreeBSD: src/usr.sbin/mergemaster/mergemaster.8,v 1.36 2006/04/30 22:09:47 gordon Exp $
 .\" $MidnightBSD$
 .\"
 .Dd February 4, 2006
@@ -33,7 +33,7 @@
 .Nd merge configuration files, et al during an upgrade
 .Sh SYNOPSIS
 .Nm
-.Op Fl scrvahipCP
+.Op Fl scrvahipCPU
 .Op Fl m Ar /path/to/sources
 .Op Fl t Ar /path/to/temp/root
 .Op Fl d
@@ -243,6 +243,8 @@
 architecture name.
 .It Fl D Ar /path
 Specify the destination directory for the installed files.
+.It Fl U
+Attempt to auto upgrade files that have not been user modified.
 .El
 .Sh ENVIRONMENT
 The
Index: mergemaster.sh
===================================================================
RCS file: /home/cvs/src/usr.sbin/mergemaster/mergemaster.sh,v
retrieving revision 1.2
retrieving revision 1.3
diff -L usr.sbin/mergemaster/mergemaster.sh -L usr.sbin/mergemaster/mergemaster.sh -u -r1.2 -r1.3
--- usr.sbin/mergemaster/mergemaster.sh
+++ usr.sbin/mergemaster/mergemaster.sh
@@ -1,14 +1,14 @@
 #!/bin/sh
 
 # mergemaster
-#
+
 # Compare files created by /usr/src/etc/Makefile (or the directory
 # the user specifies) with the currently installed copies.
-#
+
 # Copyright 1998-2004 Douglas Barton
 # DougB at FreeBSD.org
-#
-# $FreeBSD: src/usr.sbin/mergemaster/mergemaster.sh,v 1.51.8.2 2006/02/13 23:47:48 rwatson Exp $
+
+# $FreeBSD: src/usr.sbin/mergemaster/mergemaster.sh,v 1.54.4.1 2007/12/24 06:33:22 dougb Exp $
 # $MidnightBSD$
 
 PATH=/bin:/usr/bin:/usr/sbin
@@ -36,6 +36,7 @@
   echo "  -w N  Specify a screen width in columns to sdiff"
   echo "  -A architecture  Alternative architecture name to pass to make"
   echo '  -D /path/directory  Specify the destination directory to install files to'
+  echo "  -U Attempt to auto upgrade files that have not been user modified."
   echo ''
 }
 
@@ -113,6 +114,24 @@
   while [ "${HANDLE_COMPFILE}" = "v" -o "${HANDLE_COMPFILE}" = "V" -o \
     "${HANDLE_COMPFILE}" = "NOT V" ]; do
     if [ -f "${DESTDIR}${COMPFILE#.}" -a -f "${COMPFILE}" ]; then
+      if [ -n "${AUTO_UPGRADE}" ]; then
+        if echo "${CHANGED}" | grep -qsv ${DESTDIR}${COMPFILE#.}; then
+          echo ''
+          echo "  *** ${COMPFILE} has not been user modified."
+          echo ''
+
+          if mm_install "${COMPFILE}"; then
+            echo "   *** ${COMPFILE} upgraded successfully"
+            echo ''
+            # Make the list print one file per line
+            AUTO_UPGRADED_FILES="${AUTO_UPGRADED_FILES}      ${DESTDIR}${COMPFILE#.}
+"
+          else
+          echo "   *** Problem upgrading ${COMPFILE}, it will remain to merge by hand"
+          fi
+          return
+        fi
+      fi
       if [ "${HANDLE_COMPFILE}" = "v" -o "${HANDLE_COMPFILE}" = "V" ]; then
 	echo ''
 	echo '   ======================================================================   '
@@ -226,6 +245,10 @@
 #
 TEMPROOT='/var/tmp/temproot'
 
+# Assign the location of the mtree database
+#
+MTREEDB='/var/db/mergemaster.mtree'
+
 # Read /etc/mergemaster.rc first so the one in $HOME can override
 #
 if [ -r /etc/mergemaster.rc ]; then
@@ -240,11 +263,14 @@
 
 # Check the command line options
 #
-while getopts ":ascrvhipCPm:t:du:w:D:A:" COMMAND_LINE_ARGUMENT ; do
+while getopts ":ascrvhipCPm:t:du:w:D:A:U" COMMAND_LINE_ARGUMENT ; do
   case "${COMMAND_LINE_ARGUMENT}" in
   A)
     ARCHSTRING='MACHINE_ARCH='${OPTARG}
     ;;
+  U)
+    AUTO_UPGRADE=yes
+    ;;
   s)
     STRICT=yes
     unset DIFF_OPTIONS
@@ -313,6 +339,12 @@
   PRESERVE_FILES_DIR=/var/tmp/mergemaster/preserved-files-`date +%y%m%d-%H%M%S`
 fi
 
+# Check the for the mtree database in DESTDIR.
+if [ ! -f ${DESTDIR}${MTREEDB} ]; then
+  echo "*** Unable to find mtree database. Skipping auto-upgrade."
+  unset AUTO_UPGRADE
+fi
+
 echo ''
 
 # If the user has a pager defined, make sure we can run it
@@ -383,6 +415,19 @@
 #
 SOURCEDIR=${SOURCEDIR:-/usr/src/etc}
 
+# Check DESTDIR against the mergemaster mtree database to see what
+# files the user changed from the reference files.
+#
+CHANGED=
+if [ -n "${AUTO_UPGRADE}" -a -f "${DESTDIR}${MTREEDB}" ]; then
+	for file in `mtree -eq -f ${DESTDIR}${MTREEDB} -p ${DESTDIR}/ \
+		2>/dev/null | awk '($2 == "changed") {print $1}'`; do
+		if [ -f "${DESTDIR}/$file" ]; then
+			CHANGED="${CHANGED} ${DESTDIR}/$file"
+		fi
+	done
+fi
+
 # Check the width of the user's terminal
 #
 if [ -t 0 ]; then
@@ -578,6 +623,18 @@
 # We only need to compare things like freebsd.cf once
 find ${TEMPROOT}/usr/obj -type f -delete 2>/dev/null
 
+# Delete 0 length files to make the mtree database as small as possible.
+find ${TEMPROOT} -type f -size 0 -delete 2>/dev/null
+
+# Build the mtree database in a temporary location.
+# TODO: Possibly use mktemp instead for security reasons?
+case "${PRE_WORLD}" in
+'') mtree -ci -p ${TEMPROOT} -k size,md5digest > ${DESTDIR}${MTREEDB}.new 2>/dev/null
+    ;;
+*) # We don't want to mess with the mtree database on a pre-world run.
+   ;;
+esac
+
 # Get ready to start comparing files
 
 # Check umask if not specified on the command line,
@@ -782,6 +839,13 @@
   return $?
 }
 
+if [ ! -d "${TEMPROOT}" ]; then
+	echo "*** FATAL ERROR: The temproot directory (${TEMPROOT})"
+	echo '                 has disappeared!'
+	echo ''
+	exit 1
+fi
+
 echo ''
 echo "*** Beginning comparison"
 echo ''
@@ -922,6 +986,12 @@
 
 echo ''
 echo "*** Comparison complete"
+
+if [ -f "${DESTDIR}${MTREEDB}.new" ]; then
+  echo "*** Saving mtree database for future upgrades"
+  mv -f ${DESTDIR}${MTREEDB}.new ${DESTDIR}${MTREEDB} 2>/dev/null
+fi
+
 echo ''
 
 TEST_FOR_FILES=`find ${TEMPROOT} -type f -size +0 2>/dev/null`
@@ -974,6 +1044,28 @@
   ;;
 esac
 
+case "${AUTO_UPGRADED_FILES}" in
+'') ;;
+*)
+  case "${AUTO_RUN}" in
+  '')
+    (
+      echo ''
+      echo '*** You chose the automatic upgrade option for files that you did'
+      echo '    not alter on your system.  The following were upgraded for you:'
+      echo "${AUTO_UPGRADED_FILES}"
+    ) | ${PAGER}
+    ;;
+  *)
+    echo ''
+    echo '*** You chose the automatic upgrade option for files that you did'
+    echo '    not alter on your system.  The following were upgraded for you:'
+    echo "${AUTO_UPGRADED_FILES}"
+    ;;
+  esac
+  ;;
+esac
+
 run_it_now () {
   case "${AUTO_RUN}" in
   '')


More information about the Midnightbsd-cvs mailing list