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