Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 10 May 2009 18:57:37 +0200
From:      Jeremie Le Hen <jeremie@le-hen.org>
To:        dougb@FreeBSD.org
Cc:        freebsd-current@FreeBSD.org
Subject:   New mergemaster option -I, failsafe install files
Message-ID:  <20090510165737.GB88857@obiwan.tataz.chchile.org>

next in thread | raw e-mail | index | archive | help

--yrj/dFKFPuw6o+aM
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Hi Doug,

As you may guess from my multiple emails, I'm in the process of
upgrading my jails :-).

Since I have one jail per service, a very few number of configuration
files are modified on each jail.  As most of user of FreeBSD I think,
I'm used to run "mergemaster -iU" to automate the process as much as
possible.  The problem with service jails (chapter 15.6.1 of the
handbook) is that / is read-only mounted on all jails, /etc /var /root
and a few other places being symlinks to /s, the private read-write
space of each jail.  Thus when mergemaster tries to update
/boot/devices.hints it fails and abort.

Therefore I've implemented a new -I option that does the same thing as
-i except that it will proceed on failure.  At the end of the process,
it will also show an informational message about files that could not be
installed.

This patch along with the fix I sent you a few hours ago allows to use
mergemaster(8) in service jails flawlessly.

Best regards,
-- 
Jeremie Le Hen
< jeremie at le-hen dot org >< ttz at chchile dot org >

--yrj/dFKFPuw6o+aM
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment; filename="mergemaster-I.diff"

Index: mergemaster.8
===================================================================
RCS file: /mnt/space/cvsroot/src/usr.sbin/mergemaster/mergemaster.8,v
retrieving revision 1.41
diff -u -r1.41 mergemaster.8
--- mergemaster.8	23 Mar 2009 14:42:41 -0000	1.41
+++ mergemaster.8	10 May 2009 08:18:32 -0000
@@ -32,7 +32,7 @@
 .Nd merge configuration files, et al during an upgrade
 .Sh SYNOPSIS
 .Nm
-.Op Fl scrvahipFCPU
+.Op Fl scrvahiIpFCPU
 .Op Fl m Ar /path/to/sources
 .Op Fl t Ar /path/to/temp/root
 .Op Fl d
@@ -209,6 +209,9 @@
 .It Fl i
 Automatically install any files that do not exist in the
 destination directory.
+.It Fl I
+Automatically install any files that do not exist in the
+destination directory, but proceed on failure.
 .It Fl p
 Pre-buildworld mode.
 Compares only files known to be essential to the success of
Index: mergemaster.sh
===================================================================
RCS file: /mnt/space/cvsroot/src/usr.sbin/mergemaster/mergemaster.sh,v
retrieving revision 1.69
diff -u -r1.69 mergemaster.sh
--- mergemaster.sh	23 Mar 2009 14:42:41 -0000	1.69
+++ mergemaster.sh	10 May 2009 11:16:39 -0000
@@ -15,7 +15,7 @@
 display_usage () {
   VERSION_NUMBER=`grep "[$]FreeBSD:" $0 | cut -d ' ' -f 4`
   echo "mergemaster version ${VERSION_NUMBER}"
-  echo 'Usage: mergemaster [-scrvahipFCPU]'
+  echo 'Usage: mergemaster [-scrvahiIpFCPU]'
   echo '    [-m /path] [-t /path] [-d] [-u N] [-w N] [-A arch] [-D /path]'
   echo "Options:"
   echo "  -s  Strict comparison (diff every pair of files)"
@@ -25,6 +25,7 @@
   echo "  -a  Leave all files that differ to merge by hand"
   echo "  -h  Display more complete help"
   echo '  -i  Automatically install files that do not exist in destination directory'
+  echo '  -I  Automatically install files that do not exist in destination directory, but proceed on failure'
   echo '  -p  Pre-buildworld mode, only compares crucial files'
   echo '  -F  Install files that differ only by revision control Id ($FreeBSD)'
   echo '  -C  Compare local rc.conf variables to the defaults'
@@ -265,7 +266,7 @@
 
 # Check the command line options
 #
-while getopts ":ascrvhipCPm:t:du:w:D:A:FU" COMMAND_LINE_ARGUMENT ; do
+while getopts ":ascrvhiIpCPm:t:du:w:D:A:FU" COMMAND_LINE_ARGUMENT ; do
   case "${COMMAND_LINE_ARGUMENT}" in
   A)
     ARCHSTRING='TARGET_ARCH='${OPTARG}
@@ -303,6 +304,10 @@
   i)
     AUTO_INSTALL=yes
     ;;
+  I)
+    AUTO_INSTALL=yes
+    AUTO_INSTALL_FAILSAFE=yes
+    ;;
   C)
     COMP_CONFS=yes
     ;;
@@ -763,9 +768,17 @@
 # Create directories as needed
 #
 install_error () {
-  echo "*** FATAL ERROR: Unable to install ${1} to ${2}"
-  echo ''
-  exit 1
+  case "${AUTO_INSTALL_FAILSAFE}" in
+  '')
+    echo "*** FATAL ERROR: Unable to install ${1} to ${2}"
+    echo ''
+    exit 1
+    ;;
+  *)
+    AUTO_FAILED_INSTALLED_FILES="${AUTO_FAILED_INSTALLED_FILES}      $2/${1##*/}
+"
+    ;;
+  esac
 }
 
 do_install_and_rm () {
@@ -781,11 +794,14 @@
   if [ ! -d "${3}/${2##*/}" ]; then
     if install -m ${1} ${2} ${3}; then
       unlink ${2}
+      return 0
     else
       install_error ${2} ${3}
+      return 1
     fi
   else
     install_error ${2} ${3}
+    return 1
   fi
 }
 
@@ -824,7 +840,7 @@
       NEED_CAP_MKDB=yes
       ;;
     /etc/master.passwd)
-      do_install_and_rm 600 "${1}" "${DESTDIR}${INSTALL_DIR}"
+      do_install_and_rm 600 "${1}" "${DESTDIR}${INSTALL_DIR}" || return 1
       NEED_PWD_MKDB=yes
       DONT_INSTALL=yes
       ;;
@@ -1113,6 +1129,28 @@
   ;;
 esac
 
+case "${AUTO_FAILED_INSTALLED_FILES}" in
+'') ;;
+*)
+  case "${AUTO_RUN}" in
+  '')
+    (
+      echo '*** You chose the automatic install option for files that did not'
+      echo '    exist on your system.  The following could not be installed:'
+      echo "${AUTO_FAILED_INSTALLED_FILES}"
+      echo ''
+    ) | ${PAGER}
+    ;;
+  *)
+    echo ''
+    echo '*** You chose the automatic install option for files that did not'
+    echo '    exist on your system.  The following could not be installed:'
+    echo "${AUTO_FAILED_INSTALLED_FILES}"
+    ;;
+  esac
+  ;;
+esac
+
 case "${AUTO_UPGRADED_FILES}" in
 '') ;;
 *)

--yrj/dFKFPuw6o+aM--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20090510165737.GB88857>