$OpenBSD: patch-mergemaster_sh,v 1.9 2005/12/27 21:58:44 naddy Exp $
--- mergemaster.sh.orig	Sun May 11 00:06:02 2003
+++ mergemaster.sh	Tue Dec 27 22:44:22 2005
@@ -10,7 +10,7 @@
 
 # $FreeBSD: mergemaster.sh,v 1.46 2003/05/03 06:35:19 dougb Exp $
 
-PATH=/bin:/usr/bin:/usr/sbin
+PATH=/bin:/usr/bin:/usr/sbin:@LOCALBASE@/bin
 
 display_usage () {
   VERSION_NUMBER=`grep "[$]FreeBSD:" $0 | cut -d ' ' -f 4`
@@ -224,10 +224,10 @@ press_to_continue () {
 #
 TEMPROOT='/var/tmp/temproot'
 
-# Read /etc/mergemaster.rc first so the one in $HOME can override
+# Read @SYSCONFDIR@/mergemaster.rc first so the one in $HOME can override
 #
-if [ -r /etc/mergemaster.rc ]; then
-  . /etc/mergemaster.rc
+if [ -r @SYSCONFDIR@/mergemaster.rc ]; then
+  . @SYSCONFDIR@/mergemaster.rc
 fi
 
 # Read .mergemasterrc before command line so CLI can override
@@ -404,7 +404,7 @@ fi
 
 # Define what CVS $Id tag to look for to aid portability.
 #
-CVS_ID_TAG=FreeBSD
+CVS_ID_TAG=OpenBSD
 
 delete_temproot () {
   rm -rf "${TEMPROOT}" 2>/dev/null
@@ -506,10 +506,7 @@ case "${RERUN}" in
       make DESTDIR=${DESTDIR} distrib-dirs
         ;;
       esac
-      make DESTDIR=${TEMPROOT} distrib-dirs &&
-      make MAKEOBJDIRPREFIX=${TEMPROOT}/usr/obj obj &&
-      make MAKEOBJDIRPREFIX=${TEMPROOT}/usr/obj DESTDIR=${TEMPROOT} \
-          distribution;} ||
+      make DESTDIR=${TEMPROOT} -DNOMAKEDEV distribution-etc-root-var;} ||
     { echo '';
      echo "  *** FATAL ERROR: Cannot 'cd' to ${SOURCEDIR} and install files to";
       echo "      the temproot environment";
@@ -555,11 +552,6 @@ case "${RERUN}" in
      ;;
   esac
 
-  # Avoid trying to update MAKEDEV if /dev is on a devfs
-  if /sbin/sysctl vfs.devfs.generation > /dev/null 2>&1 ; then
-    rm -f ${TEMPROOT}/dev/MAKEDEV ${TEMPROOT}/dev/MAKEDEV.local
-  fi
-
   ;; # End of the "RERUN" test
 esac
 
@@ -567,11 +559,8 @@ esac
 # or spwd.db.  Instead, we want to compare the text versions, and run *_mkdb.
 # Prompt the user to do so below, as needed.
 #
-rm -f ${TEMPROOT}/etc/*.db ${TEMPROOT}/etc/passwd
+rm -f ${TEMPROOT}/etc/*.db ${TEMPROOT}/etc/mail/*.db ${TEMPROOT}/etc/passwd
 
-# We only need to compare things like freebsd.cf once
-find ${TEMPROOT}/usr/obj -type f -delete 2>/dev/null
-
 # Get ready to start comparing files
 
 # Check umask if not specified on the command line,
@@ -605,50 +594,6 @@ fi
 
 CONFIRMED_UMASK=${NEW_UMASK:-0022}
 
-#
-# Warn users who still have old rc files
-#
-for file in atm devfs diskless1 diskless2 isdn network network6 pccard \
-  serial syscons sysctl alpha amd64 i386 ia64 sparc64; do
-  if [ -f "${DESTDIR}/etc/rc.${file}" ]; then
-    OLD_RC_PRESENT=1
-    break
-  fi
-done
-
-case "${OLD_RC_PRESENT}" in
-1)
-  echo ''
-  echo " *** There are elements of the old rc system in ${DESTDIR}/etc/."
-  echo ''
-  echo '     While these scripts will not hurt anything, they are not'
-  echo '     functional on an up to date system, and can be removed.'
-  echo ''
-
-  case "${AUTO_RUN}" in
-  '')
-    echo -n 'Move these files to /var/tmp/mergemaster/old_rc? [yes] '
-    read MOVE_OLD_RC
-
-    case "${MOVE_OLD_RC}" in
-    [nN]*) ;;
-    *)
-      mkdir -p /var/tmp/mergemaster/old_rc
-        for file in atm devfs diskless1 diskless2 isdn network network6 pccard \
-          serial syscons sysctl alpha amd64 i386 ia64 sparc64; do
-          if [ -f "${DESTDIR}/etc/rc.${file}" ]; then
-            mv ${DESTDIR}/etc/rc.${file} /var/tmp/mergemaster/old_rc/
-          fi
-        done
-      echo '  The files have been moved'
-      press_to_continue
-      ;;
-    esac
-    ;;
-  *) ;;
-  esac
-esac
-
 # Use the umask/mode information to install the files
 # Create directories as needed
 #
@@ -666,12 +611,8 @@ do_install_and_rm () {
   rm -f "${2}"
 }
 
-# 4095 = "obase=10;ibase=8;07777" | bc
 find_mode () {
-  local OCTAL
-  OCTAL=$(( ~$(echo "obase=10; ibase=8; ${CONFIRMED_UMASK}" | bc) & 4095 &
-    $(echo "obase=10; ibase=8; $(stat -f "%OMp%OLp" ${1})" | bc) )) 
-  printf "%04o\n" ${OCTAL}
+  perl -e 'printf "%04o\n", (((stat("$ARGV[0]"))[2] & 07777) &~ oct("$ARGV[1]"))' "${1}" "${CONFIRMED_UMASK}"
 }
 
 mm_install () {
@@ -698,65 +639,17 @@ mm_install () {
       NEED_NEWALIASES=yes
       ;;
     /etc/login.conf)
-      NEED_CAP_MKDB=yes
+      if [ -f /etc/login.conf.db ]; then
+        NEED_CAP_MKDB=yes
+      fi
       ;;
     /etc/master.passwd)
       do_install_and_rm 600 "${1}" "${DESTDIR}${INSTALL_DIR}"
       NEED_PWD_MKDB=yes
       DONT_INSTALL=yes
       ;;
-    /.cshrc | /.profile)
-    case "${AUTO_INSTALL}" in
-    '')
-      case "${LINK_EXPLAINED}" in
-      '')
-        echo "   *** Historically BSD derived systems have had a"
-        echo "       hard link from /.cshrc and /.profile to"
-        echo "       their namesakes in /root.  Please indicate"
-        echo "       your preference below for bringing your"
-        echo "       installed files up to date."
-        echo ''
-        LINK_EXPLAINED=yes
-        ;;
-      esac
-
-      echo "   Use 'd' to delete the temporary ${COMPFILE}"
-      echo "   Use 'l' to delete the existing ${DESTDIR}${COMPFILE#.} and create the link"
-      echo ''
-      echo "   Default is to leave the temporary file to deal with by hand"
-      echo ''
-      echo -n "  How should I handle ${COMPFILE}? [Leave it to install later] "
-      read HANDLE_LINK
-      ;;
-    *)  # Part of AUTO_INSTALL
-      HANDLE_LINK=l
-      ;;
     esac
 
-      case "${HANDLE_LINK}" in
-      [dD]*)
-        rm "${COMPFILE}"
-        echo ''
-        echo "   *** Deleting ${COMPFILE}"
-        ;;
-      [lL]*)
-        echo ''
-        rm -f "${DESTDIR}${COMPFILE#.}"
-        if ln "${DESTDIR}/root/${COMPFILE##*/}" "${DESTDIR}${COMPFILE#.}"; then
-          echo "   *** Link from ${DESTDIR}${COMPFILE#.} to ${DESTDIR}/root/${COMPFILE##*/} installed successfully"
-          rm "${COMPFILE}"
-        else
-          echo "   *** Error linking ${DESTDIR}${COMPFILE#.} to ${DESTDIR}/root/${COMPFILE##*/}, ${COMPFILE} will remain to install by hand"
-        fi
-        ;;
-      *)
-        echo "   *** ${COMPFILE} will remain for your consideration"
-        ;;
-      esac
-      DONT_INSTALL=yes
-      ;;
-    esac
-
     case "${DONT_INSTALL}" in
     '')
       do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}"
