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