mergemaster.sh revision 68507
1#!/bin/sh
2
3# mergemaster
4
5# Compare files created by /usr/src/etc/Makefile (or the directory
6# the user specifies) with the currently installed copies.
7
8# Copyright 1998-2000 Douglas Barton
9# Doug@gorean.org
10
11# $FreeBSD: head/usr.sbin/mergemaster/mergemaster.sh 68507 2000-11-09 00:19:21Z dougb $
12
13PATH=/bin:/usr/bin:/usr/sbin
14
15display_usage () {
16  VERSION_NUMBER=`grep "[$]FreeBSD:" $0 | cut -d ' ' -f 4`
17  echo "mergemaster version ${VERSION_NUMBER}"
18  echo 'Usage: mergemaster [-scrvahi] [-m /path]'
19  echo '         [-t /path] [-d] [-u N] [-w N] [-D /path]'
20  echo "Options:"
21  echo "  -s  Strict comparison (diff every pair of files)"
22  echo "  -c  Use context diff instead of unified diff"
23  echo "  -r  Re-run on a previously cleaned directory (skip temproot creation)"
24  echo "  -v  Be more verbose about the process, include additional checks"
25  echo "  -a  Leave all files that differ to merge by hand"
26  echo "  -h  Display more complete help"
27  echo '  -i  Automatically install files that do not exist in destination directory'
28  echo "  -m /path/directory  Specify location of source to do the make in"
29  echo "  -t /path/directory  Specify temp root directory"
30  echo "  -d  Add date and time to directory name (e.g., /var/tmp/temproot.`date +%m%d.%H.%M`)"
31  echo "  -u N  Specify a numeric umask"
32  echo "  -w N  Specify a screen width in columns to sdiff"
33  echo '  -D /path/directory  Specify the destination directory to install files to'
34  echo ''
35}
36
37display_help () {
38  echo "* To specify a directory other than /var/tmp/temproot for the"
39  echo "  temporary root environment, use -t /path/to/temp/root"
40  echo "* The -w option takes a number as an argument for the column width"
41  echo "  of the screen.  The default is 80."
42  echo '* The -a option causes mergemaster to run without prompting.'
43}
44
45# Loop allowing the user to use sdiff to merge files and display the merged
46# file.
47merge_loop () {
48  case "${VERBOSE}" in
49  '') ;;
50  *)
51      echo "   *** Type h at the sdiff prompt (%) to get usage help"
52      ;;
53  esac
54  echo ''
55  MERGE_AGAIN=yes
56  while [ "${MERGE_AGAIN}" = "yes" ]; do
57    # Prime file.merged so we don't blat the owner/group id's
58    cp -p "${COMPFILE}" "${COMPFILE}.merged"
59    sdiff -o "${COMPFILE}.merged" --text --suppress-common-lines \
60      --width=${SCREEN_WIDTH:-80} "${DESTDIR}${COMPFILE#.}" "${COMPFILE}"
61    INSTALL_MERGED=V
62    while [ "${INSTALL_MERGED}" = "v" -o "${INSTALL_MERGED}" = "V" ]; do
63      echo ''
64      echo "  Use 'i' to install merged file"
65      echo "  Use 'r' to re-do the merge"
66      echo "  Use 'v' to view the merged file"
67      echo "  Default is to leave the temporary file to deal with by hand"
68      echo ''
69      echo -n "    *** How should I deal with the merged file? [Leave it for later] "
70      read INSTALL_MERGED
71
72      case "${INSTALL_MERGED}" in
73      [iI])
74        mv "${COMPFILE}.merged" "${COMPFILE}"
75        echo ''
76        if mm_install "${COMPFILE}"; then
77          echo "     *** Merged version of ${COMPFILE} installed successfully"
78        else
79          echo "     *** Problem installing ${COMPFILE}, it will remain to merge by hand later"
80        fi
81        unset MERGE_AGAIN
82        ;;
83      [rR])
84        rm "${COMPFILE}.merged"
85        ;;
86      [vV])
87        ${PAGER} "${COMPFILE}.merged"
88        ;;
89      '')
90        echo "   *** ${COMPFILE} will remain for your consideration"
91        unset MERGE_AGAIN
92        ;;
93      *)
94        echo "invalid choice: ${INSTALL_MERGED}"
95        INSTALL_MERGED=V
96        ;;
97      esac
98    done
99  done
100}
101
102# Loop showing user differences between files, allow merge, skip or install
103# options
104diff_loop () {
105
106  HANDLE_COMPFILE=v
107
108  while [ "${HANDLE_COMPFILE}" = "v" -o "${HANDLE_COMPFILE}" = "V" -o "${HANDLE_COMPFILE}" = "NOT V" ]; do
109    if [ -f "${DESTDIR}${COMPFILE#.}" -a -f "${COMPFILE}" ]; then
110      if [ "${HANDLE_COMPFILE}" = "v" -o "${HANDLE_COMPFILE}" = "V" ]; then
111        (
112          echo ''
113          echo "  *** Displaying differences between ${COMPFILE} and installed version:"
114          echo ''
115          diff "${DIFF_FLAG}" "${DESTDIR}${COMPFILE#.}" "${COMPFILE}"
116        ) | ${PAGER}
117        echo ''
118      fi
119    else
120      echo ''
121      echo "  *** There is no installed version of ${COMPFILE}"
122      case "${AUTO_INSTALL}" in
123      [Yy][Ee][Ss])
124        echo ''
125        if mm_install "${COMPFILE}"; then
126          echo "   *** ${COMPFILE} installed successfully"
127          echo ''
128          # Make the list print one file per line
129          AUTO_INSTALLED_FILES="${AUTO_INSTALLED_FILES}      ${DESTDIR}${COMPFILE#.}
130"
131        else
132          echo "   *** Problem installing ${COMPFILE}, it will remain to merge by hand"
133        fi
134        return
135        ;;
136      *)
137        NO_INSTALLED=yes
138        ;;
139      esac
140    fi
141
142    echo "  Use 'd' to delete the temporary ${COMPFILE}"
143    echo "  Use 'i' to install the temporary ${COMPFILE}"
144    case "${NO_INSTALLED}" in
145    '')
146      echo "  Use 'm' to merge the old and new versions"
147      echo "  Use 'v' to view to differences between the old and new versions again"
148      ;;
149    esac
150    echo ''
151    echo "  Default is to leave the temporary file to deal with by hand"
152    echo ''
153    echo -n "How should I deal with this? [Leave it for later] "
154    read HANDLE_COMPFILE
155
156    case "${HANDLE_COMPFILE}" in
157    [dD])
158      rm "${COMPFILE}"
159      echo ''
160      echo "   *** Deleting ${COMPFILE}"
161      ;;
162    [iI])
163      echo ''
164      if mm_install "${COMPFILE}"; then
165        echo "   *** ${COMPFILE} installed successfully"
166      else
167        echo "   *** Problem installing ${COMPFILE}, it will remain to merge by hand"
168      fi
169      ;;
170    [mM])
171      case "${NO_INSTALLED}" in
172      '')
173        # interact with user to merge files
174        merge_loop
175        ;;
176      *)
177        echo ''
178        echo "   *** There is no installed version of ${COMPFILE}"
179        echo ''
180        HANDLE_COMPFILE="NOT V"
181        ;;
182      esac # End of "No installed version of file but user selected merge" test
183      ;;
184    [vV])
185      continue
186      ;;
187    '')
188      echo ''
189      echo "   *** ${COMPFILE} will remain for your consideration"
190      ;;
191    *)
192      # invalid choice, show menu again.
193      echo "invalid choice: ${HANDLE_COMPFILE}"
194      echo ''
195      HANDLE_COMPFILE="NOT V"
196      continue
197      ;;
198    esac  # End of "How to handle files that are different"
199  done
200  unset NO_INSTALLED
201  echo ''
202  case "${VERBOSE}" in
203  '') ;;
204  *)
205    sleep 3
206    ;;
207  esac
208}
209
210# Set the default path for the temporary root environment
211#
212TEMPROOT='/var/tmp/temproot'
213
214# Read .mergemasterrc before command line so CLI can override
215#
216if [ -r "$HOME/.mergemasterrc" ]; then
217  . "$HOME/.mergemasterrc"
218fi
219
220# Check the command line options
221#
222while getopts ":ascrvhim:t:du:w:D:" COMMAND_LINE_ARGUMENT ; do
223  case "${COMMAND_LINE_ARGUMENT}" in
224  s)
225    STRICT=yes
226    ;;
227  c)
228    DIFF_FLAG='-c'
229    ;;
230  r)
231    RERUN=yes
232    ;;
233  v)
234    case "${AUTO_RUN}" in
235    '') VERBOSE=yes ;;
236    esac
237    ;;
238  a)
239    AUTO_RUN=yes
240    unset VERBOSE
241    ;;
242  h)
243    display_usage
244    display_help
245    exit 0
246    ;;
247  i)
248    AUTO_INSTALL=yes
249    ;;
250  m)
251    SOURCEDIR=${OPTARG}
252    ;;
253  t)
254    TEMPROOT=${OPTARG}
255    ;;
256  d)
257    TEMPROOT=${TEMPROOT}.`date +%m%d.%H.%M`
258    ;;
259  u)
260    NEW_UMASK=${OPTARG}
261    ;;
262  w)
263    SCREEN_WIDTH=${OPTARG}
264    ;;
265  D)
266    DESTDIR=${OPTARG}
267    ;;
268  *)
269    display_usage
270    exit 1
271    ;;
272  esac
273done
274
275echo ''
276
277# If the user has a pager defined, make sure we can run it
278#
279case "${DONT_CHECK_PAGER}" in
280'')
281  while ! type "${PAGER%% *}" >/dev/null && [ -n "${PAGER}" ]; do
282    echo " *** Your PAGER environment variable specifies '${PAGER}', but"
283    echo "     due to the limited PATH that I use for security reasons,"
284    echo "     I cannot execute it.  So, what would you like to do?"
285    echo ''
286    echo "  Use 'e' to exit mergemaster and fix your PAGER variable"
287    if [ -x /usr/bin/less -o -x /usr/local/bin/less ]; then
288    echo "  Use 'l' to set PAGER to 'less' for this run"
289    fi
290    echo "  Use 'm' to use plain old 'more' as your PAGER for this run"
291    echo ''
292    echo "  Default is to use plain old 'more' "
293    echo ''
294    echo -n "What should I do? [Use 'more'] "
295    read FIXPAGER
296
297    case "${FIXPAGER}" in
298    [eE])
299       exit 0
300       ;;
301    [lL])
302       if [ -x /usr/bin/less ]; then
303         PAGER=/usr/bin/less
304       elif [ -x /usr/local/bin/less ]; then
305         PAGER=/usr/local/bin/less
306       else
307         echo ''
308         echo " *** Fatal Error:"
309         echo "     You asked to use 'less' as your pager, but I can't"
310         echo "     find it in /usr/bin or /usr/local/bin"
311         exit 1
312       fi
313       ;;
314    [mM]|'')
315       PAGER=more
316       ;;
317    *)
318       echo ''
319       echo "invalid choice: ${FIXPAGER}"
320    esac
321    echo ''
322  done
323  ;;
324esac
325
326# If user has a pager defined, or got assigned one above, use it.
327# If not, use more.
328#
329PAGER=${PAGER:-more}
330
331if [ -n "${VERBOSE}" -a ! "${PAGER}" = "more" ]; then
332  echo " *** You have ${PAGER} defined as your pager so we will use that"
333  echo ''
334  sleep 3
335fi
336
337# Assign the diff flag once so we will not have to keep testing it
338#
339DIFF_FLAG=${DIFF_FLAG:--u}
340
341# Assign the source directory
342#
343SOURCEDIR=${SOURCEDIR:-/usr/src/etc}
344
345case "${RERUN}" in
346'')
347  # Set up the loop to test for the existence of the
348  # temp root directory.
349  #
350  TEST_TEMP_ROOT=yes
351  while [ "${TEST_TEMP_ROOT}" = "yes" ]; do
352    if [ -d "${TEMPROOT}" ]; then
353      echo "*** The directory specified for the temporary root environment,"
354      echo "    ${TEMPROOT}, exists.  This can be a security risk if untrusted"
355      echo "    users have access to the system."
356      echo ''
357      case "${AUTO_RUN}" in
358      '')
359        echo "  Use 'd' to delete the old ${TEMPROOT} and continue"
360        echo "  Use 't' to select a new temporary root directory"
361        echo "  Use 'e' to exit mergemaster"
362        echo ''
363        echo "  Default is to use ${TEMPROOT} as is"
364        echo ''
365        echo -n "How should I deal with this? [Use the existing ${TEMPROOT}] "
366        read DELORNOT
367
368        case "${DELORNOT}" in
369        [dD])
370          echo ''
371          echo "   *** Deleting the old ${TEMPROOT}"
372          echo ''
373          rm -rf "${TEMPROOT}"
374          unset TEST_TEMP_ROOT
375          ;;
376        [tT])
377          echo "   *** Enter new directory name for temporary root environment"
378          read TEMPROOT
379          ;;
380        [eE])
381          exit 0
382          ;;
383        '')
384          echo ''
385          echo "   *** Leaving ${TEMPROOT} intact"
386          echo ''
387          unset TEST_TEMP_ROOT
388          ;;
389        *)
390          echo ''
391          echo "invalid choice: ${DELORNOT}"
392          echo ''
393          ;;
394        esac
395        ;;
396      *)
397        # If this is an auto-run, try a hopefully safe alternative then re-test anyway
398        TEMPROOT=/var/tmp/temproot.`date +%m%d.%H.%M.%S`
399        ;;
400      esac
401    else
402      unset TEST_TEMP_ROOT
403    fi
404  done
405
406  echo "*** Creating the temporary root environment in ${TEMPROOT}"
407
408  if mkdir -p "${TEMPROOT}"; then
409    echo " *** ${TEMPROOT} ready for use"
410  fi
411
412  if [ ! -d "${TEMPROOT}" ]; then
413    echo ''
414    echo "  *** FATAL ERROR: Cannot create ${TEMPROOT}"
415    echo ''
416    exit 1
417  fi
418
419  echo " *** Creating and populating directory structure in ${TEMPROOT}"
420  echo ''
421
422  case "${VERBOSE}" in
423  '') ;;
424  *)
425    echo " *** Press [Enter] or [Return] key to continue"
426    read ANY_KEY
427    unset ANY_KEY
428    ;;
429  esac
430
431  { cd ${SOURCEDIR} &&
432    case "${DESTDIR}" in
433    '') ;;
434    *)
435      make DESTDIR=${DESTDIR} distrib-dirs
436      ;;
437    esac
438    make DESTDIR=${TEMPROOT} distrib-dirs &&
439    make DESTDIR=${TEMPROOT} -DNO_MAKEDEV distribution;} ||
440  { echo '';
441    echo "  *** FATAL ERROR: Cannot 'cd' to ${SOURCEDIR} and install files to the";
442    echo "      temproot environment";
443    echo '';
444    exit 1;}
445
446  # Doing the inventory and removing files that we don't want to compare only makes
447  # sense if we are not doing a rerun, since we have no way of knowing what happened
448  # to the files during previous incarnations.
449  case "${VERBOSE}" in
450  '') ;;
451  *)
452    echo ''
453    echo ' *** The following files exist only in the installed version of'
454    echo "     ${DESTDIR}/etc.  In the vast majority of cases these files"
455    echo '     are necessary parts of the system and should not be deleted.'
456    echo '     However because these files are not updated by this process you'
457    echo '     might want to verify their status before rebooting your system.'
458    echo ''
459    echo ' *** Press [Enter] or [Return] key to continue'
460    read ANY_KEY
461    unset ANY_KEY
462    diff -qr ${DESTDIR}/etc ${TEMPROOT}/etc | grep "^Only in /etc" | ${PAGER}
463    echo ''
464    echo ' *** Press [Enter] or [Return] key to continue'
465    read ANY_KEY
466    unset ANY_KEY
467    ;;
468  esac
469
470  # We really don't want to have to deal with these files, since
471  # master.passwd is the real file that should be compared, then
472  # the user should run pwd_mkdb if necessary.
473  #
474  rm ${TEMPROOT}/etc/spwd.db ${TEMPROOT}/etc/passwd ${TEMPROOT}/etc/pwd.db
475
476  # Avoid comparing the motd if the user specifies it in .mergemasterrc
477  case "${IGNORE_MOTD}" in
478  '') ;;
479  *) rm ${TEMPROOT}/etc/motd
480     ;;
481  esac
482
483  # Avoid trying to update MAKEDEV if /dev is on a devfs
484  if /sbin/sysctl vfs.devfs.generation > /dev/null 2>&1 ; then
485    rm ${TEMPROOT}/dev/MAKEDEV ${TEMPROOT}/dev/MAKEDEV.local
486  fi
487
488  ;; # End of the "RERUN" test
489esac
490
491# Get ready to start comparing files
492
493# Check umask if not specified on the command line,
494# and we are not doing an autorun
495#
496if [ -z "${NEW_UMASK}" -a -z "${AUTO_RUN}" ]; then
497  USER_UMASK=`umask`
498  case "${USER_UMASK}" in
499  0022) ;;
500  *)
501    echo ''
502    echo " *** Your umask is currently set to ${USER_UMASK}.  By default, this script"
503    echo "     installs all files with the same user, group and modes that"
504    echo "     they are created with by ${SOURCEDIR}/Makefile, compared to"
505    echo "     a umask of 022.  This umask allows world read permission when"
506    echo "     the file's default permissions have it."
507    echo "     No world permissions can sometimes cause problems.  A umask of"
508    echo "     022 will restore the default behavior, but is not mandatory."
509    echo "     /etc/master.passwd is a special case.  Its file permissions"
510    echo "     will be 600 (rw-------) if installed."
511    echo ''
512    echo -n "What umask should I use? [${USER_UMASK}] "
513    read NEW_UMASK
514
515    NEW_UMASK="${NEW_UMASK:-$USER_UMASK}"
516    ;;
517  esac
518  echo ''
519fi
520
521CONFIRMED_UMASK=${NEW_UMASK:-0022}
522
523# Warn users who still have ${DESTDIR}/etc/sysconfig
524#
525if [ -e "${DESTDIR}/etc/sysconfig" ]; then
526  echo ''
527  echo " *** There is a sysconfig file on this system in ${DESTDIR}/etc/."
528  echo ''
529  echo '     Starting with FreeBSD version 2.2.2 those settings moved from'
530  echo '     /etc/sysconfig to /etc/rc.conf.  If you are upgrading an older'
531  echo '     system make sure that you transfer your settings by hand from'
532  echo '     sysconfig to rc.conf and install the rc.conf file.  If you'
533  echo '     have already made this transition, you should consider'
534  echo '     renaming or deleting the sysconfig file.'
535  echo ''
536  case "${AUTO_RUN}" in
537  '')
538    echo -n "Continue with the merge process? [yes] "
539    read CONT_OR_NOT
540
541    case "${CONT_OR_NOT}" in
542    [nN]*)
543      exit 0
544      ;;
545    *)
546      echo "   *** Continuing"
547      echo ''
548      ;;
549    esac
550    ;;
551  *) ;;
552  esac
553fi
554
555# Use the umask/mode information to install the files
556# Create directories as needed
557#
558mm_install () {
559  local INSTALL_DIR
560  INSTALL_DIR=${1#.}
561  INSTALL_DIR=${INSTALL_DIR%/*}
562
563  case "${INSTALL_DIR}" in
564  '')
565    INSTALL_DIR=/
566    ;;
567  esac
568
569  if [ -n "${DESTDIR}${INSTALL_DIR}" -a ! -d "${DESTDIR}${INSTALL_DIR}" ]; then
570    DIR_MODE=`perl -e 'printf "%04o\n", (((stat("$ARGV[0]"))[2] & 07777) &~ oct("$ARGV[1]"))' "${TEMPROOT}/${INSTALL_DIR}" "${CONFIRMED_UMASK}"`
571    install -d -o root -g wheel -m "${DIR_MODE}" "${DESTDIR}${INSTALL_DIR}"
572  fi
573
574  FILE_MODE=`perl -e 'printf "%04o\n", (((stat("$ARGV[0]"))[2] & 07777) &~ oct("$ARGV[1]"))' "${1}" "${CONFIRMED_UMASK}"`
575
576  if [ ! -x "${1}" ]; then
577    case "${1#.}" in
578    /etc/mail/aliases)
579      NEED_NEWALIASES=yes
580      ;;
581    /etc/login.conf)
582      NEED_CAP_MKDB=yes
583      ;;
584    /etc/master.passwd)
585      install -m 600 "${1}" "${DESTDIR}${INSTALL_DIR}"
586      NEED_PWD_MKDB=yes
587      DONT_INSTALL=yes
588      ;;
589    /.cshrc | /.profile)
590      case "${LINK_EXPLAINED}" in
591      '')
592        echo "   *** Historically BSD derived systems have had a"
593        echo "       hard link from /.cshrc and /.profile to"
594        echo "       their namesakes in /root.  Please indicate"
595        echo "       your preference below for bringing your"
596        echo "       installed files up to date."
597        echo ''
598        LINK_EXPLAINED=yes
599        ;;
600      esac
601
602      echo "   Use 'd' to delete the temporary ${COMPFILE}"
603      echo "   Use 'l' to delete the existing ${DESTDIR}${COMPFILE#.} and create the link"
604      echo ''
605      echo "   Default is to leave the temporary file to deal with by hand"
606      echo ''
607      echo -n "  How should I handle ${COMPFILE}? [Leave it to install later] "
608      read HANDLE_LINK
609
610      case "${HANDLE_LINK}" in
611      [dD]*)
612        rm "${COMPFILE}"
613        echo ''
614        echo "   *** Deleting ${COMPFILE}"
615        ;;
616      [lL]*)
617        echo ''
618        rm -f "${DESTDIR}${COMPFILE#.}"
619        if ln "${DESTDIR}/root/${COMPFILE##*/}" "${DESTDIR}${COMPFILE#.}"; then
620          echo "   *** Link from ${DESTDIR}${COMPFILE#.} to ${DESTDIR}/root/${COMPFILE##*/} installed successfully"
621          rm "${COMPFILE}"
622        else
623          echo "   *** Error linking ${DESTDIR}${COMPFILE#.} to ${DESTDIR}/root/${COMPFILE##*/}, ${COMPFILE} will remain to install by hand"
624        fi
625        ;;
626      *)
627        echo "   *** ${COMPFILE} will remain for your consideration"
628        ;;
629      esac
630      DONT_INSTALL=yes
631      ;;
632    esac
633
634    case "${DONT_INSTALL}" in
635    '')
636      install -m "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}"
637      ;;
638    *)
639      unset DONT_INSTALL
640      ;;
641    esac
642  else
643    case "${1#.}" in
644    /dev/MAKEDEV)
645      NEED_MAKEDEV=yes
646      ;;
647    esac
648    install -m "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}"
649  fi
650  return $?
651}
652
653echo ''
654echo "*** Beginning comparison"
655echo ''
656
657cd "${TEMPROOT}"
658
659if [ -r "${MM_PRE_COMPARE_SCRIPT}" ]; then
660  . "${MM_PRE_COMPARE_SCRIPT}"
661fi
662
663# Using -size +0 avoids uselessly checking the empty log files created
664# by ${SOURCEDIR}/Makefile and the device entries in ./dev, but does
665# check the scripts in ./dev, as we'd like (assuming no devfs of course).
666#
667for COMPFILE in `find . -type f -size +0`; do
668
669  # First, check to see if the file exists in DESTDIR.  If not, the
670  # diff_loop function knows how to handle it.
671  #
672  if [ ! -e "${DESTDIR}${COMPFILE#.}" ]; then
673    diff_loop
674    continue
675  fi
676
677  case "${STRICT}" in
678  '' | [Nn][Oo])
679    # Compare CVS $Id's first so if the file hasn't been modified
680    # local changes will be ignored.
681    # If the files have the same $Id, delete the one in temproot so the
682    # user will have less to wade through if files are left to merge by hand.
683    #
684    # Reduce complexity and improve portability by using ident
685    #
686    CVSID1=`ident ${DESTDIR}${COMPFILE#.} 2>&1`
687    CVSID1="${CVSID1#${DESTDIR}}"
688    CVSID2=`ident ${COMPFILE} 2>&1`
689
690    case "${CVSID2}" in
691    *'no id keywords'*)
692      ;;
693    ."${CVSID1}")
694      echo " *** Temp ${COMPFILE} and installed have the same CVS Id, deleting"
695      rm "${COMPFILE}"
696      ;;
697    esac
698    ;;
699  esac
700
701  # If the file is still here either because the $Ids are different, the
702  # file doesn't have an $Id, or we're using STRICT mode; look at the diff.
703  #
704  if [ -f "${COMPFILE}" ]; then
705
706    # Do an absolute diff first to see if the files are actually different.
707    # If they're not different, delete the one in temproot.
708    #
709    if diff -q "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" > /dev/null 2>&1; then
710      echo " *** Temp ${COMPFILE} and installed are the same, deleting"
711      rm "${COMPFILE}"
712    else
713      # Ok, the files are different, so show the user where they differ.  Use user's
714      # choice of diff methods; and user's pager if they have one.  Use more if not.
715      # Use unified diffs by default.  Context diffs give me a headache. :)
716      #
717      case "${AUTO_RUN}" in
718      '')
719        # prompt user to install/delete/merge changes
720        diff_loop
721        ;;
722      *)
723        # If this is an auto run, make it official
724        echo "   *** ${COMPFILE} will remain for your consideration"
725        ;;
726      esac # Auto run test
727    fi # Yes, the files are different
728  fi # Yes, the file still remains to be checked
729done # This is for the do way up there at the beginning of the comparison
730
731echo ''
732echo "*** Comparison complete"
733echo ''
734
735TEST_FOR_FILES=`find ${TEMPROOT} -type f -size +0 2>/dev/null`
736if [ -n "${TEST_FOR_FILES}" ]; then
737  echo "*** Files that remain for you to merge by hand:"
738  find "${TEMPROOT}" -type f -size +0
739fi
740
741case "${AUTO_RUN}" in
742'')
743  echo ''
744  echo -n "Do you wish to delete what is left of ${TEMPROOT}? [no] "
745  read DEL_TEMPROOT
746
747  case "${DEL_TEMPROOT}" in
748  [yY]*)
749    if rm -rf "${TEMPROOT}"; then
750      echo " *** ${TEMPROOT} has been deleted"
751    else
752      echo " *** Unable to delete ${TEMPROOT}"
753    fi
754    ;;
755  *)
756    echo " *** ${TEMPROOT} will remain"
757    ;;
758  esac
759  ;;
760*) ;;
761esac
762
763case "${AUTO_INSTALLED_FILES}" in
764'') ;;
765*)
766  (
767    echo ''
768    echo '*** You chose the automatic install option for files that did not exist'
769    echo '    on your system.  The following files were installed for you:'
770    echo "${AUTO_INSTALLED_FILES}"
771  ) | ${PAGER}
772  ;;
773esac
774
775case "${NEED_MAKEDEV}" in
776'') ;;
777*)
778  echo ''
779  echo "*** You installed a new /dev/MAKEDEV script, so make sure that you run"
780  echo "    'cd /dev && /bin/sh MAKEDEV all' to rebuild your devices"
781  ;;
782esac
783
784case "${NEED_NEWALIASES}" in
785'') ;;
786*)
787  echo ''
788  echo "*** You installed a new aliases file, so make sure that you run"
789  echo "    'newaliases' to rebuild your aliases database"
790  ;;
791esac
792
793case "${NEED_CAP_MKDB}" in
794'') ;;
795*)
796  echo ''
797  echo "*** You installed a login.conf file, so make sure that you run"
798  echo "    'cap_mkdb /etc/login.conf' to rebuild your login.conf database"
799  ;;
800esac
801
802case "${NEED_PWD_MKDB}" in
803'') ;;
804*)
805  echo ''
806  echo "*** You installed a new master.passwd file, so make sure that you run"
807  echo "    'pwd_mkdb -p /etc/master.passwd' to rebuild your password files"
808  ;;
809esac
810
811echo ''
812
813if [ -r "${MM_EXIT_SCRIPT}" ]; then
814  . "${MM_EXIT_SCRIPT}"
815fi
816
817exit 0
818
819