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