@@ -1015,47 +908,27 @@ fi
 case "${COMP_CONFS}" in
 '') ;;
 *)
-  . ${DESTDIR}/etc/defaults/rc.conf
+  . ${DESTDIR}/rc.conf
 
   (echo ''
-  echo "*** Comparing conf files: ${rc_conf_files}"
+  echo "*** Comparing conf files: ${local_rcconf}"
 
-  for CONF_FILE in ${rc_conf_files}; do
+  for CONF_FILE in ${local_rcconf}; do
     if [ -r "${DESTDIR}${CONF_FILE}" ]; then
       echo ''
       echo "*** From ${DESTDIR}${CONF_FILE}"
-      echo "*** From ${DESTDIR}/etc/defaults/rc.conf"
+      echo "*** From ${DESTDIR}/etc/rc.conf"
 
       for RC_CONF_VAR in `grep -i ^[a-z] ${DESTDIR}${CONF_FILE} |
         cut -d '=' -f 1`; do
         echo ''
         grep -w ^${RC_CONF_VAR} ${DESTDIR}${CONF_FILE}
-        grep -w ^${RC_CONF_VAR} ${DESTDIR}/etc/defaults/rc.conf ||
+        grep -w ^${RC_CONF_VAR} ${DESTDIR}/etc/rc.conf ||
           echo ' * No default variable with this name'
       done
     fi
   done) | ${PAGER}
   echo ''
-  ;;
-esac
-
-case "${PRE_WORLD}" in
-'') ;;
-*)
-  MAKE_CONF="${SOURCEDIR%etc}share/examples/etc/make.conf"
-
-  (echo ''
-  echo '*** Comparing make variables'
-  echo ''
-  echo "*** From ${DESTDIR}/etc/make.conf"
-  echo "*** From ${MAKE_CONF}"
-
-  for MAKE_VAR in `grep -i ^[a-z] ${DESTDIR}/etc/make.conf | cut -d '=' -f 1`; do
-    echo ''
-    grep -w ^${MAKE_VAR} ${DESTDIR}/etc/make.conf
-    grep -w ^#${MAKE_VAR} ${MAKE_CONF} ||
-      echo ' * No example variable with this name'
-  done) | ${PAGER}
   ;;
 esac
 
