mergemaster and better support for ezjails

Warren Block wblock at wonkity.com
Sun Jul 13 02:08:55 UTC 2014


A couple of patches to make mergemaster work better with ezjails.

These are only very superficially tested.  Feedback welcome.

1. If /etc/mergemaster.rc exists in the jail, it is sourced.  This
    allows IGNORE_FILES to be set in the jail.  And other settings, but
    that's the one I wanted.

2. If /etc/localtime in the jail is a plain file, as when tzsetup has
    been run in the jail, tzsetup reinstalls the same file.  It will come
    from the host, but at first glance this does not seem to be a
    problem, seeing that jails should be updated after the host has been
    updated.  Because /usr/share/zoneinfo does not exist in the jail, I
    did not see a clean way to use tzsetup -C.  A link could be created
    to the basejail's /usr/share/zoneinfo, then deleted after
    tzsetup -C has run, or maybe there is a better way.
-------------- next part --------------
--- /usr/src/usr.sbin/mergemaster/mergemaster.sh	2014-06-03 06:16:06.000000000 -0600
+++ /usr/sbin/mergemaster	2014-07-12 19:40:22.000000000 -0600
@@ -251,16 +251,29 @@
 #
 TEMPROOT='/var/tmp/temproot'
 
+# Options string for getopts
+OPT_STR=":ascrvhipCPm:t:du:w:A:D:FU"
+
+# if -D DESTDIR is set, process it first
+DESTDIR=""
+while getopts "${OPT_STR}" COMMAND_LINE_ARGUMENT ; do
+  case "${COMMAND_LINE_ARGUMENT}" in
+  D)
+    DESTDIR=${OPTARG}
+    ;;
+  esac
+done
+
 # Read /etc/mergemaster.rc first so the one in $HOME can override
 #
 if [ -r /etc/mergemaster.rc ]; then
-  . /etc/mergemaster.rc
+  . "${DESTDIR}/etc/mergemaster.rc"
 fi
 
 # Read .mergemasterrc before command line so CLI can override
 #
 if [ -r "$HOME/.mergemasterrc" ]; then
-  . "$HOME/.mergemasterrc"
+  . "${DESTDIR}/$HOME/.mergemasterrc"
 fi
 
 for var in "$@" ; do
@@ -279,7 +292,8 @@
 
 # Check the command line options
 #
-while getopts ":ascrvhipCPm:t:du:w:D:A:FU" COMMAND_LINE_ARGUMENT ; do
+OPTIND=1
+while getopts "${OPT_STR}" COMMAND_LINE_ARGUMENT ; do
   case "${COMMAND_LINE_ARGUMENT}" in
   A)
     ARCHSTRING='TARGET_ARCH='${OPTARG}
@@ -344,7 +358,7 @@
     SCREEN_WIDTH=${OPTARG}
     ;;
   D)
-    DESTDIR=${OPTARG}
+    # has already been processed
     ;;
   *)
     display_usage
@@ -1335,10 +1349,20 @@
 
 if [ -e "${DESTDIR}/etc/localtime" -a ! -L "${DESTDIR}/etc/localtime" -a -z "${PRE_WORLD}" ]; then	# Ignore if TZ == UTC
   echo ''
-  [ -n "${DESTDIR}" ] && tzs_args="-C ${DESTDIR}"
-  if [ -f "${DESTDIR}/var/db/zoneinfo" ]; then
-    echo "*** Reinstalling `cat ${DESTDIR}/var/db/zoneinfo` as ${DESTDIR}/etc/localtime"
-    tzsetup $tzs_args -r
+  if [ -n "${DESTDIR}" ]; then
+    SHARE="${DESTDIR}/usr/share"
+    ZONE_INFO="${SHARE}/zoneinfo"
+    if [ -L "${SHARE}" -a ! -e "${ZONE_INFO}" ]; then
+      # /usr/share is a link, /usr/share/zoneinfo does not exist, this is an ezjail
+      tzs_args="-r \"${DESTDIR}\""
+    else
+      # this is a full jail
+      tzs_args="-r -C \"${DESTDIR}\""
+    fi
+    if [ -f "${DESTDIR}/var/db/zoneinfo" ]; then
+      echo "*** Reinstalling `cat ${DESTDIR}/var/db/zoneinfo` as ${DESTDIR}/etc/localtime"
+      tzsetup $tzs_args
+    fi
   else
     echo "*** There is no ${DESTDIR}/var/db/zoneinfo file to update ${DESTDIR}/etc/localtime."
     echo '    You should run tzsetup'


More information about the freebsd-jail mailing list