]> CyberLeo.Net >> Repos - FreeBSD/stable/8.git/blob - usr.sbin/mergemaster/mergemaster.sh
MFC r228122:
[FreeBSD/stable/8.git] / usr.sbin / mergemaster / mergemaster.sh
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-2011 Douglas Barton
9 # dougb@FreeBSD.org
10
11 # $FreeBSD$
12
13 PATH=/bin:/usr/bin:/usr/sbin
14
15 display_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
46 display_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.
56 merge_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
113 diff_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
244 press_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 #
252 TEMPROOT='/var/tmp/temproot'
253
254 # Read /etc/mergemaster.rc first so the one in $HOME can override
255 #
256 if [ -r /etc/mergemaster.rc ]; then
257   . /etc/mergemaster.rc
258 fi
259
260 # Read .mergemasterrc before command line so CLI can override
261 #
262 if [ -r "$HOME/.mergemasterrc" ]; then
263   . "$HOME/.mergemasterrc"
264 fi
265
266 for 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
275 done
276
277 set -- $newopts
278 unset var newopts
279
280 # Check the command line options
281 #
282 while 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
354 done
355
356 if [ -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
366 fi
367
368 # Assign the location of the mtree database
369 #
370 MTREEDB=${MTREEDB:-${DESTDIR}/var/db}
371 MTREEFILE="${MTREEDB}/mergemaster.mtree"
372
373 # Don't force the user to set this in the mergemaster rc file
374 if [ -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}
377 fi
378
379 # Check for the mtree database in DESTDIR
380 case "${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   ;;
397 esac
398
399 if [ -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
409 fi
410
411 echo ''
412
413 # If the user has a pager defined, make sure we can run it
414 #
415 case "${DONT_CHECK_PAGER}" in
416 '')
417 check_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     if [ -x /usr/bin/less -o -x /usr/local/bin/less ]; then
425     echo "  Use 'l' to set PAGER to 'less' for this run"
426     fi
427     echo "  Use 'm' to use plain old 'more' as your PAGER for this run"
428     echo ''
429     echo "  Default is to use plain old 'more' "
430     echo ''
431     echo -n "What should I do? [Use 'more'] "
432     read FIXPAGER
433
434     case "${FIXPAGER}" in
435     [eE])
436        exit 0
437        ;;
438     [lL])
439        if [ -x /usr/bin/less ]; then
440          PAGER=/usr/bin/less
441        elif [ -x /usr/local/bin/less ]; then
442          PAGER=/usr/local/bin/less
443        else
444          echo ''
445          echo " *** Fatal Error:"
446          echo "     You asked to use 'less' as your pager, but I can't"
447          echo "     find it in /usr/bin or /usr/local/bin"
448          exit 1
449        fi
450        ;;
451     [mM]|'')
452        PAGER=more
453        ;;
454     *)
455        echo ''
456        echo "invalid choice: ${FIXPAGER}"
457     esac
458     echo ''
459   done
460 }
461   if [ -n "${PAGER}" ]; then
462     check_pager
463   fi
464   ;;
465 esac
466
467 # If user has a pager defined, or got assigned one above, use it.
468 # If not, use more.
469 #
470 PAGER=${PAGER:-more}
471
472 if [ -n "${VERBOSE}" -a ! "${PAGER}" = "more" ]; then
473   echo " *** You have ${PAGER} defined as your pager so we will use that"
474   echo ''
475   sleep 3
476 fi
477
478 # Assign the diff flag once so we will not have to keep testing it
479 #
480 DIFF_FLAG=${DIFF_FLAG:--u}
481
482 # Assign the source directory
483 #
484 SOURCEDIR=${SOURCEDIR:-/usr/src}
485 if [ ! -f ${SOURCEDIR}/Makefile.inc1 -a \
486    -f ${SOURCEDIR}/../Makefile.inc1 ]; then
487   echo " *** The source directory you specified (${SOURCEDIR})"
488   echo "     will be reset to ${SOURCEDIR}/.."
489   echo ''
490   sleep 3
491   SOURCEDIR=${SOURCEDIR}/..
492 fi
493
494 # Setup make to use system files from SOURCEDIR
495 MM_MAKE="make ${ARCHSTRING} -m ${SOURCEDIR}/share/mk"
496
497 # Check DESTDIR against the mergemaster mtree database to see what
498 # files the user changed from the reference files.
499 #
500 if [ -n "${AUTO_UPGRADE}" -a -s "${MTREEFILE}" ]; then
501         CHANGED=:
502         for file in `mtree -eqL -f ${MTREEFILE} -p ${DESTDIR}/ \
503                 2>/dev/null | awk '($2 == "changed") {print $1}'`; do
504                 if [ -f "${DESTDIR}/$file" ]; then
505                         CHANGED="${CHANGED}${DESTDIR}/${file}:"
506                 fi
507         done
508         [ "$CHANGED" = ':' ] && unset CHANGED
509 fi
510
511 # Check the width of the user's terminal
512 #
513 if [ -t 0 ]; then
514   w=`tput columns`
515   case "${w}" in
516   0|'') ;; # No-op, since the input is not valid
517   *)
518     case "${SCREEN_WIDTH}" in
519     '') SCREEN_WIDTH="${w}" ;;
520     "${w}") ;; # No-op, since they are the same
521     *)
522       echo -n "*** You entered ${SCREEN_WIDTH} as your screen width, but stty "
523       echo "thinks it is ${w}."
524       echo ''
525       echo -n "What would you like to use? [${w}] "
526       read SCREEN_WIDTH
527       case "${SCREEN_WIDTH}" in
528       '') SCREEN_WIDTH="${w}" ;;
529       esac
530       ;;
531     esac
532   esac
533 fi
534
535 # Define what CVS $Id tag to look for to aid portability.
536 #
537 CVS_ID_TAG=FreeBSD
538
539 delete_temproot () {
540   rm -rf "${TEMPROOT}" 2>/dev/null
541   chflags -R 0 "${TEMPROOT}" 2>/dev/null
542   rm -rf "${TEMPROOT}" || { echo "*** Unable to delete ${TEMPROOT}";  exit 1; }
543 }
544
545 case "${RERUN}" in
546 '')
547   # Set up the loop to test for the existence of the
548   # temp root directory.
549   #
550   TEST_TEMP_ROOT=yes
551   while [ "${TEST_TEMP_ROOT}" = "yes" ]; do
552     if [ -d "${TEMPROOT}" ]; then
553       echo "*** The directory specified for the temporary root environment,"
554       echo "    ${TEMPROOT}, exists.  This can be a security risk if untrusted"
555       echo "    users have access to the system."
556       echo ''
557       case "${AUTO_RUN}" in
558       '')
559         echo "  Use 'd' to delete the old ${TEMPROOT} and continue"
560         echo "  Use 't' to select a new temporary root directory"
561         echo "  Use 'e' to exit mergemaster"
562         echo ''
563         echo "  Default is to use ${TEMPROOT} as is"
564         echo ''
565         echo -n "How should I deal with this? [Use the existing ${TEMPROOT}] "
566         read DELORNOT
567
568         case "${DELORNOT}" in
569         [dD])
570           echo ''
571           echo "   *** Deleting the old ${TEMPROOT}"
572           echo ''
573           delete_temproot
574           unset TEST_TEMP_ROOT
575           ;;
576         [tT])
577           echo "   *** Enter new directory name for temporary root environment"
578           read TEMPROOT
579           ;;
580         [eE])
581           exit 0
582           ;;
583         '')
584           echo ''
585           echo "   *** Leaving ${TEMPROOT} intact"
586           echo ''
587           unset TEST_TEMP_ROOT
588           ;;
589         *)
590           echo ''
591           echo "invalid choice: ${DELORNOT}"
592           echo ''
593           ;;
594         esac
595         ;;
596       *)
597         # If this is an auto-run, try a hopefully safe alternative then
598         # re-test anyway.
599         TEMPROOT=/var/tmp/temproot.`date +%m%d.%H.%M.%S`
600         ;;
601       esac
602     else
603       unset TEST_TEMP_ROOT
604     fi
605   done
606
607   echo "*** Creating the temporary root environment in ${TEMPROOT}"
608
609   if mkdir -p "${TEMPROOT}"; then
610     echo " *** ${TEMPROOT} ready for use"
611   fi
612
613   if [ ! -d "${TEMPROOT}" ]; then
614     echo ''
615     echo "  *** FATAL ERROR: Cannot create ${TEMPROOT}"
616     echo ''
617     exit 1
618   fi
619
620   echo " *** Creating and populating directory structure in ${TEMPROOT}"
621   echo ''
622
623   case "${VERBOSE}" in
624   '') ;;
625   *)
626     press_to_continue
627     ;;
628   esac
629
630   case "${PRE_WORLD}" in
631   '')
632     { cd ${SOURCEDIR} &&
633       case "${DESTDIR}" in
634       '') ;;
635       *)
636         ${MM_MAKE} DESTDIR=${DESTDIR} distrib-dirs >/dev/null
637         ;;
638       esac
639       od=${TEMPROOT}/usr/obj
640       ${MM_MAKE} DESTDIR=${TEMPROOT} distrib-dirs >/dev/null &&
641       MAKEOBJDIRPREFIX=$od ${MM_MAKE} _obj SUBDIR_OVERRIDE=etc >/dev/null &&
642       MAKEOBJDIRPREFIX=$od ${MM_MAKE} everything SUBDIR_OVERRIDE=etc >/dev/null &&
643       MAKEOBJDIRPREFIX=$od ${MM_MAKE} DESTDIR=${TEMPROOT} distribution >/dev/null;} ||
644     { echo '';
645      echo "  *** FATAL ERROR: Cannot 'cd' to ${SOURCEDIR} and install files to";
646       echo "      the temproot environment";
647       echo '';
648       exit 1;}
649     ;;
650   *)
651     # Only set up files that are crucial to {build|install}world
652     { mkdir -p ${TEMPROOT}/etc &&
653       cp -p ${SOURCEDIR}/etc/master.passwd ${TEMPROOT}/etc &&
654       install -p -o root -g wheel -m 0644 ${SOURCEDIR}/etc/group ${TEMPROOT}/etc;} ||
655     { echo '';
656       echo '  *** FATAL ERROR: Cannot copy files to the temproot environment';
657       echo '';
658       exit 1;}
659     ;;
660   esac
661
662   # Doing the inventory and removing files that we don't want to compare only
663   # makes sense if we are not doing a rerun, since we have no way of knowing
664   # what happened to the files during previous incarnations.
665   case "${VERBOSE}" in
666   '') ;;
667   *)
668     echo ''
669     echo ' *** The following files exist only in the installed version of'
670     echo "     ${DESTDIR}/etc.  In the vast majority of cases these files"
671     echo '     are necessary parts of the system and should not be deleted.'
672     echo '     However because these files are not updated by this process you'
673     echo '     might want to verify their status before rebooting your system.'
674     echo ''
675     press_to_continue
676     diff -qr ${DESTDIR}/etc ${TEMPROOT}/etc | grep "^Only in ${DESTDIR}/etc" | ${PAGER}
677     echo ''
678     press_to_continue
679     ;;
680   esac
681
682   # Avoid comparing the motd if the user specifies it in .mergemasterrc
683   # Compatibility shim to be removed in FreeBSD 9.x
684   case "${IGNORE_MOTD}" in
685   '') ;;
686   *) IGNORE_FILES="${IGNORE_FILES} /etc/motd"
687      echo ''
688      echo "*** You have the IGNORE_MOTD option set in your mergemaster rc file."
689      echo "    This option is deprecated in favor of the IGNORE_FILES option."
690      echo "    Please update your rc file accordingly."
691      echo ''
692      press_to_continue
693      ;;
694   esac
695
696   # Avoid comparing the following user specified files
697   for file in ${IGNORE_FILES}; do
698     test -e ${TEMPROOT}/${file} && unlink ${TEMPROOT}/${file}
699   done
700
701   # We really don't want to have to deal with files like login.conf.db, pwd.db,
702   # or spwd.db.  Instead, we want to compare the text versions, and run *_mkdb.
703   # Prompt the user to do so below, as needed.
704   #
705   rm -f ${TEMPROOT}/etc/*.db ${TEMPROOT}/etc/passwd
706
707   # We only need to compare things like freebsd.cf once
708   find ${TEMPROOT}/usr/obj -type f -delete 2>/dev/null
709
710   # Delete stuff we do not need to keep the mtree database small,
711   # and to make the actual comparison faster.
712   find ${TEMPROOT}/usr -type l -delete 2>/dev/null
713   find ${TEMPROOT} -type f -size 0 -delete 2>/dev/null
714   find -d ${TEMPROOT} -type d -empty -delete 2>/dev/null
715
716   # Build the mtree database in a temporary location.
717   case "${PRE_WORLD}" in
718   '') MTREENEW=`mktemp -t mergemaster.mtree`
719       mtree -ci -p ${TEMPROOT} -k size,md5digest > ${MTREENEW} 2>/dev/null
720       ;;
721   *) # We don't want to mess with the mtree database on a pre-world run or
722      # when re-scanning a previously-built tree.
723      ;;
724   esac
725   ;; # End of the "RERUN" test
726 esac
727
728 # Get ready to start comparing files
729
730 # Check umask if not specified on the command line,
731 # and we are not doing an autorun
732 #
733 if [ -z "${NEW_UMASK}" -a -z "${AUTO_RUN}" ]; then
734   USER_UMASK=`umask`
735   case "${USER_UMASK}" in
736   0022|022) ;;
737   *)
738     echo ''
739     echo " *** Your umask is currently set to ${USER_UMASK}.  By default, this script"
740     echo "     installs all files with the same user, group and modes that"
741     echo "     they are created with by ${SOURCEDIR}/etc/Makefile, compared to"
742     echo "     a umask of 022.  This umask allows world read permission when"
743     echo "     the file's default permissions have it."
744     echo ''
745     echo "     No world permissions can sometimes cause problems.  A umask of"
746     echo "     022 will restore the default behavior, but is not mandatory."
747     echo "     /etc/master.passwd is a special case.  Its file permissions"
748     echo "     will be 600 (rw-------) if installed."
749     echo ''
750     echo -n "What umask should I use? [${USER_UMASK}] "
751     read NEW_UMASK
752
753     NEW_UMASK="${NEW_UMASK:-$USER_UMASK}"
754     ;;
755   esac
756   echo ''
757 fi
758
759 CONFIRMED_UMASK=${NEW_UMASK:-0022}
760
761 #
762 # Warn users who still have old rc files
763 #
764 for file in atm devfs diskless1 diskless2 network network6 pccard \
765   serial syscons sysctl alpha amd64 i386 ia64 sparc64; do
766   if [ -f "${DESTDIR}/etc/rc.${file}" ]; then
767     OLD_RC_PRESENT=1
768     break
769   fi
770 done
771
772 case "${OLD_RC_PRESENT}" in
773 1)
774   echo ''
775   echo " *** There are elements of the old rc system in ${DESTDIR}/etc/."
776   echo ''
777   echo '     While these scripts will not hurt anything, they are not'
778   echo '     functional on an up to date system, and can be removed.'
779   echo ''
780
781   case "${AUTO_RUN}" in
782   '')
783     echo -n 'Move these files to /var/tmp/mergemaster/old_rc? [yes] '
784     read MOVE_OLD_RC
785
786     case "${MOVE_OLD_RC}" in
787     [nN]*) ;;
788     *)
789       mkdir -p /var/tmp/mergemaster/old_rc
790         for file in atm devfs diskless1 diskless2 network network6 pccard \
791           serial syscons sysctl alpha amd64 i386 ia64 sparc64; do
792           if [ -f "${DESTDIR}/etc/rc.${file}" ]; then
793             mv ${DESTDIR}/etc/rc.${file} /var/tmp/mergemaster/old_rc/
794           fi
795         done
796       echo '  The files have been moved'
797       press_to_continue
798       ;;
799     esac
800     ;;
801   *) ;;
802   esac
803 esac
804
805 # Use the umask/mode information to install the files
806 # Create directories as needed
807 #
808 install_error () {
809   echo "*** FATAL ERROR: Unable to install ${1} to ${2}"
810   echo ''
811   exit 1
812 }
813
814 do_install_and_rm () {
815   case "${PRESERVE_FILES}" in
816   [Yy][Ee][Ss])
817     if [ -f "${3}/${2##*/}" ]; then
818       mkdir -p ${PRESERVE_FILES_DIR}/${2%/*}
819       cp ${3}/${2##*/} ${PRESERVE_FILES_DIR}/${2%/*}
820     fi
821     ;;
822   esac
823
824   if [ ! -d "${3}/${2##*/}" ]; then
825     if install -m ${1} ${2} ${3}; then
826       unlink ${2}
827     else
828       install_error ${2} ${3}
829     fi
830   else
831     install_error ${2} ${3}
832   fi
833 }
834
835 # 4095 = "obase=10;ibase=8;07777" | bc
836 find_mode () {
837   local OCTAL
838   OCTAL=$(( ~$(echo "obase=10; ibase=8; ${CONFIRMED_UMASK}" | bc) & 4095 &
839     $(echo "obase=10; ibase=8; $(stat -f "%OMp%OLp" ${1})" | bc) ))
840   printf "%04o\n" ${OCTAL}
841 }
842
843 mm_install () {
844   local INSTALL_DIR
845   INSTALL_DIR=${1#.}
846   INSTALL_DIR=${INSTALL_DIR%/*}
847
848   case "${INSTALL_DIR}" in
849   '')
850     INSTALL_DIR=/
851     ;;
852   esac
853
854   if [ -n "${DESTDIR}${INSTALL_DIR}" -a ! -d "${DESTDIR}${INSTALL_DIR}" ]; then
855     DIR_MODE=`find_mode "${TEMPROOT}/${INSTALL_DIR}"`
856     install -d -o root -g wheel -m "${DIR_MODE}" "${DESTDIR}${INSTALL_DIR}" ||
857       install_error $1 ${DESTDIR}${INSTALL_DIR}
858   fi
859
860   FILE_MODE=`find_mode "${1}"`
861
862   if [ ! -x "${1}" ]; then
863     case "${1#.}" in
864     /etc/mail/aliases)
865       NEED_NEWALIASES=yes
866       ;;
867     /etc/login.conf)
868       NEED_CAP_MKDB=yes
869       ;;
870     /etc/services)
871       NEED_SERVICES_MKDB=yes
872       ;;
873     /etc/master.passwd)
874       do_install_and_rm 600 "${1}" "${DESTDIR}${INSTALL_DIR}"
875       NEED_PWD_MKDB=yes
876       DONT_INSTALL=yes
877       ;;
878     /.cshrc | /.profile)
879       local st_nlink
880
881       # install will unlink the file before it installs the new one,
882       # so we have to restore/create the link afterwards.
883       #
884       st_nlink=0                # In case the file does not yet exist
885       eval $(stat -s ${DESTDIR}${COMPFILE#.} 2>/dev/null)
886
887       do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}"
888
889       if [ -n "${AUTO_INSTALL}" -a $st_nlink -gt 1 ]; then
890         HANDLE_LINK=l
891       else
892         case "${LINK_EXPLAINED}" in
893         '')
894           echo "   *** Historically BSD derived systems have had a"
895           echo "       hard link from /.cshrc and /.profile to"
896           echo "       their namesakes in /root.  Please indicate"
897           echo "       your preference below for bringing your"
898           echo "       installed files up to date."
899           echo ''
900           LINK_EXPLAINED=yes
901           ;;
902         esac
903
904         echo "   Use 'd' to delete the temporary ${COMPFILE}"
905         echo "   Use 'l' to delete the existing ${DESTDIR}/root/${COMPFILE##*/} and create the link"
906         echo ''
907         echo "   Default is to leave the temporary file to deal with by hand"
908         echo ''
909         echo -n "  How should I handle ${COMPFILE}? [Leave it to install later] "
910         read HANDLE_LINK
911       fi
912
913       case "${HANDLE_LINK}" in
914       [dD]*)
915         rm "${COMPFILE}"
916         echo ''
917         echo "   *** Deleting ${COMPFILE}"
918         ;;
919       [lL]*)
920         echo ''
921         unlink ${DESTDIR}/root/${COMPFILE##*/}
922         if ln ${DESTDIR}${COMPFILE#.} ${DESTDIR}/root/${COMPFILE##*/}; then
923           echo "   *** Link from ${DESTDIR}${COMPFILE#.} to ${DESTDIR}/root/${COMPFILE##*/} installed successfully"
924         else
925           echo "   *** Error linking ${DESTDIR}${COMPFILE#.} to ${DESTDIR}/root/${COMPFILE##*/}"
926           echo "   *** ${COMPFILE} will remain for your consideration"
927         fi
928         ;;
929       *)
930         echo "   *** ${COMPFILE} will remain for your consideration"
931         ;;
932       esac
933       return
934       ;;
935     esac
936
937     case "${DONT_INSTALL}" in
938     '')
939       do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}"
940       ;;
941     *)
942       unset DONT_INSTALL
943       ;;
944     esac
945   else  # File matched -x
946     do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}"
947   fi
948   return $?
949 }
950
951 if [ ! -d "${TEMPROOT}" ]; then
952         echo "*** FATAL ERROR: The temproot directory (${TEMPROOT})"
953         echo '                 has disappeared!'
954         echo ''
955         exit 1
956 fi
957
958 echo ''
959 echo "*** Beginning comparison"
960 echo ''
961
962 # Pre-world does not populate /etc/rc.d.
963 # It is very possible that a previous run would have deleted files in
964 # ${TEMPROOT}/etc/rc.d, thus creating a lot of false positives.
965 if [ -z "${PRE_WORLD}" -a -z "${RERUN}" ]; then
966   echo "   *** Checking ${DESTDIR}/etc/rc.d for stale files"
967   echo ''
968   cd "${DESTDIR}/etc/rc.d" &&
969   for file in *; do
970     if [ ! -e "${TEMPROOT}/etc/rc.d/${file}" ]; then
971       STALE_RC_FILES="${STALE_RC_FILES} ${file}"
972     fi
973   done
974   case "${STALE_RC_FILES}" in
975   ''|' *')
976     echo '   *** No stale files found'
977     ;;
978   *)
979     echo "   *** The following files exist in ${DESTDIR}/etc/rc.d but not in"
980     echo "       ${TEMPROOT}/etc/rc.d/:"
981     echo ''
982     echo "${STALE_RC_FILES}"
983     echo ''
984     echo '       The presence of stale files in this directory can cause the'
985     echo '       dreaded unpredictable results, and therefore it is highly'
986     echo '       recommended that you delete them.'
987     case "${AUTO_RUN}" in
988     '')
989       echo ''
990       echo -n '   *** Delete them now? [n] '
991       read DELETE_STALE_RC_FILES
992       case "${DELETE_STALE_RC_FILES}" in
993       [yY])
994         echo '      *** Deleting ... '
995         rm ${STALE_RC_FILES}
996         echo '                       done.'
997         ;;
998       *)
999         echo '      *** Files will not be deleted'
1000         ;;
1001       esac
1002       sleep 2
1003       ;;
1004     *)
1005       if [ -n "${DELETE_STALE_RC_FILES}" ]; then
1006         echo '      *** Deleting ... '
1007         rm ${STALE_RC_FILES}
1008         echo '                       done.'
1009       fi
1010     esac
1011     ;;
1012   esac
1013   echo ''
1014 fi
1015
1016 cd "${TEMPROOT}"
1017
1018 if [ -r "${MM_PRE_COMPARE_SCRIPT}" ]; then
1019   . "${MM_PRE_COMPARE_SCRIPT}"
1020 fi
1021
1022 # Things that were files/directories/links in one version can sometimes
1023 # change to something else in a newer version.  So we need to explicitly
1024 # test for this, and warn the user if what we find does not match.
1025 #
1026 for COMPFILE in `find . | sort` ; do
1027   if [ -e "${DESTDIR}${COMPFILE#.}" ]; then
1028     INSTALLED_TYPE=`stat -f '%HT' ${DESTDIR}${COMPFILE#.}`
1029   else
1030     continue
1031   fi
1032   TEMPROOT_TYPE=`stat -f '%HT' $COMPFILE`
1033
1034   if [ ! "$TEMPROOT_TYPE" = "$INSTALLED_TYPE" ]; then
1035     [ "$COMPFILE" = '.' ] && continue
1036     TEMPROOT_TYPE=`echo $TEMPROOT_TYPE | tr [:upper:] [:lower:]`
1037     INSTALLED_TYPE=`echo $INSTALLED_TYPE | tr [:upper:] [:lower:]`
1038
1039     echo "*** The installed file ${DESTDIR}${COMPFILE#.} has the type \"$INSTALLED_TYPE\""
1040     echo "    but the new version has the type \"$TEMPROOT_TYPE\""
1041     echo ''
1042     echo "    How would you like to handle this?"
1043     echo ''
1044     echo "    Use 'r' to remove ${DESTDIR}${COMPFILE#.}"
1045     case "$TEMPROOT_TYPE" in
1046     'symbolic link')
1047         TARGET=`readlink $COMPFILE`
1048         echo "    and create a link to $TARGET in its place" ;;
1049     *)  echo "    You will be able to install it as a \"$TEMPROOT_TYPE\"" ;;
1050     esac
1051     echo ''
1052     echo "    Use 'i' to ignore this"
1053     echo ''
1054     echo -n "    How to proceed? [i] "
1055     read ANSWER
1056     case "$ANSWER" in
1057     [rR])       case "${PRESERVE_FILES}" in
1058                 [Yy][Ee][Ss])
1059                 mv ${DESTDIR}${COMPFILE#.} ${PRESERVE_FILES_DIR}/ || exit 1 ;;
1060                 *) rm -rf ${DESTDIR}${COMPFILE#.} ;;
1061                 esac
1062                 case "$TEMPROOT_TYPE" in
1063                 'symbolic link') ln -sf $TARGET ${DESTDIR}${COMPFILE#.} ;;
1064                 esac ;;
1065     *)  echo ''
1066         echo "*** See the man page about adding ${COMPFILE#.} to the list of IGNORE_FILES"
1067         press_to_continue ;;
1068     esac
1069     echo ''
1070   fi
1071 done
1072
1073 for COMPFILE in `find . -type f | sort`; do
1074
1075   # First, check to see if the file exists in DESTDIR.  If not, the
1076   # diff_loop function knows how to handle it.
1077   #
1078   if [ ! -e "${DESTDIR}${COMPFILE#.}" ]; then
1079     case "${AUTO_RUN}" in
1080       '')
1081         diff_loop
1082         ;;
1083       *)
1084         case "${AUTO_INSTALL}" in
1085         '')
1086           # If this is an auto run, make it official
1087           echo "   *** ${COMPFILE} will remain for your consideration"
1088           ;;
1089         *)
1090           diff_loop
1091           ;;
1092         esac
1093         ;;
1094     esac # Auto run test
1095     continue
1096   fi
1097
1098   case "${STRICT}" in
1099   '' | [Nn][Oo])
1100     # Compare CVS $Id's first so if the file hasn't been modified
1101     # local changes will be ignored.
1102     # If the files have the same $Id, delete the one in temproot so the
1103     # user will have less to wade through if files are left to merge by hand.
1104     #
1105     CVSID1=`grep "[$]${CVS_ID_TAG}:" ${DESTDIR}${COMPFILE#.} 2>/dev/null`
1106     CVSID2=`grep "[$]${CVS_ID_TAG}:" ${COMPFILE} 2>/dev/null` || CVSID2=none
1107
1108     case "${CVSID2}" in
1109     "${CVSID1}")
1110       echo " *** Temp ${COMPFILE} and installed have the same CVS Id, deleting"
1111       rm "${COMPFILE}"
1112       ;;
1113     esac
1114     ;;
1115   esac
1116
1117   # If the file is still here either because the $Ids are different, the
1118   # file doesn't have an $Id, or we're using STRICT mode; look at the diff.
1119   #
1120   if [ -f "${COMPFILE}" ]; then
1121
1122     # Do an absolute diff first to see if the files are actually different.
1123     # If they're not different, delete the one in temproot.
1124     #
1125     if diff -q ${DIFF_OPTIONS} "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" > \
1126       /dev/null 2>&1; then
1127       echo " *** Temp ${COMPFILE} and installed are the same, deleting"
1128       rm "${COMPFILE}"
1129     else
1130       # Ok, the files are different, so show the user where they differ.
1131       # Use user's choice of diff methods; and user's pager if they have one.
1132       # Use more if not.
1133       # Use unified diffs by default.  Context diffs give me a headache. :)
1134       #
1135       # If the user chose the -F option, test for that before proceeding
1136       #
1137       if [ -n "$FREEBSD_ID" ]; then
1138         if diff -q -I'[$]FreeBSD.*[$]' "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" > \
1139             /dev/null 2>&1; then
1140           if mm_install "${COMPFILE}"; then
1141             echo "*** Updated revision control Id for ${DESTDIR}${COMPFILE#.}"
1142           else
1143             echo "*** Problem installing ${COMPFILE}, it will remain to merge by hand later"
1144           fi
1145           continue
1146         fi
1147       fi
1148       case "${AUTO_RUN}" in
1149       '')
1150         # prompt user to install/delete/merge changes
1151         diff_loop
1152         ;;
1153       *)
1154         # If this is an auto run, make it official
1155         echo "   *** ${COMPFILE} will remain for your consideration"
1156         ;;
1157       esac # Auto run test
1158     fi # Yes, the files are different
1159   fi # Yes, the file still remains to be checked
1160 done # This is for the for way up there at the beginning of the comparison
1161
1162 echo ''
1163 echo "*** Comparison complete"
1164
1165 if [ -s "${MTREENEW}" ]; then
1166   echo "*** Saving mtree database for future upgrades"
1167   test -e "${MTREEFILE}" && unlink ${MTREEFILE}
1168   mv ${MTREENEW} ${MTREEFILE}
1169 fi
1170
1171 echo ''
1172
1173 TEST_FOR_FILES=`find ${TEMPROOT} -type f -size +0 2>/dev/null`
1174 if [ -n "${TEST_FOR_FILES}" ]; then
1175   echo "*** Files that remain for you to merge by hand:"
1176   find "${TEMPROOT}" -type f -size +0 | sort
1177   echo ''
1178
1179   case "${AUTO_RUN}" in
1180   '')
1181     echo -n "Do you wish to delete what is left of ${TEMPROOT}? [no] "
1182     read DEL_TEMPROOT
1183     case "${DEL_TEMPROOT}" in
1184     [yY]*)
1185       delete_temproot
1186       ;;
1187     *)
1188       echo " *** ${TEMPROOT} will remain"
1189       ;;
1190     esac
1191     ;;
1192   *) ;;
1193   esac
1194 else
1195   echo "*** ${TEMPROOT} is empty, deleting"
1196   delete_temproot
1197 fi
1198
1199 case "${AUTO_INSTALLED_FILES}" in
1200 '') ;;
1201 *)
1202   case "${AUTO_RUN}" in
1203   '')
1204     (
1205       echo ''
1206       echo '*** You chose the automatic install option for files that did not'
1207       echo '    exist on your system.  The following were installed for you:'
1208       echo "${AUTO_INSTALLED_FILES}"
1209     ) | ${PAGER}
1210     ;;
1211   *)
1212     echo ''
1213     echo '*** You chose the automatic install option for files that did not'
1214     echo '    exist on your system.  The following were installed for you:'
1215     echo "${AUTO_INSTALLED_FILES}"
1216     ;;
1217   esac
1218   ;;
1219 esac
1220
1221 case "${AUTO_UPGRADED_FILES}" in
1222 '') ;;
1223 *)
1224   case "${AUTO_RUN}" in
1225   '')
1226     (
1227       echo ''
1228       echo '*** You chose the automatic upgrade option for files that you did'
1229       echo '    not alter on your system.  The following were upgraded for you:'
1230       echo "${AUTO_UPGRADED_FILES}"
1231     ) | ${PAGER}
1232     ;;
1233   *)
1234     echo ''
1235     echo '*** You chose the automatic upgrade option for files that you did'
1236     echo '    not alter on your system.  The following were upgraded for you:'
1237     echo "${AUTO_UPGRADED_FILES}"
1238     ;;
1239   esac
1240   ;;
1241 esac
1242
1243 run_it_now () {
1244   [ -n "$AUTO_RUN" ] && return
1245
1246   local answer
1247
1248   echo ''
1249   while : ; do
1250     if [ "$RUN_UPDATES" = always ]; then
1251       answer=y
1252     elif [ "$RUN_UPDATES" = never ]; then
1253       answer=n
1254     else
1255       echo -n '    Would you like to run it now? y or n [n] '
1256       read answer
1257     fi
1258
1259     case "$answer" in
1260     y)
1261       echo "    Running ${1}"
1262       echo ''
1263       eval "${1}"
1264       return
1265       ;;
1266     ''|n)
1267       if [ ! "$RUN_UPDATES" = never ]; then
1268         echo ''
1269         echo "       *** Cancelled"
1270         echo ''
1271       fi
1272       echo "    Make sure to run ${1} yourself"
1273       return
1274       ;;
1275     *)
1276       echo ''
1277       echo "       *** Sorry, I do not understand your answer (${answer})"
1278       echo ''
1279     esac
1280   done
1281 }
1282
1283 case "${NEED_NEWALIASES}" in
1284 '') ;;
1285 *)
1286   echo ''
1287   if [ -n "${DESTDIR}" ]; then
1288     echo "*** You installed a new aliases file into ${DESTDIR}/etc/mail, but"
1289     echo "    the newaliases command is limited to the directories configured"
1290     echo "    in sendmail.cf.  Make sure to create your aliases database by"
1291     echo "    hand when your sendmail configuration is done."
1292   else
1293     echo "*** You installed a new aliases file, so make sure that you run"
1294     echo "    '/usr/bin/newaliases' to rebuild your aliases database"
1295     run_it_now '/usr/bin/newaliases'
1296   fi
1297   ;;
1298 esac
1299
1300 case "${NEED_CAP_MKDB}" in
1301 '') ;;
1302 *)
1303   echo ''
1304   echo "*** You installed a login.conf file, so make sure that you run"
1305   echo "    '/usr/bin/cap_mkdb ${DESTDIR}/etc/login.conf'"
1306   echo "     to rebuild your login.conf database"
1307   run_it_now "/usr/bin/cap_mkdb ${DESTDIR}/etc/login.conf"
1308   ;;
1309 esac
1310
1311 case "${NEED_SERVICES_MKDB}" in
1312 '') ;;
1313 *)
1314   echo ''
1315   echo "*** You installed a services file, so make sure that you run"
1316   echo "    '/usr/sbin/services_mkdb -q -o ${DESTDIR}/var/db/services.db ${DESTDIR}/etc/services'"
1317   echo "     to rebuild your services database"
1318   run_it_now "/usr/sbin/services_mkdb -q -o ${DESTDIR}/var/db/services.db ${DESTDIR}/etc/services"
1319   ;;
1320 esac
1321
1322 case "${NEED_PWD_MKDB}" in
1323 '') ;;
1324 *)
1325   echo ''
1326   echo "*** You installed a new master.passwd file, so make sure that you run"
1327   if [ -n "${DESTDIR}" ]; then
1328     echo "    '/usr/sbin/pwd_mkdb -d ${DESTDIR}/etc -p ${DESTDIR}/etc/master.passwd'"
1329     echo "    to rebuild your password files"
1330     run_it_now "/usr/sbin/pwd_mkdb -d ${DESTDIR}/etc -p ${DESTDIR}/etc/master.passwd"
1331   else
1332     echo "    '/usr/sbin/pwd_mkdb -p /etc/master.passwd'"
1333     echo "     to rebuild your password files"
1334     run_it_now '/usr/sbin/pwd_mkdb -p /etc/master.passwd'
1335   fi
1336   ;;
1337 esac
1338
1339 if [ -e "${DESTDIR}/etc/localtime" ]; then      # Ignore if TZ == UTC
1340   echo ''
1341   [ -n "${DESTDIR}" ] && tzs_args="-C ${DESTDIR}"
1342   if [ -f "${DESTDIR}/var/db/zoneinfo" ]; then
1343     echo "*** Reinstalling `cat ${DESTDIR}/var/db/zoneinfo` as ${DESTDIR}/etc/localtime"
1344     tzsetup $tzs_args -r
1345   else
1346     echo "*** There is no ${DESTDIR}/var/db/zoneinfo file to update ${DESTDIR}/etc/localtime."
1347     echo '    You should run tzsetup'
1348     run_it_now "tzsetup $tzs_args"
1349   fi
1350 fi
1351
1352 echo ''
1353
1354 if [ -r "${MM_EXIT_SCRIPT}" ]; then
1355   . "${MM_EXIT_SCRIPT}"
1356 fi
1357
1358 case "${COMP_CONFS}" in
1359 '') ;;
1360 *)
1361   . ${DESTDIR}/etc/defaults/rc.conf
1362
1363   (echo ''
1364   echo "*** Comparing conf files: ${rc_conf_files}"
1365
1366   for CONF_FILE in ${rc_conf_files}; do
1367     if [ -r "${DESTDIR}${CONF_FILE}" ]; then
1368       echo ''
1369       echo "*** From ${DESTDIR}${CONF_FILE}"
1370       echo "*** From ${DESTDIR}/etc/defaults/rc.conf"
1371
1372       for RC_CONF_VAR in `grep -i ^[a-z] ${DESTDIR}${CONF_FILE} |
1373         cut -d '=' -f 1`; do
1374         echo ''
1375         grep -w ^${RC_CONF_VAR} ${DESTDIR}${CONF_FILE}
1376         grep -w ^${RC_CONF_VAR} ${DESTDIR}/etc/defaults/rc.conf ||
1377           echo ' * No default variable with this name'
1378       done
1379     fi
1380   done) | ${PAGER}
1381   echo ''
1382   ;;
1383 esac
1384
1385 case "${PRE_WORLD}" in
1386 '') ;;
1387 *)
1388   MAKE_CONF="${SOURCEDIR}/share/examples/etc/make.conf"
1389
1390   (echo ''
1391   echo '*** Comparing make variables'
1392   echo ''
1393   echo "*** From ${DESTDIR}/etc/make.conf"
1394   echo "*** From ${MAKE_CONF}"
1395
1396   for MAKE_VAR in `grep -i ^[a-z] ${DESTDIR}/etc/make.conf | cut -d '=' -f 1`; do
1397     echo ''
1398     grep -w ^${MAKE_VAR} ${DESTDIR}/etc/make.conf
1399     grep -w ^#${MAKE_VAR} ${MAKE_CONF} ||
1400       echo ' * No example variable with this name'
1401   done) | ${PAGER}
1402   ;;
1403 esac
1404
1405 if [ -n "${PRESERVE_FILES}" ]; then
1406   find -d $PRESERVE_FILES_DIR -type d -empty -delete 2>/dev/null
1407   rmdir $PRESERVE_FILES_DIR 2>/dev/null
1408 fi
1409
1410 exit 0