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 (c) 1998-2012 Douglas Barton, All rights reserved
9# Please see detailed copyright below
10
11# $FreeBSD$
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 [-scrvhpCP] [-a|[-iFU]] [--run-updates=always|never]'
19  echo '    [-m /path] [-t /path] [-d] [-u N] [-w N] [-A arch] [-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 '  -p  Pre-buildworld mode, only compares crucial files'
29  echo '  -F  Install files that differ only by revision control Id ($FreeBSD)'
30  echo '  -C  Compare local rc.conf variables to the defaults'
31  echo '  -P  Preserve files that are overwritten'
32  echo "  -U  Attempt to auto upgrade files that have not been user modified"
33  echo '      ***DANGEROUS***'
34  echo '  --run-updates=  Specify always or never to run newalises, pwd_mkdb, etc.'
35  echo ''
36  echo "  -m /path/directory  Specify location of source to do the make in"
37  echo "  -t /path/directory  Specify temp root directory"
38  echo "  -d  Add date and time to directory name (e.g., /var/tmp/temproot.`date +%m%d.%H.%M`)"
39  echo "  -u N  Specify a numeric umask"
40  echo "  -w N  Specify a screen width in columns to sdiff"
41  echo "  -A architecture  Alternative architecture name to pass to make"
42  echo '  -D /path/directory  Specify the destination directory to install files to'
43  echo ''
44}
45
46display_help () {
47  echo "* To specify a directory other than /var/tmp/temproot for the"
48  echo "  temporary root environment, use -t /path/to/temp/root"
49  echo "* The -w option takes a number as an argument for the column width"
50  echo "  of the screen.  The default is 80."
51  echo '* The -a option causes mergemaster to run without prompting.'
52}
53
54# Loop allowing the user to use sdiff to merge files and display the merged
55# file.
56merge_loop () {
57  case "${VERBOSE}" in
58  '') ;;
59  *)
60      echo "   *** Type h at the sdiff prompt (%) to get usage help"
61      ;;
62  esac
63  echo ''
64  MERGE_AGAIN=yes
65  while [ "${MERGE_AGAIN}" = "yes" ]; do
66    # Prime file.merged so we don't blat the owner/group id's
67    cp -p "${COMPFILE}" "${COMPFILE}.merged"
68    sdiff -o "${COMPFILE}.merged" --text --suppress-common-lines \
69      --width=${SCREEN_WIDTH:-80} "${DESTDIR}${COMPFILE#.}" "${COMPFILE}"
70    INSTALL_MERGED=V
71    while [ "${INSTALL_MERGED}" = "v" -o "${INSTALL_MERGED}" = "V" ]; do
72      echo ''
73      echo "  Use 'i' to install merged file"
74      echo "  Use 'r' to re-do the merge"
75      echo "  Use 'v' to view the merged file"
76      echo "  Default is to leave the temporary file to deal with by hand"
77      echo ''
78      echo -n "    *** How should I deal with the merged file? [Leave it for later] "
79      read INSTALL_MERGED
80
81      case "${INSTALL_MERGED}" in
82      [iI])
83        mv "${COMPFILE}.merged" "${COMPFILE}"
84        echo ''
85        if mm_install "${COMPFILE}"; then
86          echo "     *** Merged version of ${COMPFILE} installed successfully"
87        else
88          echo "     *** Problem installing ${COMPFILE}, it will remain to merge by hand later"
89        fi
90        unset MERGE_AGAIN
91        ;;
92      [rR])
93        rm "${COMPFILE}.merged"
94        ;;
95      [vV])
96        ${PAGER} "${COMPFILE}.merged"
97        ;;
98      '')
99        echo "   *** ${COMPFILE} will remain for your consideration"
100        unset MERGE_AGAIN
101        ;;
102      *)
103        echo "invalid choice: ${INSTALL_MERGED}"
104        INSTALL_MERGED=V
105        ;;
106      esac
107    done
108  done
109}
110
111# Loop showing user differences between files, allow merge, skip or install
112# options
113diff_loop () {
114
115  HANDLE_COMPFILE=v
116
117  while [ "${HANDLE_COMPFILE}" = "v" -o "${HANDLE_COMPFILE}" = "V" -o \
118    "${HANDLE_COMPFILE}" = "NOT V" ]; do
119    if [ -f "${DESTDIR}${COMPFILE#.}" -a -f "${COMPFILE}" ]; then
120      if [ -n "${AUTO_UPGRADE}" -a -n "${CHANGED}" ]; then
121        case "${CHANGED}" in
122        *:${DESTDIR}${COMPFILE#.}:*) ;;		# File has been modified
123        *)
124          echo ''
125          echo "  *** ${COMPFILE} has not been user modified."
126          echo ''
127
128          if mm_install "${COMPFILE}"; then
129            echo "   *** ${COMPFILE} upgraded successfully"
130            echo ''
131            # Make the list print one file per line
132            AUTO_UPGRADED_FILES="${AUTO_UPGRADED_FILES}      ${DESTDIR}${COMPFILE#.}
133"
134          else
135            echo "   *** Problem upgrading ${COMPFILE}, it will remain to merge by hand"
136          fi
137          return
138          ;;
139        esac
140      fi
141      if [ "${HANDLE_COMPFILE}" = "v" -o "${HANDLE_COMPFILE}" = "V" ]; then
142	echo ''
143	echo '   ======================================================================   '
144	echo ''
145        (
146          echo "  *** Displaying differences between ${COMPFILE} and installed version:"
147          echo ''
148          diff ${DIFF_FLAG} ${DIFF_OPTIONS} "${DESTDIR}${COMPFILE#.}" "${COMPFILE}"
149        ) | ${PAGER}
150        echo ''
151      fi
152    else
153      echo ''
154      echo "  *** There is no installed version of ${COMPFILE}"
155      echo ''
156      case "${AUTO_INSTALL}" in
157      [Yy][Ee][Ss])
158        echo ''
159        if mm_install "${COMPFILE}"; then
160          echo "   *** ${COMPFILE} installed successfully"
161          echo ''
162          # Make the list print one file per line
163          AUTO_INSTALLED_FILES="${AUTO_INSTALLED_FILES}      ${DESTDIR}${COMPFILE#.}
164"
165        else
166          echo "   *** Problem installing ${COMPFILE}, it will remain to merge by hand"
167        fi
168        return
169        ;;
170      *)
171        NO_INSTALLED=yes
172        ;;
173      esac
174    fi
175
176    echo "  Use 'd' to delete the temporary ${COMPFILE}"
177    echo "  Use 'i' to install the temporary ${COMPFILE}"
178    case "${NO_INSTALLED}" in
179    '')
180      echo "  Use 'm' to merge the temporary and installed versions"
181      echo "  Use 'v' to view the diff results again"
182      ;;
183    esac
184    echo ''
185    echo "  Default is to leave the temporary file to deal with by hand"
186    echo ''
187    echo -n "How should I deal with this? [Leave it for later] "
188    read HANDLE_COMPFILE
189
190    case "${HANDLE_COMPFILE}" in
191    [dD])
192      rm "${COMPFILE}"
193      echo ''
194      echo "   *** Deleting ${COMPFILE}"
195      ;;
196    [iI])
197      echo ''
198      if mm_install "${COMPFILE}"; then
199        echo "   *** ${COMPFILE} installed successfully"
200      else
201        echo "   *** Problem installing ${COMPFILE}, it will remain to merge by hand"
202      fi
203      ;;
204    [mM])
205      case "${NO_INSTALLED}" in
206      '')
207        # interact with user to merge files
208        merge_loop
209        ;;
210      *)
211        echo ''
212        echo "   *** There is no installed version of ${COMPFILE}"
213        echo ''
214        HANDLE_COMPFILE="NOT V"
215        ;;
216      esac # End of "No installed version of file but user selected merge" test
217      ;;
218    [vV])
219      continue
220      ;;
221    '')
222      echo ''
223      echo "   *** ${COMPFILE} will remain for your consideration"
224      ;;
225    *)
226      # invalid choice, show menu again.
227      echo "invalid choice: ${HANDLE_COMPFILE}"
228      echo ''
229      HANDLE_COMPFILE="NOT V"
230      continue
231      ;;
232    esac  # End of "How to handle files that are different"
233  done
234  unset NO_INSTALLED
235  echo ''
236  case "${VERBOSE}" in
237  '') ;;
238  *)
239    sleep 3
240    ;;
241  esac
242}
243
244press_to_continue () {
245  local DISCARD
246  echo -n ' *** Press the [Enter] or [Return] key to continue '
247  read DISCARD
248}
249
250# Set the default path for the temporary root environment
251#
252TEMPROOT='/var/tmp/temproot'
253
254# Read /etc/mergemaster.rc first so the one in $HOME can override
255#
256if [ -r /etc/mergemaster.rc ]; then
257  . /etc/mergemaster.rc
258fi
259
260# Read .mergemasterrc before command line so CLI can override
261#
262if [ -r "$HOME/.mergemasterrc" ]; then
263  . "$HOME/.mergemasterrc"
264fi
265
266for var in "$@" ; do
267  case "$var" in
268  --run-updates*)
269    RUN_UPDATES=`echo ${var#--run-updates=} | tr [:upper:] [:lower:]`
270    ;;
271  *)
272    newopts="$newopts $var"
273    ;;
274  esac
275done
276
277set -- $newopts
278unset var newopts
279
280# Check the command line options
281#
282while getopts ":ascrvhipCPm:t:du:w:D:A:FU" COMMAND_LINE_ARGUMENT ; do
283  case "${COMMAND_LINE_ARGUMENT}" in
284  A)
285    ARCHSTRING='TARGET_ARCH='${OPTARG}
286    ;;
287  F)
288    FREEBSD_ID=yes
289    ;;
290  U)
291    AUTO_UPGRADE=yes
292    ;;
293  s)
294    STRICT=yes
295    unset DIFF_OPTIONS
296    ;;
297  c)
298    DIFF_FLAG='-c'
299    ;;
300  r)
301    RERUN=yes
302    ;;
303  v)
304    case "${AUTO_RUN}" in
305    '') VERBOSE=yes ;;
306    esac
307    ;;
308  a)
309    AUTO_RUN=yes
310    unset VERBOSE
311    ;;
312  h)
313    display_usage
314    display_help
315    exit 0
316    ;;
317  i)
318    AUTO_INSTALL=yes
319    ;;
320  C)
321    COMP_CONFS=yes
322    ;;
323  P)
324    PRESERVE_FILES=yes
325    ;;
326  p)
327    PRE_WORLD=yes
328    unset COMP_CONFS
329    unset AUTO_RUN
330    ;;
331  m)
332    SOURCEDIR=${OPTARG}
333    ;;
334  t)
335    TEMPROOT=${OPTARG}
336    ;;
337  d)
338    TEMPROOT=${TEMPROOT}.`date +%m%d.%H.%M`
339    ;;
340  u)
341    NEW_UMASK=${OPTARG}
342    ;;
343  w)
344    SCREEN_WIDTH=${OPTARG}
345    ;;
346  D)
347    DESTDIR=${OPTARG}
348    ;;
349  *)
350    display_usage
351    exit 1
352    ;;
353  esac
354done
355
356if [ -n "$AUTO_RUN" ]; then
357  if [ -n "$FREEBSD_ID" -o -n "$AUTO_UPGRADE" -o -n "$AUTO_INSTALL" ]; then
358    echo ''
359    echo "*** You have included the -a option along with one or more options"
360    echo '    that indicate that you wish mergemaster to actually make updates'
361    echo '    (-F, -U, or -i), however these options are not compatible.'
362    echo '    Please read mergemaster(8) for more information.'
363    echo ''
364    exit 1
365  fi
366fi
367
368# Assign the location of the mtree database
369#
370MTREEDB=${MTREEDB:-${DESTDIR}/var/db}
371MTREEFILE="${MTREEDB}/mergemaster.mtree"
372
373# Don't force the user to set this in the mergemaster rc file
374if [ -n "${PRESERVE_FILES}" -a -z "${PRESERVE_FILES_DIR}" ]; then
375  PRESERVE_FILES_DIR=/var/tmp/mergemaster/preserved-files-`date +%y%m%d-%H%M%S`
376  mkdir -p ${PRESERVE_FILES_DIR}
377fi
378
379# Check for the mtree database in DESTDIR
380case "${AUTO_UPGRADE}" in
381'') ;;	# If the option is not set no need to run the test or warn the user
382*)
383  if [ ! -s "${MTREEFILE}" ]; then
384    echo ''
385    echo "*** Unable to find mtree database (${MTREEFILE})."
386    echo "    Skipping auto-upgrade on this run."
387    echo "    It will be created for the next run when this one is complete."
388    echo ''
389    case "${AUTO_RUN}" in
390    '')
391      press_to_continue
392      ;;
393    esac
394    unset AUTO_UPGRADE
395  fi
396  ;;
397esac
398
399if [ -e "${DESTDIR}/etc/fstab" ]; then
400  if grep -q nodev ${DESTDIR}/etc/fstab; then
401    echo ''
402    echo "*** You have the deprecated 'nodev' option in ${DESTDIR}/etc/fstab."
403    echo "    This can prevent the filesystem from being mounted on reboot."
404    echo "    Please update your fstab before continuing."
405    echo "    See fstab(5) for more information."
406    echo ''
407    exit 1
408  fi
409fi
410
411echo ''
412
413# If the user has a pager defined, make sure we can run it
414#
415case "${DONT_CHECK_PAGER}" in
416'')
417check_pager () {
418  while ! type "${PAGER%% *}" >/dev/null; do
419    echo " *** Your PAGER environment variable specifies '${PAGER}', but"
420    echo "     due to the limited PATH that I use for security reasons,"
421    echo "     I cannot execute it.  So, what would you like to do?"
422    echo ''
423    echo "  Use 'e' to exit mergemaster and fix your PAGER variable"
424    echo "  Use 'l' to set PAGER to 'less' for this run"
425    echo "  Use 'm' to use plain old 'more' as your PAGER for this run"
426    echo ''
427    echo "  or you may type an absolute path to PAGER for this run"
428    echo ''
429    echo "  Default is to use 'less' "
430    echo ''
431    echo -n "What should I do? [Use 'less'] "
432    read FIXPAGER
433
434    case "${FIXPAGER}" in
435    [eE])
436       exit 0
437       ;;
438    [lL]|'')
439       PAGER=less
440       ;;
441    [mM])
442       PAGER=more
443       ;;
444    /*)
445       PAGER="$FIXPAGER"
446       ;;
447    *)
448       echo ''
449       echo "invalid choice: ${FIXPAGER}"
450    esac
451    echo ''
452  done
453}
454  if [ -n "${PAGER}" ]; then
455    check_pager
456  fi
457  ;;
458esac
459
460# If user has a pager defined, or got assigned one above, use it.
461# If not, use less.
462#
463PAGER=${PAGER:-less}
464
465if [ -n "${VERBOSE}" -a ! "${PAGER}" = "less" ]; then
466  echo " *** You have ${PAGER} defined as your pager so we will use that"
467  echo ''
468  sleep 3
469fi
470
471# Assign the diff flag once so we will not have to keep testing it
472#
473DIFF_FLAG=${DIFF_FLAG:--u}
474
475# Assign the source directory
476#
477SOURCEDIR=${SOURCEDIR:-/usr/src}
478if [ ! -f ${SOURCEDIR}/Makefile.inc1 -a \
479   -f ${SOURCEDIR}/../Makefile.inc1 ]; then
480  echo " *** The source directory you specified (${SOURCEDIR})"
481  echo "     will be reset to ${SOURCEDIR}/.."
482  echo ''
483  sleep 3
484  SOURCEDIR=${SOURCEDIR}/..
485fi
486if [ ! -f ${SOURCEDIR}/Makefile.inc1 ]; then
487    echo     "*** ${SOURCEDIR} was not found."
488    if [ -f ./Makefile.inc1 ]; then
489	echo "    Found Makefile.inc1 in the current directory."
490	echo -n "    Would you like to set SOURCEDIR to $(pwd)? [no and exit] "
491	read SRCDOT
492	case "${SRCDOT}" in
493	    [yY]*)
494		echo "    *** Setting SOURCEDIR to $(pwd)"
495		SOURCEDIR=$(pwd)
496		;;
497	    *)
498		echo "    **** No suitable ${SOURCEDIR} found, exiting"
499		exit 1
500		;;
501	esac
502    else
503	echo "    **** No suitable ${SOURCEDIR} found, exiting"
504	exit 1
505    fi
506fi
507SOURCEDIR=$(realpath "$SOURCEDIR")
508
509# Setup make to use system files from SOURCEDIR
510MM_MAKE="make ${ARCHSTRING} -m ${SOURCEDIR}/share/mk -DNO_FILEMON"
511
512# Check DESTDIR against the mergemaster mtree database to see what
513# files the user changed from the reference files.
514#
515if [ -n "${AUTO_UPGRADE}" -a -s "${MTREEFILE}" ]; then
516	# Force FreeBSD 9 compatible output when available.
517	if mtree -F freebsd9 -c -p /var/empty/ > /dev/null 2>&1; then
518		MTREE_FLAVOR="-F freebsd9"
519	else
520		MTREE_FLAVOR=
521	fi
522	CHANGED=:
523	for file in `mtree -eqL ${MTREE_FLAVOR} -f ${MTREEFILE} -p ${DESTDIR}/ \
524		2>/dev/null | awk '($2 == "changed") {print $1}'`; do
525		if [ -f "${DESTDIR}/$file" ]; then
526			CHANGED="${CHANGED}${DESTDIR}/${file}:"
527		fi
528	done
529	[ "$CHANGED" = ':' ] && unset CHANGED
530fi
531
532# Check the width of the user's terminal
533#
534if [ -t 0 ]; then
535  w=`tput columns`
536  case "${w}" in
537  0|'') ;; # No-op, since the input is not valid
538  *)
539    case "${SCREEN_WIDTH}" in
540    '') SCREEN_WIDTH="${w}" ;;
541    "${w}") ;; # No-op, since they are the same
542    *)
543      echo -n "*** You entered ${SCREEN_WIDTH} as your screen width, but stty "
544      echo "thinks it is ${w}."
545      echo ''
546      echo -n "What would you like to use? [${w}] "
547      read SCREEN_WIDTH
548      case "${SCREEN_WIDTH}" in
549      '') SCREEN_WIDTH="${w}" ;;
550      esac
551      ;;
552    esac
553  esac
554fi
555
556# Define what $Id tag to look for to aid portability.
557#
558ID_TAG=FreeBSD
559
560delete_temproot () {
561  rm -rf "${TEMPROOT}" 2>/dev/null
562  chflags -R 0 "${TEMPROOT}" 2>/dev/null
563  rm -rf "${TEMPROOT}" || { echo "*** Unable to delete ${TEMPROOT}";  exit 1; }
564}
565
566case "${RERUN}" in
567'')
568  # Set up the loop to test for the existence of the
569  # temp root directory.
570  #
571  TEST_TEMP_ROOT=yes
572  while [ "${TEST_TEMP_ROOT}" = "yes" ]; do
573    if [ -d "${TEMPROOT}" ]; then
574      echo "*** The directory specified for the temporary root environment,"
575      echo "    ${TEMPROOT}, exists.  This can be a security risk if untrusted"
576      echo "    users have access to the system."
577      echo ''
578      case "${AUTO_RUN}" in
579      '')
580        echo "  Use 'd' to delete the old ${TEMPROOT} and continue"
581        echo "  Use 't' to select a new temporary root directory"
582        echo "  Use 'e' to exit mergemaster"
583        echo ''
584        echo "  Default is to use ${TEMPROOT} as is"
585        echo ''
586        echo -n "How should I deal with this? [Use the existing ${TEMPROOT}] "
587        read DELORNOT
588
589        case "${DELORNOT}" in
590        [dD])
591          echo ''
592          echo "   *** Deleting the old ${TEMPROOT}"
593          echo ''
594          delete_temproot
595          unset TEST_TEMP_ROOT
596          ;;
597        [tT])
598          echo "   *** Enter new directory name for temporary root environment"
599          read TEMPROOT
600          ;;
601        [eE])
602          exit 0
603          ;;
604        '')
605          echo ''
606          echo "   *** Leaving ${TEMPROOT} intact"
607          echo ''
608          unset TEST_TEMP_ROOT
609          ;;
610        *)
611          echo ''
612          echo "invalid choice: ${DELORNOT}"
613          echo ''
614          ;;
615        esac
616        ;;
617      *)
618        # If this is an auto-run, try a hopefully safe alternative then
619        # re-test anyway.
620        TEMPROOT=/var/tmp/temproot.`date +%m%d.%H.%M.%S`
621        ;;
622      esac
623    else
624      unset TEST_TEMP_ROOT
625    fi
626  done
627
628  echo "*** Creating the temporary root environment in ${TEMPROOT}"
629
630  if mkdir -p "${TEMPROOT}"; then
631    echo " *** ${TEMPROOT} ready for use"
632  fi
633
634  if [ ! -d "${TEMPROOT}" ]; then
635    echo ''
636    echo "  *** FATAL ERROR: Cannot create ${TEMPROOT}"
637    echo ''
638    exit 1
639  fi
640
641  echo " *** Creating and populating directory structure in ${TEMPROOT}"
642  echo ''
643
644  case "${VERBOSE}" in
645  '') ;;
646  *)
647    press_to_continue
648    ;;
649  esac
650
651  case "${PRE_WORLD}" in
652  '')
653    { cd ${SOURCEDIR} &&
654      case "${DESTDIR}" in
655      '') ;;
656      *)
657        ${MM_MAKE} DESTDIR=${DESTDIR} distrib-dirs >/dev/null
658        ;;
659      esac
660      ${MM_MAKE} DESTDIR=${TEMPROOT} distrib-dirs >/dev/null &&
661      ${MM_MAKE} _obj SUBDIR_OVERRIDE=etc >/dev/null &&
662      ${MM_MAKE} everything SUBDIR_OVERRIDE=etc >/dev/null &&
663      ${MM_MAKE} DESTDIR=${TEMPROOT} distribution >/dev/null;} ||
664    { echo '';
665     echo "  *** FATAL ERROR: Cannot 'cd' to ${SOURCEDIR} and install files to";
666      echo "      the temproot environment";
667      echo '';
668      exit 1;}
669    ;;
670  *)
671    # Only set up files that are crucial to {build|install}world
672    { mkdir -p ${TEMPROOT}/etc &&
673      cp -p ${SOURCEDIR}/etc/master.passwd ${TEMPROOT}/etc &&
674      install -p -o root -g wheel -m 0644 ${SOURCEDIR}/etc/group ${TEMPROOT}/etc;} ||
675    { echo '';
676      echo '  *** FATAL ERROR: Cannot copy files to the temproot environment';
677      echo '';
678      exit 1;}
679    ;;
680  esac
681
682  # Doing the inventory and removing files that we don't want to compare only
683  # makes sense if we are not doing a rerun, since we have no way of knowing
684  # what happened to the files during previous incarnations.
685  case "${VERBOSE}" in
686  '') ;;
687  *)
688    echo ''
689    echo ' *** The following files exist only in the installed version of'
690    echo "     ${DESTDIR}/etc.  In the vast majority of cases these files"
691    echo '     are necessary parts of the system and should not be deleted.'
692    echo '     However because these files are not updated by this process you'
693    echo '     might want to verify their status before rebooting your system.'
694    echo ''
695    press_to_continue
696    diff -qr ${DESTDIR}/etc ${TEMPROOT}/etc | grep "^Only in ${DESTDIR}/etc" | ${PAGER}
697    echo ''
698    press_to_continue
699    ;;
700  esac
701
702  case "${IGNORE_MOTD}" in
703  '') ;;
704  *)
705     echo ''
706     echo "*** You have the IGNORE_MOTD option set in your mergemaster rc file."
707     echo "    This option is deprecated in favor of the IGNORE_FILES option."
708     echo "    Please update your rc file accordingly."
709     echo ''
710     exit 1
711     ;;
712  esac
713
714  # Avoid comparing the following user specified files
715  for file in ${IGNORE_FILES}; do
716    test -e ${TEMPROOT}/${file} && unlink ${TEMPROOT}/${file}
717  done
718
719  # We really don't want to have to deal with files like login.conf.db, pwd.db,
720  # or spwd.db.  Instead, we want to compare the text versions, and run *_mkdb.
721  # Prompt the user to do so below, as needed.
722  #
723  rm -f ${TEMPROOT}/etc/*.db ${TEMPROOT}/etc/passwd \
724      ${TEMPROOT}/var/db/services.db
725
726  # We only need to compare things like freebsd.cf once
727  find ${TEMPROOT}/usr/obj -type f -delete 2>/dev/null
728
729  # Delete stuff we do not need to keep the mtree database small,
730  # and to make the actual comparison faster.
731  find ${TEMPROOT}/usr -type l -delete 2>/dev/null
732  find ${TEMPROOT} -type f -size 0 -delete 2>/dev/null
733  find -d ${TEMPROOT} -type d -empty -mindepth 1 -delete 2>/dev/null
734
735  # Build the mtree database in a temporary location.
736  case "${PRE_WORLD}" in
737  '') MTREENEW=`mktemp -t mergemaster.mtree`
738      mtree -nci -p ${TEMPROOT} -k size,md5digest > ${MTREENEW} 2>/dev/null
739      ;;
740  *) # We don't want to mess with the mtree database on a pre-world run or
741     # when re-scanning a previously-built tree.
742     ;;
743  esac
744  ;; # End of the "RERUN" test
745esac
746
747# Get ready to start comparing files
748
749# Check umask if not specified on the command line,
750# and we are not doing an autorun
751#
752if [ -z "${NEW_UMASK}" -a -z "${AUTO_RUN}" ]; then
753  USER_UMASK=`umask`
754  case "${USER_UMASK}" in
755  0022|022) ;;
756  *)
757    echo ''
758    echo " *** Your umask is currently set to ${USER_UMASK}.  By default, this script"
759    echo "     installs all files with the same user, group and modes that"
760    echo "     they are created with by ${SOURCEDIR}/etc/Makefile, compared to"
761    echo "     a umask of 022.  This umask allows world read permission when"
762    echo "     the file's default permissions have it."
763    echo ''
764    echo "     No world permissions can sometimes cause problems.  A umask of"
765    echo "     022 will restore the default behavior, but is not mandatory."
766    echo "     /etc/master.passwd is a special case.  Its file permissions"
767    echo "     will be 600 (rw-------) if installed."
768    echo ''
769    echo -n "What umask should I use? [${USER_UMASK}] "
770    read NEW_UMASK
771
772    NEW_UMASK="${NEW_UMASK:-$USER_UMASK}"
773    ;;
774  esac
775  echo ''
776fi
777
778CONFIRMED_UMASK=${NEW_UMASK:-0022}
779
780#
781# Warn users who still have old rc files
782#
783for file in atm devfs diskless1 diskless2 network network6 pccard \
784  serial syscons sysctl alpha amd64 i386 sparc64; do
785  if [ -f "${DESTDIR}/etc/rc.${file}" ]; then
786    OLD_RC_PRESENT=1
787    break
788  fi
789done
790
791case "${OLD_RC_PRESENT}" in
7921)
793  echo ''
794  echo " *** There are elements of the old rc system in ${DESTDIR}/etc/."
795  echo ''
796  echo '     While these scripts will not hurt anything, they are not'
797  echo '     functional on an up to date system, and can be removed.'
798  echo ''
799
800  case "${AUTO_RUN}" in
801  '')
802    echo -n 'Move these files to /var/tmp/mergemaster/old_rc? [yes] '
803    read MOVE_OLD_RC
804
805    case "${MOVE_OLD_RC}" in
806    [nN]*) ;;
807    *)
808      mkdir -p /var/tmp/mergemaster/old_rc
809        for file in atm devfs diskless1 diskless2 network network6 pccard \
810          serial syscons sysctl alpha amd64 i386 sparc64; do
811          if [ -f "${DESTDIR}/etc/rc.${file}" ]; then
812            mv ${DESTDIR}/etc/rc.${file} /var/tmp/mergemaster/old_rc/
813          fi
814        done
815      echo '  The files have been moved'
816      press_to_continue
817      ;;
818    esac
819    ;;
820  *) ;;
821  esac
822esac
823
824# Use the umask/mode information to install the files
825# Create directories as needed
826#
827install_error () {
828  echo "*** FATAL ERROR: Unable to install ${1} to ${2}"
829  echo ''
830  exit 1
831}
832
833do_install_and_rm () {
834  case "${PRESERVE_FILES}" in
835  [Yy][Ee][Ss])
836    if [ -f "${3}/${2##*/}" ]; then
837      mkdir -p ${PRESERVE_FILES_DIR}/${2%/*}
838      cp ${3}/${2##*/} ${PRESERVE_FILES_DIR}/${2%/*}
839    fi
840    ;;
841  esac
842
843  if [ ! -d "${3}/${2##*/}" ]; then
844    if install -m ${1} ${2} ${3}; then
845      unlink ${2}
846    else
847      install_error ${2} ${3}
848    fi
849  else
850    install_error ${2} ${3}
851  fi
852}
853
854# 4095 = "obase=10;ibase=8;07777" | bc
855find_mode () {
856  local OCTAL
857  OCTAL=$(( ~$(echo "obase=10; ibase=8; ${CONFIRMED_UMASK}" | bc) & 4095 &
858    $(echo "obase=10; ibase=8; $(stat -f "%OMp%OLp" ${1})" | bc) ))
859  printf "%04o\n" ${OCTAL}
860}
861
862mm_install () {
863  local INSTALL_DIR
864  INSTALL_DIR=${1#.}
865  INSTALL_DIR=${INSTALL_DIR%/*}
866
867  case "${INSTALL_DIR}" in
868  '')
869    INSTALL_DIR=/
870    ;;
871  esac
872
873  if [ -n "${DESTDIR}${INSTALL_DIR}" -a ! -d "${DESTDIR}${INSTALL_DIR}" ]; then
874    DIR_MODE=`find_mode "${TEMPROOT}/${INSTALL_DIR}"`
875    install -d -o root -g wheel -m "${DIR_MODE}" "${DESTDIR}${INSTALL_DIR}" ||
876      install_error $1 ${DESTDIR}${INSTALL_DIR}
877  fi
878
879  FILE_MODE=`find_mode "${1}"`
880
881  if [ ! -x "${1}" ]; then
882    case "${1#.}" in
883    /etc/mail/aliases)
884      NEED_NEWALIASES=yes
885      ;;
886    /etc/login.conf)
887      NEED_CAP_MKDB=yes
888      ;;
889    /etc/services)
890      NEED_SERVICES_MKDB=yes
891      ;;
892    /etc/master.passwd)
893      do_install_and_rm 600 "${1}" "${DESTDIR}${INSTALL_DIR}"
894      NEED_PWD_MKDB=yes
895      DONT_INSTALL=yes
896      ;;
897    /.cshrc | /.profile)
898      local st_nlink
899
900      # install will unlink the file before it installs the new one,
901      # so we have to restore/create the link afterwards.
902      #
903      st_nlink=0		# In case the file does not yet exist
904      eval $(stat -s ${DESTDIR}${COMPFILE#.} 2>/dev/null)
905
906      do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}"
907
908      if [ -n "${AUTO_INSTALL}" -a $st_nlink -gt 1 ]; then
909        HANDLE_LINK=l
910      else
911        case "${LINK_EXPLAINED}" in
912        '')
913          echo "   *** Historically BSD derived systems have had a"
914          echo "       hard link from /.cshrc and /.profile to"
915          echo "       their namesakes in /root.  Please indicate"
916          echo "       your preference below for bringing your"
917          echo "       installed files up to date."
918          echo ''
919          LINK_EXPLAINED=yes
920          ;;
921        esac
922
923        echo "   Use 'd' to delete the temporary ${COMPFILE}"
924        echo "   Use 'l' to delete the existing ${DESTDIR}/root/${COMPFILE##*/} and create the link"
925        echo ''
926        echo "   Default is to leave the temporary file to deal with by hand"
927        echo ''
928        echo -n "  How should I handle ${COMPFILE}? [Leave it to install later] "
929        read HANDLE_LINK
930      fi
931
932      case "${HANDLE_LINK}" in
933      [dD]*)
934        rm "${COMPFILE}"
935        echo ''
936        echo "   *** Deleting ${COMPFILE}"
937        ;;
938      [lL]*)
939        echo ''
940        unlink ${DESTDIR}/root/${COMPFILE##*/}
941        if ln ${DESTDIR}${COMPFILE#.} ${DESTDIR}/root/${COMPFILE##*/}; then
942          echo "   *** Link from ${DESTDIR}${COMPFILE#.} to ${DESTDIR}/root/${COMPFILE##*/} installed successfully"
943        else
944          echo "   *** Error linking ${DESTDIR}${COMPFILE#.} to ${DESTDIR}/root/${COMPFILE##*/}"
945          echo "   *** ${COMPFILE} will remain for your consideration"
946        fi
947        ;;
948      *)
949        echo "   *** ${COMPFILE} will remain for your consideration"
950        ;;
951      esac
952      return
953      ;;
954    esac
955
956    case "${DONT_INSTALL}" in
957    '')
958      do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}"
959      ;;
960    *)
961      unset DONT_INSTALL
962      ;;
963    esac
964  else	# File matched -x
965    do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}"
966  fi
967  return $?
968}
969
970if [ ! -d "${TEMPROOT}" ]; then
971	echo "*** FATAL ERROR: The temproot directory (${TEMPROOT})"
972	echo '                 has disappeared!'
973	echo ''
974	exit 1
975fi
976
977echo ''
978echo "*** Beginning comparison"
979echo ''
980
981# Pre-world does not populate /etc/rc.d.
982# It is very possible that a previous run would have deleted files in
983# ${TEMPROOT}/etc/rc.d, thus creating a lot of false positives.
984if [ -z "${PRE_WORLD}" -a -z "${RERUN}" ]; then
985  echo "   *** Checking ${DESTDIR}/etc/rc.d for stale files"
986  echo ''
987  cd "${DESTDIR}/etc/rc.d" &&
988  for file in *; do
989    if [ ! -e "${TEMPROOT}/etc/rc.d/${file}" ]; then
990      STALE_RC_FILES="${STALE_RC_FILES} ${file}"
991    fi
992  done
993  case "${STALE_RC_FILES}" in
994  ''|' *')
995    echo '   *** No stale files found'
996    ;;
997  *)
998    echo "   *** The following files exist in ${DESTDIR}/etc/rc.d but not in"
999    echo "       ${TEMPROOT}/etc/rc.d/:"
1000    echo ''
1001    echo "${STALE_RC_FILES}"
1002    echo ''
1003    echo '       The presence of stale files in this directory can cause the'
1004    echo '       dreaded unpredictable results, and therefore it is highly'
1005    echo '       recommended that you delete them.'
1006    case "${AUTO_RUN}" in
1007    '')
1008      echo ''
1009      echo -n '   *** Delete them now? [n] '
1010      read DELETE_STALE_RC_FILES
1011      case "${DELETE_STALE_RC_FILES}" in
1012      [yY])
1013        echo '      *** Deleting ... '
1014        rm ${STALE_RC_FILES}
1015        echo '                       done.'
1016        ;;
1017      *)
1018        echo '      *** Files will not be deleted'
1019        ;;
1020      esac
1021      sleep 2
1022      ;;
1023    *)
1024      if [ -n "${DELETE_STALE_RC_FILES}" ]; then
1025        echo '      *** Deleting ... '
1026        rm ${STALE_RC_FILES}
1027        echo '                       done.'
1028      fi
1029    esac
1030    ;;
1031  esac
1032  echo ''
1033fi
1034
1035cd "${TEMPROOT}"
1036
1037if [ -r "${MM_PRE_COMPARE_SCRIPT}" ]; then
1038  . "${MM_PRE_COMPARE_SCRIPT}"
1039fi
1040
1041# Things that were files/directories/links in one version can sometimes
1042# change to something else in a newer version.  So we need to explicitly
1043# test for this, and warn the user if what we find does not match.
1044#
1045for COMPFILE in `find . | sort` ; do
1046  if [ -e "${DESTDIR}${COMPFILE#.}" ]; then
1047    INSTALLED_TYPE=`stat -f '%HT' ${DESTDIR}${COMPFILE#.}`
1048  else
1049    continue
1050  fi
1051  TEMPROOT_TYPE=`stat -f '%HT' $COMPFILE`
1052
1053  if [ ! "$TEMPROOT_TYPE" = "$INSTALLED_TYPE" ]; then
1054    [ "$COMPFILE" = '.' ] && continue
1055    TEMPROOT_TYPE=`echo $TEMPROOT_TYPE | tr [:upper:] [:lower:]`
1056    INSTALLED_TYPE=`echo $INSTALLED_TYPE | tr [:upper:] [:lower:]`
1057
1058    echo "*** The installed file ${DESTDIR}${COMPFILE#.} has the type \"$INSTALLED_TYPE\""
1059    echo "    but the new version has the type \"$TEMPROOT_TYPE\""
1060    echo ''
1061    echo "    How would you like to handle this?"
1062    echo ''
1063    echo "    Use 'r' to remove ${DESTDIR}${COMPFILE#.}"
1064    case "$TEMPROOT_TYPE" in
1065    'symbolic link')
1066	TARGET=`readlink $COMPFILE`
1067	echo "    and create a link to $TARGET in its place" ;;
1068    *)	echo "    You will be able to install it as a \"$TEMPROOT_TYPE\"" ;;
1069    esac
1070    echo ''
1071    echo "    Use 'i' to ignore this"
1072    echo ''
1073    echo -n "    How to proceed? [i] "
1074    read ANSWER
1075    case "$ANSWER" in
1076    [rR])	case "${PRESERVE_FILES}" in
1077		[Yy][Ee][Ss])
1078		mv ${DESTDIR}${COMPFILE#.} ${PRESERVE_FILES_DIR}/ || exit 1 ;;
1079		*) rm -rf ${DESTDIR}${COMPFILE#.} ;;
1080		esac
1081		case "$TEMPROOT_TYPE" in
1082		'symbolic link') ln -sf $TARGET ${DESTDIR}${COMPFILE#.} ;;
1083		esac ;;
1084    *)	echo ''
1085        echo "*** See the man page about adding ${COMPFILE#.} to the list of IGNORE_FILES"
1086        press_to_continue ;;
1087    esac
1088    echo ''
1089  fi
1090done
1091
1092for COMPFILE in `find . -type f | sort`; do
1093
1094  # First, check to see if the file exists in DESTDIR.  If not, the
1095  # diff_loop function knows how to handle it.
1096  #
1097  if [ ! -e "${DESTDIR}${COMPFILE#.}" ]; then
1098    case "${AUTO_RUN}" in
1099      '')
1100        diff_loop
1101        ;;
1102      *)
1103        case "${AUTO_INSTALL}" in
1104        '')
1105          # If this is an auto run, make it official
1106          echo "   *** ${COMPFILE} will remain for your consideration"
1107          ;;
1108        *)
1109          diff_loop
1110          ;;
1111        esac
1112        ;;
1113    esac # Auto run test
1114    continue
1115  fi
1116
1117  case "${STRICT}" in
1118  '' | [Nn][Oo])
1119    # Compare $Id's first so if the file hasn't been modified
1120    # local changes will be ignored.
1121    # If the files have the same $Id, delete the one in temproot so the
1122    # user will have less to wade through if files are left to merge by hand.
1123    #
1124    ID1=`grep "[$]${ID_TAG}:" ${DESTDIR}${COMPFILE#.} 2>/dev/null`
1125    ID2=`grep "[$]${ID_TAG}:" ${COMPFILE} 2>/dev/null` || ID2=none
1126
1127    case "${ID2}" in
1128    "${ID1}")
1129      echo " *** Temp ${COMPFILE} and installed have the same Id, deleting"
1130      rm "${COMPFILE}"
1131      ;;
1132    esac
1133    ;;
1134  esac
1135
1136  # If the file is still here either because the $Ids are different, the
1137  # file doesn't have an $Id, or we're using STRICT mode; look at the diff.
1138  #
1139  if [ -f "${COMPFILE}" ]; then
1140
1141    # Do an absolute diff first to see if the files are actually different.
1142    # If they're not different, delete the one in temproot.
1143    #
1144    if diff -q ${DIFF_OPTIONS} "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" > \
1145      /dev/null 2>&1; then
1146      echo " *** Temp ${COMPFILE} and installed are the same, deleting"
1147      rm "${COMPFILE}"
1148    else
1149      # Ok, the files are different, so show the user where they differ.
1150      # Use user's choice of diff methods; and user's pager if they have one.
1151      # Use less if not.
1152      # Use unified diffs by default.  Context diffs give me a headache. :)
1153      #
1154      # If the user chose the -F option, test for that before proceeding
1155      #
1156      if [ -n "$FREEBSD_ID" ]; then
1157        if diff -q -I'[$]FreeBSD.*[$]' "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" > \
1158            /dev/null 2>&1; then
1159          if mm_install "${COMPFILE}"; then
1160            echo "*** Updated revision control Id for ${DESTDIR}${COMPFILE#.}"
1161          else
1162            echo "*** Problem installing ${COMPFILE}, it will remain to merge by hand later"
1163          fi
1164          continue
1165        fi
1166      fi
1167      case "${AUTO_RUN}" in
1168      '')
1169        # prompt user to install/delete/merge changes
1170        diff_loop
1171        ;;
1172      *)
1173        # If this is an auto run, make it official
1174        echo "   *** ${COMPFILE} will remain for your consideration"
1175        ;;
1176      esac # Auto run test
1177    fi # Yes, the files are different
1178  fi # Yes, the file still remains to be checked
1179done # This is for the for way up there at the beginning of the comparison
1180
1181echo ''
1182echo "*** Comparison complete"
1183
1184if [ -s "${MTREENEW}" ]; then
1185  echo "*** Saving mtree database for future upgrades"
1186  test -e "${MTREEFILE}" && unlink ${MTREEFILE}
1187  mv ${MTREENEW} ${MTREEFILE}
1188fi
1189
1190echo ''
1191
1192TEST_FOR_FILES=`find ${TEMPROOT} -type f -size +0 2>/dev/null`
1193if [ -n "${TEST_FOR_FILES}" ]; then
1194  echo "*** Files that remain for you to merge by hand:"
1195  find "${TEMPROOT}" -type f -size +0 | sort
1196  echo ''
1197
1198  case "${AUTO_RUN}" in
1199  '')
1200    echo -n "Do you wish to delete what is left of ${TEMPROOT}? [no] "
1201    read DEL_TEMPROOT
1202    case "${DEL_TEMPROOT}" in
1203    [yY]*)
1204      delete_temproot
1205      ;;
1206    *)
1207      echo " *** ${TEMPROOT} will remain"
1208      ;;
1209    esac
1210    ;;
1211  *) ;;
1212  esac
1213else
1214  echo "*** ${TEMPROOT} is empty, deleting"
1215  delete_temproot
1216fi
1217
1218case "${AUTO_INSTALLED_FILES}" in
1219'') ;;
1220*)
1221  case "${AUTO_RUN}" in
1222  '')
1223    (
1224      echo ''
1225      echo '*** You chose the automatic install option for files that did not'
1226      echo '    exist on your system.  The following were installed for you:'
1227      echo "${AUTO_INSTALLED_FILES}"
1228    ) | ${PAGER}
1229    ;;
1230  *)
1231    echo ''
1232    echo '*** You chose the automatic install option for files that did not'
1233    echo '    exist on your system.  The following were installed for you:'
1234    echo "${AUTO_INSTALLED_FILES}"
1235    ;;
1236  esac
1237  ;;
1238esac
1239
1240case "${AUTO_UPGRADED_FILES}" in
1241'') ;;
1242*)
1243  case "${AUTO_RUN}" in
1244  '')
1245    (
1246      echo ''
1247      echo '*** You chose the automatic upgrade option for files that you did'
1248      echo '    not alter on your system.  The following were upgraded for you:'
1249      echo "${AUTO_UPGRADED_FILES}"
1250    ) | ${PAGER}
1251    ;;
1252  *)
1253    echo ''
1254    echo '*** You chose the automatic upgrade option for files that you did'
1255    echo '    not alter on your system.  The following were upgraded for you:'
1256    echo "${AUTO_UPGRADED_FILES}"
1257    ;;
1258  esac
1259  ;;
1260esac
1261
1262run_it_now () {
1263  [ -n "$AUTO_RUN" ] && return
1264
1265  local answer
1266
1267  echo ''
1268  while : ; do
1269    if [ "$RUN_UPDATES" = always ]; then
1270      answer=y
1271    elif [ "$RUN_UPDATES" = never ]; then
1272      answer=n
1273    else
1274      echo -n '    Would you like to run it now? y or n [n] '
1275      read answer
1276    fi
1277
1278    case "$answer" in
1279    y)
1280      echo "    Running ${1}"
1281      echo ''
1282      eval "${1}"
1283      return
1284      ;;
1285    ''|n)
1286      if [ ! "$RUN_UPDATES" = never ]; then
1287        echo ''
1288        echo "       *** Cancelled"
1289        echo ''
1290      fi
1291      echo "    Make sure to run ${1} yourself"
1292      return
1293      ;;
1294    *)
1295      echo ''
1296      echo "       *** Sorry, I do not understand your answer (${answer})"
1297      echo ''
1298    esac
1299  done
1300}
1301
1302case "${NEED_NEWALIASES}" in
1303'') ;;
1304*)
1305  echo ''
1306  if [ -n "${DESTDIR}" ]; then
1307    echo "*** You installed a new aliases file into ${DESTDIR}/etc/mail, but"
1308    echo "    the newaliases command is limited to the directories configured"
1309    echo "    in sendmail.cf.  Make sure to create your aliases database by"
1310    echo "    hand when your sendmail configuration is done."
1311  else
1312    echo "*** You installed a new aliases file, so make sure that you run"
1313    echo "    '/usr/bin/newaliases' to rebuild your aliases database"
1314    run_it_now '/usr/bin/newaliases'
1315  fi
1316  ;;
1317esac
1318
1319case "${NEED_CAP_MKDB}" in
1320'') ;;
1321*)
1322  echo ''
1323  echo "*** You installed a login.conf file, so make sure that you run"
1324  echo "    '/usr/bin/cap_mkdb ${DESTDIR}/etc/login.conf'"
1325  echo "     to rebuild your login.conf database"
1326  run_it_now "/usr/bin/cap_mkdb ${DESTDIR}/etc/login.conf"
1327  ;;
1328esac
1329
1330case "${NEED_SERVICES_MKDB}" in
1331'') ;;
1332*)
1333  echo ''
1334  echo "*** You installed a services file, so make sure that you run"
1335  echo "    '/usr/sbin/services_mkdb -q -o ${DESTDIR}/var/db/services.db ${DESTDIR}/etc/services'"
1336  echo "     to rebuild your services database"
1337  run_it_now "/usr/sbin/services_mkdb -q -o ${DESTDIR}/var/db/services.db ${DESTDIR}/etc/services"
1338  ;;
1339esac
1340
1341case "${NEED_PWD_MKDB}" in
1342'') ;;
1343*)
1344  echo ''
1345  echo "*** You installed a new master.passwd file, so make sure that you run"
1346  if [ -n "${DESTDIR}" ]; then
1347    echo "    '/usr/sbin/pwd_mkdb -d ${DESTDIR}/etc -p ${DESTDIR}/etc/master.passwd'"
1348    echo "    to rebuild your password files"
1349    run_it_now "/usr/sbin/pwd_mkdb -d ${DESTDIR}/etc -p ${DESTDIR}/etc/master.passwd"
1350  else
1351    echo "    '/usr/sbin/pwd_mkdb -p /etc/master.passwd'"
1352    echo "     to rebuild your password files"
1353    run_it_now '/usr/sbin/pwd_mkdb -p /etc/master.passwd'
1354  fi
1355  ;;
1356esac
1357
1358if [ -e "${DESTDIR}/etc/localtime" -a ! -L "${DESTDIR}/etc/localtime" -a -z "${PRE_WORLD}" ]; then	# Ignore if TZ == UTC
1359  echo ''
1360  [ -n "${DESTDIR}" ] && tzs_args="-C ${DESTDIR}"
1361  if [ -f "${DESTDIR}/var/db/zoneinfo" ]; then
1362    echo "*** Reinstalling `cat ${DESTDIR}/var/db/zoneinfo` as ${DESTDIR}/etc/localtime"
1363    tzsetup $tzs_args -r
1364  else
1365    echo "*** There is no ${DESTDIR}/var/db/zoneinfo file to update ${DESTDIR}/etc/localtime."
1366    echo '    You should run tzsetup'
1367    run_it_now "tzsetup $tzs_args"
1368  fi
1369fi
1370
1371echo ''
1372
1373if [ -r "${MM_EXIT_SCRIPT}" ]; then
1374  . "${MM_EXIT_SCRIPT}"
1375fi
1376
1377case "${COMP_CONFS}" in
1378'') ;;
1379*)
1380  . ${DESTDIR}/etc/defaults/rc.conf
1381
1382  (echo ''
1383  echo "*** Comparing conf files: ${rc_conf_files}"
1384
1385  for CONF_FILE in ${rc_conf_files}; do
1386    if [ -r "${DESTDIR}${CONF_FILE}" ]; then
1387      echo ''
1388      echo "*** From ${DESTDIR}${CONF_FILE}"
1389      echo "*** From ${DESTDIR}/etc/defaults/rc.conf"
1390
1391      for RC_CONF_VAR in `grep -i ^[a-z] ${DESTDIR}${CONF_FILE} |
1392        cut -d '=' -f 1`; do
1393        echo ''
1394        grep -w ^${RC_CONF_VAR} ${DESTDIR}${CONF_FILE}
1395        grep -w ^${RC_CONF_VAR} ${DESTDIR}/etc/defaults/rc.conf ||
1396          echo ' * No default variable with this name'
1397      done
1398    fi
1399  done) | ${PAGER}
1400  echo ''
1401  ;;
1402esac
1403
1404if [ -n "${PRESERVE_FILES}" ]; then
1405  find -d $PRESERVE_FILES_DIR -type d -empty -delete 2>/dev/null
1406  rmdir $PRESERVE_FILES_DIR 2>/dev/null
1407fi
1408
1409exit 0
1410
1411#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1412
1413#  Copyright (c) 1998-2012 Douglas Barton
1414#  All rights reserved.
1415#
1416#  Redistribution and use in source and binary forms, with or without
1417#  modification, are permitted provided that the following conditions
1418#  are met:
1419#  1. Redistributions of source code must retain the above copyright
1420#     notice, this list of conditions and the following disclaimer.
1421#  2. Redistributions in binary form must reproduce the above copyright
1422#     notice, this list of conditions and the following disclaimer in the
1423#     documentation and/or other materials provided with the distribution.
1424#
1425#  THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1426#  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1427#  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1428#  ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1429#  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1430#  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1431#  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1432#  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1433#  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1434#  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1435#  SUCH DAMAGE.
1436