mergemaster.sh revision 52400
152400Sbillf#!/bin/sh
252400Sbillf
352400Sbillf# mergemaster
452400Sbillf
552400Sbillf# Compare files created by /usr/src/etc/Makefile (or the directory
652400Sbillf# the user specifies) with the currently installed copies.
752400Sbillf
852400Sbillf# Copyright 1998, 1999 Douglas Barton
952400Sbillf# Doug@gorean.org
1052400Sbillf
1152400Sbillf# $Revision: 1.36 $
1252400Sbillf# $Date: 1999/09/10 20:56:33 $
1352400Sbillf
1452400SbillfPATH=/bin:/usr/bin:/usr/sbin
1552400Sbillf
1652400Sbillfdisplay_usage () {
1752400Sbillf  VERSION_NUMBER=`grep "[$]Revision:" $0 | cut -d ' ' -f 3`
1852400Sbillf  echo "mergemaster version ${VERSION_NUMBER}"
1952400Sbillf  echo "Usage: mergemaster [-scrvah] [-m /path] [-t /path] [-d] [-u N] [-w N]"
2052400Sbillf  echo "Options:"
2152400Sbillf  echo "  -s  Strict comparison (diff every pair of files)"
2252400Sbillf  echo "  -c  Use context diff instead of unified diff"
2352400Sbillf  echo "  -r  Re-run on a previously cleaned directory (skip temproot creation)"
2452400Sbillf  echo "  -v  Be more verbose about the process, include additional checks"
2552400Sbillf  echo "  -a  Leave all files that differ to merge by hand"
2652400Sbillf  echo "  -h  Display more complete help"
2752400Sbillf  echo "  -m /path/directory  Specify location of source to do the make in"
2852400Sbillf  echo "  -t /path/directory  Specify temp root directory"
2952400Sbillf  echo "  -d  Add date and time to directory name (e.g., /var/tmp/temproot.`date +%m%d.%H.%M`)"
3052400Sbillf  echo "  -u N  Specify a numeric umask"
3152400Sbillf  echo "  -w N  Specify a screen width in columns to sdiff"
3252400Sbillf  echo ''
3352400Sbillf}
3452400Sbillf
3552400Sbillfdisplay_help () {
3652400Sbillf  echo "* To create a temporary root environment, compare CVS revision \$Ids"
3752400Sbillf  echo "  for files that have them, and compare diffs for files that do not,"
3852400Sbillf  echo "  or have different ones, just type, mergemaster"
3952400Sbillf  echo "* To specify a directory other than /var/tmp/temproot for the"
4052400Sbillf  echo "  temporary root environment, use -t /path/to/temp/root"
4152400Sbillf  echo "* The -w option takes a number as an argument for the column width"
4252400Sbillf  echo "  of the screen. The default is 80."
4352400Sbillf  echo "* The -a option causes mergemaster to run without prompting"
4452400Sbillf}
4552400Sbillf
4652400Sbillf# Set the default path for the temporary root environment
4752400Sbillf#
4852400SbillfTEMPROOT='/var/tmp/temproot'
4952400Sbillf
5052400Sbillf# Read .mergemasterrc before command line so CLI can override
5152400Sbillf#
5252400Sbillfif [ -f "$HOME/.mergemasterrc" ]; then
5352400Sbillf  . "$HOME/.mergemasterrc"
5452400Sbillffi
5552400Sbillf
5652400Sbillf# Check the command line options
5752400Sbillf#
5852400Sbillfwhile getopts ":ascrvhm:t:du:w:" COMMAND_LINE_ARGUMENT ; do
5952400Sbillf  case "${COMMAND_LINE_ARGUMENT}" in
6052400Sbillf  s)
6152400Sbillf    STRICT=yes
6252400Sbillf    ;;
6352400Sbillf  c)
6452400Sbillf    DIFF_FLAG='-c'
6552400Sbillf    ;;
6652400Sbillf  r)
6752400Sbillf    RERUN=yes
6852400Sbillf    ;;
6952400Sbillf  v)
7052400Sbillf    case "${AUTO_RUN}" in
7152400Sbillf    '') VERBOSE=yes ;;
7252400Sbillf    esac
7352400Sbillf    ;;
7452400Sbillf  a)
7552400Sbillf    AUTO_RUN=yes
7652400Sbillf    unset VERBOSE
7752400Sbillf    ;;
7852400Sbillf  h)
7952400Sbillf    display_usage
8052400Sbillf    display_help
8152400Sbillf    exit 0
8252400Sbillf    ;;
8352400Sbillf  m)
8452400Sbillf    SOURCEDIR=${OPTARG}
8552400Sbillf    ;;
8652400Sbillf  t)
8752400Sbillf    TEMPROOT=${OPTARG}
8852400Sbillf    ;;
8952400Sbillf  d)
9052400Sbillf    TEMPROOT=${TEMPROOT}.`date +%m%d.%H.%M`
9152400Sbillf    ;;
9252400Sbillf  u)
9352400Sbillf    NEW_UMASK=${OPTARG}
9452400Sbillf    ;;
9552400Sbillf  w)
9652400Sbillf    SCREEN_WIDTH=${OPTARG}
9752400Sbillf    ;;
9852400Sbillf  *)
9952400Sbillf    display_usage
10052400Sbillf    exit 1
10152400Sbillf    ;;
10252400Sbillf  esac
10352400Sbillfdone
10452400Sbillf
10552400Sbillfecho ''
10652400Sbillf
10752400Sbillf# If the user has a pager defined, make sure we can run it
10852400Sbillf#
10952400Sbillfcase "${DONT_CHECK_PAGER}" in
11052400Sbillf'')
11152400Sbillf  if [ -n "${PAGER}" -a ! -x "${PAGER}" ]; then
11252400Sbillf    echo " *** Your PAGER environment variable specifies '${PAGER}', but"
11352400Sbillf    echo "     I cannot execute it. In general it is good practice to"
11452400Sbillf    echo "     specify the full path for environment variables like"
11552400Sbillf    echo "     PAGER and EDITOR. Meanwhile, what would you like to do?"
11652400Sbillf    echo ''
11752400Sbillf    echo "  Use 'e' to exit mergemaster and fix your PAGER variable"
11852400Sbillf    if [ -x /usr/local/bin/less ]; then
11952400Sbillf    echo "  Use 'l' to set PAGER to /usr/local/bin/less for this run"
12052400Sbillf    fi
12152400Sbillf    echo "  Use 'm' to use plain old 'more' as your PAGER for this run"
12252400Sbillf    echo ''
12352400Sbillf    echo "  Default is to use plain old 'more' "
12452400Sbillf    echo ''
12552400Sbillf    read -p "What should I do? [Use 'more'] " FIXPAGER
12652400Sbillf    case "${FIXPAGER}" in
12752400Sbillf    [eE]*)
12852400Sbillf       exit 0
12952400Sbillf       ;;
13052400Sbillf    [lL]*)
13152400Sbillf       PAGER=/usr/local/bin/less
13252400Sbillf       ;;
13352400Sbillf    *)
13452400Sbillf       PAGER=more
13552400Sbillf       ;;
13652400Sbillf    esac
13752400Sbillf    echo ''
13852400Sbillf  fi
13952400Sbillf  ;;
14052400Sbillfesac
14152400Sbillf
14252400Sbillf# If user has a pager defined, or got assigned one above, use it.
14352400Sbillf# If not, use more.
14452400Sbillf#
14552400SbillfPAGER=${PAGER:-more}
14652400Sbillf
14752400Sbillfif [ -n "${VERBOSE}" -a ! "${PAGER}" = "more" ]; then
14852400Sbillf  echo " *** You have ${PAGER} defined as your pager so we will use that"
14952400Sbillf  echo ''
15052400Sbillf  sleep 3
15152400Sbillffi
15252400Sbillf
15352400Sbillf# Assign the diff flag once so we will not have to keep testing it
15452400Sbillf#
15552400SbillfDIFF_FLAG=${DIFF_FLAG:--u}
15652400Sbillf
15752400Sbillf# Assign the source directory
15852400Sbillf#
15952400SbillfSOURCEDIR=${SOURCEDIR:-/usr/src/etc}
16052400Sbillf
16152400Sbillfcase "${RERUN}" in
16252400Sbillf'')
16352400Sbillf  # Set up the loop to test for the existence of the
16452400Sbillf  # temp root directory.
16552400Sbillf  #
16652400Sbillf  TEST_TEMP_ROOT=yes
16752400Sbillf  while [ "${TEST_TEMP_ROOT}" = "yes" ]; do
16852400Sbillf    if [ -d "${TEMPROOT}" ]; then
16952400Sbillf      echo "*** The directory specified for the temporary root environment,"
17052400Sbillf      echo "    ${TEMPROOT}, exists. This can be a security risk if untrusted"
17152400Sbillf      echo "    users have access to the system."
17252400Sbillf      echo ''
17352400Sbillf      case "${AUTO_RUN}" in
17452400Sbillf      '')
17552400Sbillf        echo "  Use 'd' to delete the old ${TEMPROOT} and continue"
17652400Sbillf        echo "  Use 't' to select a new temporary root directory"
17752400Sbillf        echo "  Use 'e' to exit mergemaster"
17852400Sbillf        echo ''
17952400Sbillf        echo "  Default is to use ${TEMPROOT} as is"
18052400Sbillf        echo ''
18152400Sbillf        read -p "How should I deal with this? [Use the existing ${TEMPROOT}] " DELORNOT
18252400Sbillf          case "${DELORNOT}" in
18352400Sbillf          [dD]*)
18452400Sbillf            echo ''
18552400Sbillf            echo "   *** Deleting the old ${TEMPROOT}"
18652400Sbillf            echo ''
18752400Sbillf            rm -rf "${TEMPROOT}"
18852400Sbillf            unset TEST_TEMP_ROOT
18952400Sbillf            ;;
19052400Sbillf          [tT]*)
19152400Sbillf            echo "   *** Enter new directory name for temporary root environment"
19252400Sbillf            read TEMPROOT
19352400Sbillf            ;;
19452400Sbillf          [eE]*)
19552400Sbillf            exit 0
19652400Sbillf            ;;
19752400Sbillf          *)
19852400Sbillf            echo ''
19952400Sbillf            echo "   *** Leaving ${TEMPROOT} intact"
20052400Sbillf            echo ''
20152400Sbillf            unset TEST_TEMP_ROOT
20252400Sbillf            ;;
20352400Sbillf          esac
20452400Sbillf          ;;
20552400Sbillf      *)
20652400Sbillf        # If this is an auto-run, try a hopefully safe alternative then re-test anyway
20752400Sbillf        TEMPROOT=/var/tmp/temproot.`date +%m%d.%H.%M.%S`
20852400Sbillf        ;;
20952400Sbillf      esac
21052400Sbillf    else
21152400Sbillf      unset TEST_TEMP_ROOT
21252400Sbillf    fi
21352400Sbillf  done
21452400Sbillf
21552400Sbillf  echo "*** Creating the temporary root environment in ${TEMPROOT}"
21652400Sbillf
21752400Sbillf  if mkdir -p "${TEMPROOT}"; then
21852400Sbillf    echo " *** ${TEMPROOT} ready for use"
21952400Sbillf  fi
22052400Sbillf
22152400Sbillf  if [ ! -d "${TEMPROOT}" ]; then
22252400Sbillf    echo ''
22352400Sbillf    echo "  *** FATAL ERROR: Cannot create ${TEMPROOT}"
22452400Sbillf    echo ''
22552400Sbillf    exit 1
22652400Sbillf  fi
22752400Sbillf
22852400Sbillf  echo " *** Creating and populating directory structure in ${TEMPROOT}"
22952400Sbillf  echo ''
23052400Sbillf
23152400Sbillf  case "${VERBOSE}" in
23252400Sbillf  '') ;;
23352400Sbillf  *)
23452400Sbillf    echo " *** Press [Enter] or [Return] key to continue"
23552400Sbillf    read ANY_KEY
23652400Sbillf    unset ANY_KEY
23752400Sbillf    ;;
23852400Sbillf  esac
23952400Sbillf
24052400Sbillf  { cd ${SOURCEDIR} &&
24152400Sbillf    make DESTDIR=${TEMPROOT} distrib-dirs &&
24252400Sbillf    make DESTDIR=${TEMPROOT} distribution;} ||
24352400Sbillf  { echo '';
24452400Sbillf    echo "  *** FATAL ERROR: Cannot 'cd' to ${SOURCEDIR} and install files to the";
24552400Sbillf    echo "      temproot environment";
24652400Sbillf    echo '';
24752400Sbillf    exit 1;}
24852400Sbillf
24952400Sbillf  # We really don't want to have to deal with these files, since
25052400Sbillf  # master.passwd is the real file that should be compared, then
25152400Sbillf  # the user should run pwd_mkdb if necessary.
25252400Sbillf  # Only do this if we are not rerun'ing, since if we are the
25352400Sbillf  # files will not be there.
25452400Sbillf  #
25552400Sbillf  rm ${TEMPROOT}/etc/spwd.db ${TEMPROOT}/etc/passwd ${TEMPROOT}/etc/pwd.db
25652400Sbillf
25752400Sbillf  ;; # End of the "RERUN" test
25852400Sbillfesac
25952400Sbillf
26052400Sbillf# Get ready to start comparing files
26152400Sbillf
26252400Sbillfcase "${VERBOSE}" in
26352400Sbillf'') ;;
26452400Sbillf*)
26552400Sbillf  echo ''
26652400Sbillf  echo " *** The following files exist only in the installed version"
26752400Sbillf  echo "     of /etc. In the far majority of cases these files are"
26852400Sbillf  echo "     necessary parts of the system and should not be deleted,"
26952400Sbillf  echo "     however because these files are not updated by this process"
27052400Sbillf  echo "     you might want to verify their status before rebooting your system."
27152400Sbillf  echo ''
27252400Sbillf  echo " *** Press [Enter] or [Return] key to continue"
27352400Sbillf  read ANY_KEY
27452400Sbillf  unset ANY_KEY
27552400Sbillf  diff -qr /etc ${TEMPROOT}/etc | grep "^Only in /etc" | ${PAGER}
27652400Sbillf  echo ''
27752400Sbillf  echo " *** Press [Enter] or [Return] key to continue"
27852400Sbillf  read ANY_KEY
27952400Sbillf  unset ANY_KEY
28052400Sbillf  ;;
28152400Sbillfesac
28252400Sbillf
28352400Sbillf# Check umask if not specified on the command line,
28452400Sbillf# and we are not doing an autorun
28552400Sbillf#
28652400Sbillfif [ -z "${NEW_UMASK}" -a -z "${AUTO_RUN}" ]; then
28752400Sbillf  USER_UMASK=`umask`
28852400Sbillf  case "${USER_UMASK}" in
28952400Sbillf  0022) ;;
29052400Sbillf  *)
29152400Sbillf    echo ''
29252400Sbillf    echo " *** Your umask is currently set to ${USER_UMASK}. By default, this script"
29352400Sbillf    echo "     installs all files with the same user, group and modes that"
29452400Sbillf    echo "     they are created with by ${SOURCEDIR}/Makefile, compared to"
29552400Sbillf    echo "     a umask of 022. This umask allows world read permission when"
29652400Sbillf    echo "     the file's default permissions have it."
29752400Sbillf    echo "     No world permissions can sometimes cause problems. A umask of"
29852400Sbillf    echo "     022 will restore the default behavior, but is not mandatory."
29952400Sbillf    echo "     /etc/master.passwd is a special case. Its file permissions"
30052400Sbillf    echo "     will be 600 (rw-------) if installed."
30152400Sbillf    echo ''
30252400Sbillf    read -p "What umask should I use? [${USER_UMASK}] " NEW_UMASK
30352400Sbillf    NEW_UMASK="${NEW_UMASK:-$USER_UMASK}"
30452400Sbillf    ;;
30552400Sbillf  esac
30652400Sbillf  echo ''
30752400Sbillffi
30852400Sbillf
30952400SbillfCONFIRMED_UMASK=${NEW_UMASK:-0022}
31052400Sbillf
31152400Sbillf# Warn users who have an /etc/sysconfig file
31252400Sbillf#
31352400Sbillfif [ -f /etc/sysconfig ]; then
31452400Sbillf  echo " *** There is an /etc/sysconfig file on this system. Starting with"
31552400Sbillf  echo "     FreeBSD version 2.2.2 those settings have moved from /etc/sysconfig"
31652400Sbillf  echo "     to /etc/rc.conf. If you are upgrading an older system make sure"
31752400Sbillf  echo "     that you transfer your settings by hand from sysconfig to rc.conf and"
31852400Sbillf  echo "     install the rc.conf file. If you have already made this transition,"
31952400Sbillf  echo "     you should consider renaming or deleting the /etc/sysconfig file."
32052400Sbillf  echo ''
32152400Sbillf  case "${AUTO_RUN}" in
32252400Sbillf  '')
32352400Sbillf    read -p "Continue with the merge process? [yes] " CONT_OR_NOT
32452400Sbillf    case "${CONT_OR_NOT}" in
32552400Sbillf    [nN]*)
32652400Sbillf      exit 0
32752400Sbillf      ;;
32852400Sbillf    *)
32952400Sbillf      echo "   *** Continuing"
33052400Sbillf      echo ''
33152400Sbillf      ;;
33252400Sbillf    esac
33352400Sbillf    ;;
33452400Sbillf  *) ;;
33552400Sbillf  esac
33652400Sbillffi
33752400Sbillf
33852400Sbillfecho ''
33952400Sbillfecho "*** Beginning comparison"
34052400Sbillfecho ''
34152400Sbillf
34252400Sbillfcd "${TEMPROOT}"
34352400Sbillf
34452400Sbillf# Use the umask/mode information to install the files
34552400Sbillf# Create directories as needed
34652400Sbillf#
34752400Sbillfmm_install () {
34852400Sbillf  local INSTALL_DIR
34952400Sbillf  INSTALL_DIR=${1#.}
35052400Sbillf  INSTALL_DIR=${INSTALL_DIR%/*}
35152400Sbillf  case "${INSTALL_DIR}" in
35252400Sbillf  '')
35352400Sbillf    INSTALL_DIR=/
35452400Sbillf    ;;
35552400Sbillf  esac
35652400Sbillf
35752400Sbillf  if [ -n "${INSTALL_DIR}" -a ! -d "${INSTALL_DIR}" ]; then
35852400Sbillf    DIR_MODE=`perl -e 'printf "%04o\n", (((stat("$ARGV[0]"))[2] & 07777) &~ oct("$ARGV[1]"))' "${TEMPROOT}/${INSTALL_DIR}" "${CONFIRMED_UMASK}"`
35952400Sbillf    install -d -o root -g wheel -m "${DIR_MODE}" "${INSTALL_DIR}"
36052400Sbillf  fi
36152400Sbillf
36252400Sbillf  FILE_MODE=`perl -e 'printf "%04o\n", (((stat("$ARGV[0]"))[2] & 07777) &~ oct("$ARGV[1]"))' "${1}" "${CONFIRMED_UMASK}"`
36352400Sbillf
36452400Sbillf  if [ ! -x "${1}" ]; then
36552400Sbillf    case "${1#.}" in
36652400Sbillf    /dev/MAKEDEV)
36752400Sbillf      NEED_MAKEDEV=yes
36852400Sbillf      ;;
36952400Sbillf    /etc/aliases)
37052400Sbillf      NEED_NEWALIASES=yes
37152400Sbillf      ;;
37252400Sbillf    /etc/login.conf)
37352400Sbillf      NEED_CAP_MKDB=yes
37452400Sbillf      ;;
37552400Sbillf    /etc/master.passwd)
37652400Sbillf      install -m 600 "${1}" "${INSTALL_DIR}"
37752400Sbillf      NEED_PWD_MKDB=yes
37852400Sbillf      DONT_INSTALL=yes
37952400Sbillf      ;;
38052400Sbillf    /.cshrc | /.profile)
38152400Sbillf      case "${LINK_EXPLAINED}" in
38252400Sbillf      '')
38352400Sbillf        echo "   *** Historically FreeBSD has had a hard link from"
38452400Sbillf        echo "       /.cshrc and /.profile to their namesakes in"
38552400Sbillf        echo "       /root. Please indicate your preference below"
38652400Sbillf        echo "       for bringing your installed files up to date."
38752400Sbillf        echo ''
38852400Sbillf        LINK_EXPLAINED=yes
38952400Sbillf        ;;
39052400Sbillf      esac
39152400Sbillf
39252400Sbillf      echo "   Use 'd' to delete the temporary ${COMPFILE}"
39352400Sbillf      echo "   Use 'l' to delete the existing ${COMPFILE#.} and create the link"
39452400Sbillf      echo ''
39552400Sbillf      echo "   Default is to leave the temporary file to deal with by hand"
39652400Sbillf      echo ''
39752400Sbillf      read -p "  How should I handle ${COMPFILE}? [Leave it to install later] " HANDLE_LINK
39852400Sbillf      case "${HANDLE_LINK}" in
39952400Sbillf      [dD]*)
40052400Sbillf        rm "${COMPFILE}"
40152400Sbillf        echo ''
40252400Sbillf        echo "   *** Deleting ${COMPFILE}"
40352400Sbillf        ;;
40452400Sbillf      [lL]*)
40552400Sbillf        echo ''
40652400Sbillf        if [ -e "${COMPFILE#.}" ]; then
40752400Sbillf          rm "${COMPFILE#.}"
40852400Sbillf        fi
40952400Sbillf        if ln "/root/${COMPFILE##*/}" "${COMPFILE#.}"; then
41052400Sbillf          echo "   *** Link from ${COMPFILE#.} to /root/${COMPFILE##*/} installed successfully"
41152400Sbillf          rm "${COMPFILE}"
41252400Sbillf        else
41352400Sbillf          echo "   *** Error linking ${COMPFILE#.} to /root/${COMPFILE##*/}, ${COMPFILE} will remain to install by hand"
41452400Sbillf        fi
41552400Sbillf        ;;
41652400Sbillf      *)
41752400Sbillf        echo "   *** ${COMPFILE} will remain for your consideration"
41852400Sbillf        ;;
41952400Sbillf      esac
42052400Sbillf      DONT_INSTALL=yes
42152400Sbillf      ;;
42252400Sbillf    esac
42352400Sbillf
42452400Sbillf    case "${DONT_INSTALL}" in
42552400Sbillf    '')
42652400Sbillf      install -m "${FILE_MODE}" "${1}" "${INSTALL_DIR}"
42752400Sbillf      ;;
42852400Sbillf    *)
42952400Sbillf      unset DONT_INSTALL
43052400Sbillf      ;;
43152400Sbillf    esac
43252400Sbillf
43352400Sbillf  else
43452400Sbillf    install -m "${FILE_MODE}" "${1}" "${INSTALL_DIR}"
43552400Sbillf  fi
43652400Sbillf  return $?
43752400Sbillf}
43852400Sbillf
43952400Sbillfcompare_ids () {
44052400Sbillf  case "${1}" in
44152400Sbillf "${2}")
44252400Sbillf    echo " *** Temp ${COMPFILE} and installed have the same ${IDTAG}, deleting"
44352400Sbillf    rm "${COMPFILE}"
44452400Sbillf    ;;
44552400Sbillf  esac
44652400Sbillf}
44752400Sbillf
44852400Sbillf# Using -size +0 avoids uselessly checking the empty log files created
44952400Sbillf# by ${SOURCEDIR}/Makefile and the device entries in ./dev, but does
45052400Sbillf# check the scripts in ./dev, as we'd like.
45152400Sbillf#
45252400Sbillffor COMPFILE in `find . -type f -size +0`; do
45352400Sbillf  case "${STRICT}" in
45452400Sbillf  '' | [Nn][Oo])
45552400Sbillf    # Compare CVS $Id's first so if the file hasn't been modified
45652400Sbillf    # local changes will be ignored.
45752400Sbillf    # If the files have the same $Id, delete the one in temproot so the
45852400Sbillf    # user will have less to wade through if files are left to merge by hand.
45952400Sbillf    # Take the $Id -> $FreeBSD tag change into account
46052400Sbillf    #
46152400Sbillf    FREEBSDID1=`grep "[$]FreeBSD:" ${COMPFILE#.} 2>/dev/null`
46252400Sbillf    FREEBSDID2=`grep "[$]FreeBSD:" ${COMPFILE} 2>/dev/null`
46352400Sbillf
46452400Sbillf    if [ -n "${FREEBSDID1}" -a -n "${FREEBSDID2}" ]; then
46552400Sbillf      IDTAG='$FreeBSD'
46652400Sbillf      compare_ids "${FREEBSDID1}" "${FREEBSDID2}"
46752400Sbillf    else
46852400Sbillf      CVSID1=`grep "[$]Id:" ${COMPFILE#.} 2>/dev/null`
46952400Sbillf      CVSID2=`grep "[$]Id:" ${COMPFILE} 2>/dev/null`
47052400Sbillf
47152400Sbillf      if [ -n "${CVSID1}" -a -n "${CVSID2}" ]; then
47252400Sbillf        IDTAG='$Id'
47352400Sbillf        compare_ids "${CVSID1}" "${CVSID2}"
47452400Sbillf      fi
47552400Sbillf    fi
47652400Sbillf    ;;
47752400Sbillf  esac
47852400Sbillf
47952400Sbillf  # If the file is still here either because the $Ids are different, the
48052400Sbillf  # file doesn't have an $Id, or we're using STRICT mode; look at the diff.
48152400Sbillf  #
48252400Sbillf  if [ -f "${COMPFILE}" ]; then
48352400Sbillf
48452400Sbillf    # Do an absolute diff first to see if the files are actually different.
48552400Sbillf    # If they're not different, delete the one in temproot.
48652400Sbillf    #
48752400Sbillf    if diff -q "${COMPFILE#.}" "${COMPFILE}" > /dev/null 2>&1; then
48852400Sbillf      echo " *** Temp ${COMPFILE} and installed are the same, deleting"
48952400Sbillf      rm "${COMPFILE}"
49052400Sbillf    else
49152400Sbillf      # Ok, the files are different, so show the user where they differ. Use user's
49252400Sbillf      # choice of diff methods; and user's pager if they have one. Use more if not.
49352400Sbillf      # Use unified diffs by default. Context diffs give me a headache. :)
49452400Sbillf      #
49552400Sbillf      case "${AUTO_RUN}" in
49652400Sbillf      '')
49752400Sbillf        echo ''
49852400Sbillf        if [ -f "${COMPFILE#.}" -a -f "${COMPFILE}" ]; then
49952400Sbillf          echo "  *** Displaying differences between ${COMPFILE} and installed version"
50052400Sbillf          echo ''
50152400Sbillf          diff "${DIFF_FLAG}" "${COMPFILE#.}" "${COMPFILE}" | ${PAGER}
50252400Sbillf          echo ''
50352400Sbillf        else
50452400Sbillf          echo "  *** There is no installed version of ${COMPFILE}"
50552400Sbillf          NO_INSTALLED=yes
50652400Sbillf        fi
50752400Sbillf        echo "  Use 'd' to delete the temporary ${COMPFILE}"
50852400Sbillf        echo "  Use 'i' to install the temporary ${COMPFILE}"
50952400Sbillf        case "${NO_INSTALLED}" in
51052400Sbillf        '')
51152400Sbillf          echo "  Use 'm' to merge the old and new versions"
51252400Sbillf          ;;
51352400Sbillf        esac
51452400Sbillf        echo ''
51552400Sbillf        echo "  Default is to leave the temporary file to deal with by hand"
51652400Sbillf        echo ''
51752400Sbillf        read -p "How should I deal with this? [Leave it for later] " HANDLE_COMPFILE
51852400Sbillf        case "${HANDLE_COMPFILE}" in
51952400Sbillf        [dD]*)
52052400Sbillf          rm "${COMPFILE}"
52152400Sbillf          echo ''
52252400Sbillf          echo "   *** Deleting ${COMPFILE}"
52352400Sbillf          ;;
52452400Sbillf        [iI]*)
52552400Sbillf          echo ''
52652400Sbillf          if mm_install "${COMPFILE}"; then
52752400Sbillf            echo "   *** ${COMPFILE} installed successfully"
52852400Sbillf          else
52952400Sbillf            echo "   *** Problem installing ${COMPFILE}, it will remain to merge by hand"
53052400Sbillf          fi
53152400Sbillf          ;;
53252400Sbillf        [mM]*)
53352400Sbillf          case "${NO_INSTALLED}" in
53452400Sbillf          '')
53552400Sbillf            case "${VERBOSE}" in
53652400Sbillf            '') ;;
53752400Sbillf            *)
53852400Sbillf              echo "   *** Type h at the sdiff prompt (%) to get usage help"
53952400Sbillf              ;;
54052400Sbillf            esac
54152400Sbillf            echo ''
54252400Sbillf            MERGE_AGAIN=yes
54352400Sbillf            while [ "${MERGE_AGAIN}" = "yes" ]; do
54452400Sbillf              # Prime file.merged so we don't blat the owner/group id's
54552400Sbillf              cp -p "${COMPFILE}" "${COMPFILE}.merged"
54652400Sbillf              sdiff -o "${COMPFILE}.merged" --text --suppress-common-lines \
54752400Sbillf                --width=${SCREEN_WIDTH:-80} "${COMPFILE#.}" "${COMPFILE}"
54852400Sbillf
54952400Sbillf              echo ''
55052400Sbillf              echo "  Use 'i' to install merged file"
55152400Sbillf              echo "  Use 'r' to re-do the merge"
55252400Sbillf              echo "  Default is to leave the temporary file to deal with by hand"
55352400Sbillf              echo ''
55452400Sbillf              read -p "    *** How should I deal with the merged file? [Leave it for later] " INSTALL_MERGED
55552400Sbillf
55652400Sbillf              case "${INSTALL_MERGED}" in
55752400Sbillf              [iI]*)
55852400Sbillf                mv "${COMPFILE}.merged" "${COMPFILE}"
55952400Sbillf                echo ''
56052400Sbillf                if mm_install "${COMPFILE}"; then
56152400Sbillf                  echo "     *** Merged version of ${COMPFILE} installed successfully"
56252400Sbillf                else 
56352400Sbillf                  echo "     *** Problem installing ${COMPFILE}, it will remain to merge by hand later"
56452400Sbillf                fi 
56552400Sbillf                unset MERGE_AGAIN
56652400Sbillf                ;;
56752400Sbillf              [rR]*)
56852400Sbillf                rm "${COMPFILE}.merged"
56952400Sbillf                ;; 
57052400Sbillf              *)
57152400Sbillf                echo "   *** ${COMPFILE} will remain for your consideration"
57252400Sbillf                unset MERGE_AGAIN
57352400Sbillf              ;;
57452400Sbillf              esac
57552400Sbillf            done
57652400Sbillf            ;;
57752400Sbillf          *)
57852400Sbillf            echo ''
57952400Sbillf            echo "   *** There is no installed version of ${COMPFILE}"
58052400Sbillf            echo "       to merge so it will remain to install by hand later"
58152400Sbillf            echo ''
58252400Sbillf            echo "   *** Press [Enter] or [Return] key to continue"
58352400Sbillf            read ANY_KEY
58452400Sbillf            unset ANY_KEY
58552400Sbillf            ;;
58652400Sbillf          esac # End of "No installed version of file but user selected merge" test
58752400Sbillf          ;;
58852400Sbillf        *)
58952400Sbillf          echo ''
59052400Sbillf          echo "   *** ${COMPFILE} will remain for your consideration"
59152400Sbillf          ;;
59252400Sbillf        esac  # End of "How to handle files that are different"
59352400Sbillf        unset NO_INSTALLED
59452400Sbillf        echo ''
59552400Sbillf        case "${VERBOSE}" in
59652400Sbillf        '') ;;
59752400Sbillf        *)
59852400Sbillf          sleep 3
59952400Sbillf          ;;
60052400Sbillf        esac
60152400Sbillf        ;;
60252400Sbillf      *)
60352400Sbillf        # If this is an auto run, make it official
60452400Sbillf        echo "   *** ${COMPFILE} will remain for your consideration"
60552400Sbillf        ;;
60652400Sbillf      esac # Auto run test
60752400Sbillf    fi # Yes, the files are different
60852400Sbillf  fi # Yes, the file still remains to be checked
60952400Sbillfdone # This is for the do way up there at the beginning of the comparison
61052400Sbillf
61152400Sbillfecho "*** Comparison complete"
61252400Sbillfecho ''
61352400Sbillf
61452400SbillfTEST_FOR_FILES=`find ${TEMPROOT} -type f -size +0 2>/dev/null`
61552400Sbillfif [ -n "${TEST_FOR_FILES}" ]; then
61652400Sbillf  echo "*** Files that remain for you to merge by hand:"
61752400Sbillf  find "${TEMPROOT}" -type f -size +0
61852400Sbillffi
61952400Sbillf
62052400Sbillfcase "${AUTO_RUN}" in
62152400Sbillf'')
62252400Sbillf  echo ''
62352400Sbillf  read -p "Do you wish to delete what is left of ${TEMPROOT}? [no] " DEL_TEMPROOT
62452400Sbillf  case "${DEL_TEMPROOT}" in
62552400Sbillf  [yY]*)
62652400Sbillf    if rm -rf "${TEMPROOT}"; then
62752400Sbillf      echo " *** ${TEMPROOT} has been deleted"
62852400Sbillf    else
62952400Sbillf      echo " *** Unable to delete ${TEMPROOT}"
63052400Sbillf    fi
63152400Sbillf    ;;
63252400Sbillf  *)
63352400Sbillf    echo " *** ${TEMPROOT} will remain"
63452400Sbillf    ;;
63552400Sbillf  esac
63652400Sbillf  ;;
63752400Sbillf*) ;;
63852400Sbillfesac
63952400Sbillf
64052400Sbillfcase "${NEED_MAKEDEV}" in
64152400Sbillf'') ;;
64252400Sbillf*)
64352400Sbillf  echo ''
64452400Sbillf  echo "*** You installed a new /dev/MAKEDEV script, so make sure that you run"
64552400Sbillf  echo "    'cd /dev && /bin/sh MAKEDEV all' to rebuild your devices"
64652400Sbillf  ;;
64752400Sbillfesac
64852400Sbillf
64952400Sbillfcase "${NEED_NEWALIASES}" in
65052400Sbillf'') ;;
65152400Sbillf*)
65252400Sbillf  echo ''
65352400Sbillf  echo "*** You installed a new aliases file, so make sure that you run"
65452400Sbillf  echo "    'newaliases' to rebuild your aliases database"
65552400Sbillf  ;;
65652400Sbillfesac
65752400Sbillf
65852400Sbillfcase "${NEED_CAP_MKDB}" in
65952400Sbillf'') ;;
66052400Sbillf*)
66152400Sbillf  echo ''
66252400Sbillf  echo "*** You installed a login.conf file, so make sure that you run"
66352400Sbillf  echo "    'cap_mkdb /etc/login.conf' to rebuild your login.conf database"
66452400Sbillf  ;;
66552400Sbillfesac
66652400Sbillf
66752400Sbillfcase "${NEED_PWD_MKDB}" in
66852400Sbillf'') ;;
66952400Sbillf*)
67052400Sbillf  echo ''
67152400Sbillf  echo "*** You installed a new master.passwd file, so make sure that you run"
67252400Sbillf  echo "    'pwd_mkdb -p /etc/master.passwd' to rebuild your password files"
67352400Sbillf  ;;
67452400Sbillfesac
67552400Sbillf
67652400Sbillfecho ''
67752400Sbillf
67852400Sbillfexit 0
679