$OpenBSD: patch-mergemaster_sh,v 1.7 2003/07/23 19:12:18 naddy Exp $
--- mergemaster.sh.orig	Sun May 11 00:06:02 2003
+++ mergemaster.sh	Wed Jul 23 02:40:22 2003
@@ -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`
@@ -59,7 +59,7 @@ merge_loop () {
   while [ "${MERGE_AGAIN}" = "yes" ]; do
     # Prime file.merged so we don't blat the owner/group id's
     cp -p "${COMPFILE}" "${COMPFILE}.merged"
-    sdiff -o "${COMPFILE}.merged" --text --suppress-common-lines \
+    gsdiff -o "${COMPFILE}.merged" --text --suppress-common-lines \
       --width=${SCREEN_WIDTH:-80} "${DESTDIR}${COMPFILE#.}" "${COMPFILE}"
     INSTALL_MERGED=V
     while [ "${INSTALL_MERGED}" = "v" -o "${INSTALL_MERGED}" = "V" ]; do
@@ -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,10 +559,7 @@ 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
-
-# We only need to compare things like freebsd.cf once
-find ${TEMPROOT}/usr/obj -type f -delete 2>/dev/null
+rm -f ${TEMPROOT}/etc/*.db ${TEMPROOT}/etc/mail/*.db ${TEMPROOT}/etc/passwd
 
 # Get ready to start comparing files
 
@@ -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,7 +639,9 @@ 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}"
@@ -1015,47 +958,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
 
