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