]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.sbin/mergemaster/mergemaster.sh
This commit was generated by cvs2svn to compensate for changes in r98944,
[FreeBSD/FreeBSD.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-2002 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 [-scrvahipC] [-m /path]'
19   echo '         [-t /path] [-d] [-u N] [-w N] [-D /path]'
20   echo "Options:"
21   echo "  -s  Strict comparison (diff every pair of files)"
22   echo "  -c  Use context diff instead of unified diff"
23   echo "  -r  Re-run on a previously cleaned directory (skip temproot creation)"
24   echo "  -v  Be more verbose about the process, include additional checks"
25   echo "  -a  Leave all files that differ to merge by hand"
26   echo "  -h  Display more complete help"
27   echo '  -i  Automatically install files that do not exist in destination directory'
28   echo '  -p  Pre-buildworld mode, only compares crucial files'
29   echo '  -C  Compare local rc.conf variables to the defaults'
30   echo "  -m /path/directory  Specify location of source to do the make in"
31   echo "  -t /path/directory  Specify temp root directory"
32   echo "  -d  Add date and time to directory name (e.g., /var/tmp/temproot.`date +%m%d.%H.%M`)"
33   echo "  -u N  Specify a numeric umask"
34   echo "  -w N  Specify a screen width in columns to sdiff"
35   echo '  -D /path/directory  Specify the destination directory to install files to'
36   echo ''
37 }
38
39 display_help () {
40   echo "* To specify a directory other than /var/tmp/temproot for the"
41   echo "  temporary root environment, use -t /path/to/temp/root"
42   echo "* The -w option takes a number as an argument for the column width"
43   echo "  of the screen.  The default is 80."
44   echo '* The -a option causes mergemaster to run without prompting.'
45 }
46
47 # Loop allowing the user to use sdiff to merge files and display the merged
48 # file.
49 merge_loop () {
50   case "${VERBOSE}" in
51   '') ;;
52   *)
53       echo "   *** Type h at the sdiff prompt (%) to get usage help"
54       ;;
55   esac
56   echo ''
57   MERGE_AGAIN=yes
58   while [ "${MERGE_AGAIN}" = "yes" ]; do
59     # Prime file.merged so we don't blat the owner/group id's
60     cp -p "${COMPFILE}" "${COMPFILE}.merged"
61     sdiff -o "${COMPFILE}.merged" --text --suppress-common-lines \
62       --width=${SCREEN_WIDTH:-80} "${DESTDIR}${COMPFILE#.}" "${COMPFILE}"
63     INSTALL_MERGED=V
64     while [ "${INSTALL_MERGED}" = "v" -o "${INSTALL_MERGED}" = "V" ]; do
65       echo ''
66       echo "  Use 'i' to install merged file"
67       echo "  Use 'r' to re-do the merge"
68       echo "  Use 'v' to view the merged file"
69       echo "  Default is to leave the temporary file to deal with by hand"
70       echo ''
71       echo -n "    *** How should I deal with the merged file? [Leave it for later] "
72       read INSTALL_MERGED
73
74       case "${INSTALL_MERGED}" in
75       [iI])
76         mv "${COMPFILE}.merged" "${COMPFILE}"
77         echo ''
78         if mm_install "${COMPFILE}"; then
79           echo "     *** Merged version of ${COMPFILE} installed successfully"
80         else
81           echo "     *** Problem installing ${COMPFILE}, it will remain to merge by hand later"
82         fi
83         unset MERGE_AGAIN
84         ;;
85       [rR])
86         rm "${COMPFILE}.merged"
87         ;;
88       [vV])
89         ${PAGER} "${COMPFILE}.merged"
90         ;;
91       '')
92         echo "   *** ${COMPFILE} will remain for your consideration"
93         unset MERGE_AGAIN
94         ;;
95       *)
96         echo "invalid choice: ${INSTALL_MERGED}"
97         INSTALL_MERGED=V
98         ;;
99       esac
100     done
101   done
102 }
103
104 # Loop showing user differences between files, allow merge, skip or install
105 # options
106 diff_loop () {
107
108   HANDLE_COMPFILE=v
109
110   while [ "${HANDLE_COMPFILE}" = "v" -o "${HANDLE_COMPFILE}" = "V" -o \
111     "${HANDLE_COMPFILE}" = "NOT V" ]; do
112     if [ -f "${DESTDIR}${COMPFILE#.}" -a -f "${COMPFILE}" ]; then
113       if [ "${HANDLE_COMPFILE}" = "v" -o "${HANDLE_COMPFILE}" = "V" ]; then
114         echo ''
115         echo '   ======================================================================   '
116         echo ''
117         (
118           echo ''
119           echo "  *** Displaying differences between ${COMPFILE} and installed version:"
120           echo ''
121           diff "${DIFF_FLAG}" "${DESTDIR}${COMPFILE#.}" "${COMPFILE}"
122         ) | ${PAGER}
123         echo ''
124       fi
125     else
126       echo ''
127       echo "  *** There is no installed version of ${COMPFILE}"
128       echo ''
129       case "${AUTO_INSTALL}" in
130       [Yy][Ee][Ss])
131         echo ''
132         if mm_install "${COMPFILE}"; then
133           echo "   *** ${COMPFILE} installed successfully"
134           echo ''
135           # Make the list print one file per line
136           AUTO_INSTALLED_FILES="${AUTO_INSTALLED_FILES}      ${DESTDIR}${COMPFILE#.}
137 "
138         else
139           echo "   *** Problem installing ${COMPFILE}, it will remain to merge by hand"
140         fi
141         return
142         ;;
143       *)
144         NO_INSTALLED=yes
145         ;;
146       esac
147     fi
148
149     echo "  Use 'd' to delete the temporary ${COMPFILE}"
150     echo "  Use 'i' to install the temporary ${COMPFILE}"
151     case "${NO_INSTALLED}" in
152     '')
153       echo "  Use 'm' to merge the temporary and installed versions"
154       echo "  Use 'v' to view the diff results again"
155       ;;
156     esac
157     echo ''
158     echo "  Default is to leave the temporary file to deal with by hand"
159     echo ''
160     echo -n "How should I deal with this? [Leave it for later] "
161     read HANDLE_COMPFILE
162
163     case "${HANDLE_COMPFILE}" in
164     [dD])
165       rm "${COMPFILE}"
166       echo ''
167       echo "   *** Deleting ${COMPFILE}"
168       ;;
169     [iI])
170       echo ''
171       if mm_install "${COMPFILE}"; then
172         echo "   *** ${COMPFILE} installed successfully"
173       else
174         echo "   *** Problem installing ${COMPFILE}, it will remain to merge by hand"
175       fi
176       ;;
177     [mM])
178       case "${NO_INSTALLED}" in
179       '')
180         # interact with user to merge files
181         merge_loop
182         ;;
183       *)
184         echo ''
185         echo "   *** There is no installed version of ${COMPFILE}"
186         echo ''
187         HANDLE_COMPFILE="NOT V"
188         ;;
189       esac # End of "No installed version of file but user selected merge" test
190       ;;
191     [vV])
192       continue
193       ;;
194     '')
195       echo ''
196       echo "   *** ${COMPFILE} will remain for your consideration"
197       ;;
198     *)
199       # invalid choice, show menu again.
200       echo "invalid choice: ${HANDLE_COMPFILE}"
201       echo ''
202       HANDLE_COMPFILE="NOT V"
203       continue
204       ;;
205     esac  # End of "How to handle files that are different"
206   done
207   unset NO_INSTALLED
208   echo ''
209   case "${VERBOSE}" in
210   '') ;;
211   *)
212     sleep 3
213     ;;
214   esac
215 }
216
217 press_to_continue () {
218   local DISCARD
219   echo -n ' *** Press the [Enter] or [Return] key to continue '
220   read DISCARD
221 }
222
223 # Set the default path for the temporary root environment
224 #
225 TEMPROOT='/var/tmp/temproot'
226
227 # Read /etc/mergemaster.rc first so the one in $HOME can override
228 #
229 if [ -r /etc/mergemaster.rc ]; then
230   . /etc/mergemaster.rc
231 fi
232
233 # Read .mergemasterrc before command line so CLI can override
234 #
235 if [ -r "$HOME/.mergemasterrc" ]; then
236   . "$HOME/.mergemasterrc"
237 fi
238
239 # Check the command line options
240 #
241 while getopts ":ascrvhipCm:t:du:w:D:" COMMAND_LINE_ARGUMENT ; do
242   case "${COMMAND_LINE_ARGUMENT}" in
243   s)
244     STRICT=yes
245     ;;
246   c)
247     DIFF_FLAG='-c'
248     ;;
249   r)
250     RERUN=yes
251     ;;
252   v)
253     case "${AUTO_RUN}" in
254     '') VERBOSE=yes ;;
255     esac
256     ;;
257   a)
258     AUTO_RUN=yes
259     unset VERBOSE
260     ;;
261   h)
262     display_usage
263     display_help
264     exit 0
265     ;;
266   i)
267     AUTO_INSTALL=yes
268     ;;
269   C)
270     COMP_CONFS=yes
271     ;;
272   p)
273     PRE_WORLD=yes
274     unset COMP_CONFS
275     unset AUTO_RUN
276     ;;
277   m)
278     SOURCEDIR=${OPTARG}
279     ;;
280   t)
281     TEMPROOT=${OPTARG}
282     ;;
283   d)
284     TEMPROOT=${TEMPROOT}.`date +%m%d.%H.%M`
285     ;;
286   u)
287     NEW_UMASK=${OPTARG}
288     ;;
289   w)
290     SCREEN_WIDTH=${OPTARG}
291     ;;
292   D)
293     DESTDIR=${OPTARG}
294     ;;
295   *)
296     display_usage
297     exit 1
298     ;;
299   esac
300 done
301
302 echo ''
303
304 # If the user has a pager defined, make sure we can run it
305 #
306 case "${DONT_CHECK_PAGER}" in
307 '')
308   while ! type "${PAGER%% *}" >/dev/null && [ -n "${PAGER}" ]; do
309     echo " *** Your PAGER environment variable specifies '${PAGER}', but"
310     echo "     due to the limited PATH that I use for security reasons,"
311     echo "     I cannot execute it.  So, what would you like to do?"
312     echo ''
313     echo "  Use 'e' to exit mergemaster and fix your PAGER variable"
314     if [ -x /usr/bin/less -o -x /usr/local/bin/less ]; then
315     echo "  Use 'l' to set PAGER to 'less' for this run"
316     fi
317     echo "  Use 'm' to use plain old 'more' as your PAGER for this run"
318     echo ''
319     echo "  Default is to use plain old 'more' "
320     echo ''
321     echo -n "What should I do? [Use 'more'] "
322     read FIXPAGER
323
324     case "${FIXPAGER}" in
325     [eE])
326        exit 0
327        ;;
328     [lL])
329        if [ -x /usr/bin/less ]; then
330          PAGER=/usr/bin/less
331        elif [ -x /usr/local/bin/less ]; then
332          PAGER=/usr/local/bin/less
333        else
334          echo ''
335          echo " *** Fatal Error:"
336          echo "     You asked to use 'less' as your pager, but I can't"
337          echo "     find it in /usr/bin or /usr/local/bin"
338          exit 1
339        fi
340        ;;
341     [mM]|'')
342        PAGER=more
343        ;;
344     *)
345        echo ''
346        echo "invalid choice: ${FIXPAGER}"
347     esac
348     echo ''
349   done
350   ;;
351 esac
352
353 # If user has a pager defined, or got assigned one above, use it.
354 # If not, use more.
355 #
356 PAGER=${PAGER:-more}
357
358 if [ -n "${VERBOSE}" -a ! "${PAGER}" = "more" ]; then
359   echo " *** You have ${PAGER} defined as your pager so we will use that"
360   echo ''
361   sleep 3
362 fi
363
364 # Assign the diff flag once so we will not have to keep testing it
365 #
366 DIFF_FLAG=${DIFF_FLAG:--u}
367
368 # Assign the source directory
369 #
370 SOURCEDIR=${SOURCEDIR:-/usr/src/etc}
371
372 # Check the width of the user's terminal
373 #
374 if [ -t 0 ]; then
375   w=$(stty -a | sed -ne 's/.* \([0-9][0-9]*\) columns.*/\1/p')
376   case "${w}" in
377   0|'') ;; # No-op, since the input is not valid
378   *)
379     case "${SCREEN_WIDTH}" in
380     '') SCREEN_WIDTH="${w}" ;;
381     "${w}") ;; # No-op, since they are the same
382     *)
383       echo -n "*** You entered ${SCREEN_WIDTH} as your screen width, but stty "
384       echo "thinks it is ${w}."
385       echo ''
386       echo -n "What would you like to use? [${w}] "
387       read SCREEN_WIDTH
388       case "${SCREEN_WIDTH}" in
389       '') SCREEN_WIDTH="${w}" ;;
390       esac
391       ;;
392     esac
393   esac
394 fi
395
396 # Define what CVS $Id tag to look for to aid portability.
397 #
398 CVS_ID_TAG=FreeBSD
399
400 case "${RERUN}" in
401 '')
402   # Set up the loop to test for the existence of the
403   # temp root directory.
404   #
405   TEST_TEMP_ROOT=yes
406   while [ "${TEST_TEMP_ROOT}" = "yes" ]; do
407     if [ -d "${TEMPROOT}" ]; then
408       echo "*** The directory specified for the temporary root environment,"
409       echo "    ${TEMPROOT}, exists.  This can be a security risk if untrusted"
410       echo "    users have access to the system."
411       echo ''
412       case "${AUTO_RUN}" in
413       '')
414         echo "  Use 'd' to delete the old ${TEMPROOT} and continue"
415         echo "  Use 't' to select a new temporary root directory"
416         echo "  Use 'e' to exit mergemaster"
417         echo ''
418         echo "  Default is to use ${TEMPROOT} as is"
419         echo ''
420         echo -n "How should I deal with this? [Use the existing ${TEMPROOT}] "
421         read DELORNOT
422
423         case "${DELORNOT}" in
424         [dD])
425           echo ''
426           echo "   *** Deleting the old ${TEMPROOT}"
427           echo ''
428           chflags -R noschg "${TEMPROOT}"
429           rm -rf "${TEMPROOT}"
430           unset TEST_TEMP_ROOT
431           ;;
432         [tT])
433           echo "   *** Enter new directory name for temporary root environment"
434           read TEMPROOT
435           ;;
436         [eE])
437           exit 0
438           ;;
439         '')
440           echo ''
441           echo "   *** Leaving ${TEMPROOT} intact"
442           echo ''
443           unset TEST_TEMP_ROOT
444           ;;
445         *)
446           echo ''
447           echo "invalid choice: ${DELORNOT}"
448           echo ''
449           ;;
450         esac
451         ;;
452       *)
453         # If this is an auto-run, try a hopefully safe alternative then
454         # re-test anyway.
455         TEMPROOT=/var/tmp/temproot.`date +%m%d.%H.%M.%S`
456         ;;
457       esac
458     else
459       unset TEST_TEMP_ROOT
460     fi
461   done
462
463   echo "*** Creating the temporary root environment in ${TEMPROOT}"
464
465   if mkdir -p "${TEMPROOT}"; then
466     echo " *** ${TEMPROOT} ready for use"
467   fi
468
469   if [ ! -d "${TEMPROOT}" ]; then
470     echo ''
471     echo "  *** FATAL ERROR: Cannot create ${TEMPROOT}"
472     echo ''
473     exit 1
474   fi
475
476   echo " *** Creating and populating directory structure in ${TEMPROOT}"
477   echo ''
478
479   case "${VERBOSE}" in
480   '') ;;
481   *)
482     press_to_continue
483     ;;
484   esac
485
486   case "${PRE_WORLD}" in
487   '')
488     { cd ${SOURCEDIR} &&
489       case "${DESTDIR}" in
490       '') ;;
491       *)
492       make DESTDIR=${DESTDIR} distrib-dirs
493         ;;
494       esac
495       make DESTDIR=${TEMPROOT} distrib-dirs &&
496       make MAKEOBJDIRPREFIX=${TEMPROOT}/usr/obj obj &&
497       make MAKEOBJDIRPREFIX=${TEMPROOT}/usr/obj DESTDIR=${TEMPROOT} \
498           -DNO_MAKEDEV_RUN distribution;} ||
499     { echo '';
500      echo "  *** FATAL ERROR: Cannot 'cd' to ${SOURCEDIR} and install files to";
501       echo "      the temproot environment";
502       echo '';
503       exit 1;}
504     ;;
505   *)
506     # Only set up files that are crucial to {build|install}world
507     { mkdir -p ${TEMPROOT}/etc &&
508       cp -p ${SOURCEDIR}/master.passwd ${TEMPROOT}/etc &&
509       cp -p ${SOURCEDIR}/group ${TEMPROOT}/etc;} ||
510     { echo '';
511       echo '  *** FATAL ERROR: Cannot copy files to the temproot environment';
512       echo '';
513       exit 1;}
514     ;;
515   esac
516
517   # Doing the inventory and removing files that we don't want to compare only
518   # makes sense if we are not doing a rerun, since we have no way of knowing
519   # what happened to the files during previous incarnations.
520   case "${VERBOSE}" in
521   '') ;;
522   *)
523     echo ''
524     echo ' *** The following files exist only in the installed version of'
525     echo "     ${DESTDIR}/etc.  In the vast majority of cases these files"
526     echo '     are necessary parts of the system and should not be deleted.'
527     echo '     However because these files are not updated by this process you'
528     echo '     might want to verify their status before rebooting your system.'
529     echo ''
530     press_to_continue
531     diff -qr ${DESTDIR}/etc ${TEMPROOT}/etc | grep "^Only in /etc" | ${PAGER}
532     echo ''
533     press_to_continue
534     ;;
535   esac
536
537   # Avoid comparing the motd if the user specifies it in .mergemasterrc
538   case "${IGNORE_MOTD}" in
539   '') ;;
540   *) rm -f ${TEMPROOT}/etc/motd
541      ;;
542   esac
543
544   # Avoid trying to update MAKEDEV if /dev is on a devfs
545   if /sbin/sysctl vfs.devfs.generation > /dev/null 2>&1 ; then
546     rm -f ${TEMPROOT}/dev/MAKEDEV ${TEMPROOT}/dev/MAKEDEV.local
547   fi
548
549   ;; # End of the "RERUN" test
550 esac
551
552 # We really don't want to have to deal with these files, since
553 # master.passwd is the real file that should be compared, then
554 # the user should run pwd_mkdb if necessary.
555 #
556 rm -f ${TEMPROOT}/etc/spwd.db ${TEMPROOT}/etc/passwd ${TEMPROOT}/etc/pwd.db
557
558 # We only need to compare things like freebsd.cf once
559 find ${TEMPROOT}/usr/obj -type f -delete 2>/dev/null
560
561 # Get ready to start comparing files
562
563 # Check umask if not specified on the command line,
564 # and we are not doing an autorun
565 #
566 if [ -z "${NEW_UMASK}" -a -z "${AUTO_RUN}" ]; then
567   USER_UMASK=`umask`
568   case "${USER_UMASK}" in
569   0022|022) ;;
570   *)
571     echo ''
572     echo " *** Your umask is currently set to ${USER_UMASK}.  By default, this script"
573     echo "     installs all files with the same user, group and modes that"
574     echo "     they are created with by ${SOURCEDIR}/Makefile, compared to"
575     echo "     a umask of 022.  This umask allows world read permission when"
576     echo "     the file's default permissions have it."
577     echo ''
578     echo "     No world permissions can sometimes cause problems.  A umask of"
579     echo "     022 will restore the default behavior, but is not mandatory."
580     echo "     /etc/master.passwd is a special case.  Its file permissions"
581     echo "     will be 600 (rw-------) if installed."
582     echo ''
583     echo -n "What umask should I use? [${USER_UMASK}] "
584     read NEW_UMASK
585
586     NEW_UMASK="${NEW_UMASK:-$USER_UMASK}"
587     ;;
588   esac
589   echo ''
590 fi
591
592 CONFIRMED_UMASK=${NEW_UMASK:-0022}
593
594 # Warn users who still have ${DESTDIR}/etc/sysconfig
595 #
596 if [ -e "${DESTDIR}/etc/sysconfig" ]; then
597   echo ''
598   echo " *** There is a sysconfig file on this system in ${DESTDIR}/etc/."
599   echo ''
600   echo '     Starting with FreeBSD version 2.2.2 those settings moved from'
601   echo '     /etc/sysconfig to /etc/rc.conf.  If you are upgrading an older'
602   echo '     system make sure that you transfer your settings by hand from'
603   echo '     sysconfig to rc.conf and install the rc.conf file.  If you'
604   echo '     have already made this transition, you should consider'
605   echo '     renaming or deleting the sysconfig file.'
606   echo ''
607   case "${AUTO_RUN}" in
608   '')
609     echo -n "Continue with the merge process? [yes] "
610     read CONT_OR_NOT
611
612     case "${CONT_OR_NOT}" in
613     [nN]*)
614       exit 0
615       ;;
616     *)
617       echo "   *** Continuing"
618       echo ''
619       ;;
620     esac
621     ;;
622   *) ;;
623   esac
624 fi
625
626 # Use the umask/mode information to install the files
627 # Create directories as needed
628 #
629 do_install_and_rm () {
630   install -m "${1}" "${2}" "${3}" &&
631   rm -f "${2}"
632 }
633
634 # 4095 = "obase=10;ibase=8;07777" | bc
635 find_mode () {
636   local OCTAL
637   OCTAL=$(( ~$(echo "obase=10; ibase=8; ${CONFIRMED_UMASK}" | bc) & 4095 &
638     $(echo "obase=10; ibase=8; $(stat -f "%OMp%OLp" ${1})" | bc) )) 
639   printf "%04o\n" ${OCTAL}
640 }
641
642 mm_install () {
643   local INSTALL_DIR
644   INSTALL_DIR=${1#.}
645   INSTALL_DIR=${INSTALL_DIR%/*}
646
647   case "${INSTALL_DIR}" in
648   '')
649     INSTALL_DIR=/
650     ;;
651   esac
652
653   if [ -n "${DESTDIR}${INSTALL_DIR}" -a ! -d "${DESTDIR}${INSTALL_DIR}" ]; then
654     DIR_MODE=`find_mode "${TEMPROOT}/${INSTALL_DIR}"`
655     install -d -o root -g wheel -m "${DIR_MODE}" "${DESTDIR}${INSTALL_DIR}"
656   fi
657
658   FILE_MODE=`find_mode "${1}"`
659
660   if [ ! -x "${1}" ]; then
661     case "${1#.}" in
662     /etc/mail/aliases)
663       NEED_NEWALIASES=yes
664       ;;
665     /etc/login.conf)
666       NEED_CAP_MKDB=yes
667       ;;
668     /etc/master.passwd)
669       do_install_and_rm 600 "${1}" "${DESTDIR}${INSTALL_DIR}"
670       NEED_PWD_MKDB=yes
671       DONT_INSTALL=yes
672       ;;
673     /.cshrc | /.profile)
674     case "${AUTO_INSTALL}" in
675     '')
676       case "${LINK_EXPLAINED}" in
677       '')
678         echo "   *** Historically BSD derived systems have had a"
679         echo "       hard link from /.cshrc and /.profile to"
680         echo "       their namesakes in /root.  Please indicate"
681         echo "       your preference below for bringing your"
682         echo "       installed files up to date."
683         echo ''
684         LINK_EXPLAINED=yes
685         ;;
686       esac
687
688       echo "   Use 'd' to delete the temporary ${COMPFILE}"
689       echo "   Use 'l' to delete the existing ${DESTDIR}${COMPFILE#.} and create the link"
690       echo ''
691       echo "   Default is to leave the temporary file to deal with by hand"
692       echo ''
693       echo -n "  How should I handle ${COMPFILE}? [Leave it to install later] "
694       read HANDLE_LINK
695       ;;
696     *)  # Part of AUTO_INSTALL
697       HANDLE_LINK=l
698       ;;
699     esac
700
701       case "${HANDLE_LINK}" in
702       [dD]*)
703         rm "${COMPFILE}"
704         echo ''
705         echo "   *** Deleting ${COMPFILE}"
706         ;;
707       [lL]*)
708         echo ''
709         rm -f "${DESTDIR}${COMPFILE#.}"
710         if ln "${DESTDIR}/root/${COMPFILE##*/}" "${DESTDIR}${COMPFILE#.}"; then
711           echo "   *** Link from ${DESTDIR}${COMPFILE#.} to ${DESTDIR}/root/${COMPFILE##*/} installed successfully"
712           rm "${COMPFILE}"
713         else
714           echo "   *** Error linking ${DESTDIR}${COMPFILE#.} to ${DESTDIR}/root/${COMPFILE##*/}, ${COMPFILE} will remain to install by hand"
715         fi
716         ;;
717       *)
718         echo "   *** ${COMPFILE} will remain for your consideration"
719         ;;
720       esac
721       DONT_INSTALL=yes
722       ;;
723     esac
724
725     case "${DONT_INSTALL}" in
726     '')
727       do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}"
728       ;;
729     *)
730       unset DONT_INSTALL
731       ;;
732     esac
733   else  # File matched -x
734     case "${1#.}" in
735     /dev/MAKEDEV)
736       NEED_MAKEDEV=yes
737       ;;
738     esac
739     do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}"
740   fi
741   return $?
742 }
743
744 echo ''
745 echo "*** Beginning comparison"
746 echo ''
747
748 cd "${TEMPROOT}"
749
750 if [ -r "${MM_PRE_COMPARE_SCRIPT}" ]; then
751   . "${MM_PRE_COMPARE_SCRIPT}"
752 fi
753
754 # Using -size +0 avoids uselessly checking the empty log files created
755 # by ${SOURCEDIR}/Makefile and the device entries in ./dev, but does
756 # check the scripts in ./dev, as we'd like (assuming no devfs of course).
757 #
758 for COMPFILE in `find . -type f -size +0`; do
759
760   # First, check to see if the file exists in DESTDIR.  If not, the
761   # diff_loop function knows how to handle it.
762   #
763   if [ ! -e "${DESTDIR}${COMPFILE#.}" ]; then
764     case "${AUTO_RUN}" in
765       '')
766         diff_loop
767         ;;
768       *)
769         case "${AUTO_INSTALL}" in
770         '')
771           # If this is an auto run, make it official
772           echo "   *** ${COMPFILE} will remain for your consideration"
773           ;;
774         *)
775           diff_loop
776           ;;
777         esac
778         ;;
779     esac # Auto run test
780     continue
781   fi
782
783   case "${STRICT}" in
784   '' | [Nn][Oo])
785     # Compare CVS $Id's first so if the file hasn't been modified
786     # local changes will be ignored.
787     # If the files have the same $Id, delete the one in temproot so the
788     # user will have less to wade through if files are left to merge by hand.
789     #
790     CVSID1=`grep "[$]${CVS_ID_TAG}:" ${DESTDIR}${COMPFILE#.} 2>/dev/null`
791     CVSID2=`grep "[$]${CVS_ID_TAG}:" ${COMPFILE} 2>/dev/null` || CVSID2=none
792
793     case "${CVSID2}" in
794     "${CVSID1}")
795       echo " *** Temp ${COMPFILE} and installed have the same CVS Id, deleting"
796       rm "${COMPFILE}"
797       ;;
798     esac
799     ;;
800   esac
801
802   # If the file is still here either because the $Ids are different, the
803   # file doesn't have an $Id, or we're using STRICT mode; look at the diff.
804   #
805   if [ -f "${COMPFILE}" ]; then
806
807     # Do an absolute diff first to see if the files are actually different.
808     # If they're not different, delete the one in temproot.
809     #
810     if diff -q "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" > /dev/null 2>&1; then
811       echo " *** Temp ${COMPFILE} and installed are the same, deleting"
812       rm "${COMPFILE}"
813     else
814       # Ok, the files are different, so show the user where they differ.
815       # Use user's choice of diff methods; and user's pager if they have one.
816       # Use more if not.
817       # Use unified diffs by default.  Context diffs give me a headache. :)
818       #
819       case "${AUTO_RUN}" in
820       '')
821         # prompt user to install/delete/merge changes
822         diff_loop
823         ;;
824       *)
825         # If this is an auto run, make it official
826         echo "   *** ${COMPFILE} will remain for your consideration"
827         ;;
828       esac # Auto run test
829     fi # Yes, the files are different
830   fi # Yes, the file still remains to be checked
831 done # This is for the do way up there at the beginning of the comparison
832
833 echo ''
834 echo "*** Comparison complete"
835 echo ''
836
837 TEST_FOR_FILES=`find ${TEMPROOT} -type f -size +0 2>/dev/null`
838 if [ -n "${TEST_FOR_FILES}" ]; then
839   echo "*** Files that remain for you to merge by hand:"
840   find "${TEMPROOT}" -type f -size +0
841   echo ''
842 fi
843
844 case "${AUTO_RUN}" in
845 '')
846   echo -n "Do you wish to delete what is left of ${TEMPROOT}? [no] "
847   read DEL_TEMPROOT
848
849   case "${DEL_TEMPROOT}" in
850   [yY]*)
851     if chflags -R noschg "${TEMPROOT}" && rm -rf "${TEMPROOT}"; then
852       echo " *** ${TEMPROOT} has been deleted"
853     else
854       echo " *** Unable to delete ${TEMPROOT}"
855     fi
856     ;;
857   *)
858     echo " *** ${TEMPROOT} will remain"
859     ;;
860   esac
861   ;;
862 *) ;;
863 esac
864
865 case "${AUTO_INSTALLED_FILES}" in
866 '') ;;
867 *)
868   case "${AUTO_RUN}" in
869   '')
870     (
871       echo ''
872       echo '*** You chose the automatic install option for files that did not'
873       echo '    exist on your system.  The following were installed for you:'
874       echo "${AUTO_INSTALLED_FILES}"
875     ) | ${PAGER}
876     ;;
877   *)
878     echo ''
879     echo '*** You chose the automatic install option for files that did not'
880     echo '    exist on your system.  The following were installed for you:'
881     echo "${AUTO_INSTALLED_FILES}"
882     ;;
883   esac
884   ;;
885 esac
886
887 run_it_now () {
888   case "${AUTO_RUN}" in
889   '')
890     unset YES_OR_NO
891     echo ''
892     echo -n '    Would you like to run it now? y or n [n] '
893     read YES_OR_NO
894
895     case "${YES_OR_NO}" in
896     y)
897       echo "    Running ${1}"
898       echo ''
899       eval "${1}"
900       ;;
901     ''|n)
902       echo ''
903       echo "       *** Cancelled"
904       echo ''
905       echo "    Make sure to run ${1} yourself"
906       ;;
907     *)
908       echo ''
909       echo "       *** Sorry, I do not understand your answer (${YES_OR_NO})"
910       echo ''
911       echo "    Make sure to run ${1} yourself"
912     esac
913     ;;
914   *) ;;
915   esac
916 }
917
918 case "${NEED_MAKEDEV}" in
919 '') ;;
920 *)
921   echo ''
922   echo "*** You installed a new ${DESTDIR}/dev/MAKEDEV script, so make sure that you run"
923   echo "    'cd ${DESTDIR}/dev && /bin/sh MAKEDEV all' to rebuild your devices"
924   run_it_now "cd ${DESTDIR}/dev && /bin/sh MAKEDEV all"
925   ;;
926 esac
927
928 case "${NEED_NEWALIASES}" in
929 '') ;;
930 *)
931   echo ''
932   if [ -n "${DESTDIR}" ]; then
933     echo "*** You installed a new aliases file into ${DESTDIR}/etc/mail, but"
934     echo "    the newaliases command is limited to the directories configured"
935     echo "    in sendmail.cf.  Make sure to create your aliases database by"
936     echo "    hand when your sendmail configuration is done."
937   else
938     echo "*** You installed a new aliases file, so make sure that you run"
939     echo "    '/usr/bin/newaliases' to rebuild your aliases database"
940     run_it_now '/usr/bin/newaliases'
941   fi
942   ;;
943 esac
944
945 case "${NEED_CAP_MKDB}" in
946 '') ;;
947 *)
948   echo ''
949   echo "*** You installed a login.conf file, so make sure that you run"
950   echo "    '/usr/bin/cap_mkdb ${DESTDIR}/etc/login.conf'"
951   echo "     to rebuild your login.conf database"
952   run_it_now "/usr/bin/cap_mkdb ${DESTDIR}/etc/login.conf"
953   ;;
954 esac
955
956 case "${NEED_PWD_MKDB}" in
957 '') ;;
958 *)
959   echo ''
960   echo "*** You installed a new master.passwd file, so make sure that you run"
961   if [ -n "${DESTDIR}" ]; then
962     echo "    '/usr/sbin/pwd_mkdb -d ${DESTDIR}/etc -p ${DESTDIR}/etc/master.passwd'"
963     echo "    to rebuild your password files"
964     run_it_now "/usr/sbin/pwd_mkdb -d ${DESTDIR}/etc -p ${DESTDIR}/etc/master.passwd"
965   else
966     echo "    '/usr/sbin/pwd_mkdb -p /etc/master.passwd'"
967     echo "     to rebuild your password files"
968     run_it_now '/usr/sbin/pwd_mkdb -p /etc/master.passwd'
969   fi
970   ;;
971 esac
972
973 echo ''
974
975 if [ -r "${MM_EXIT_SCRIPT}" ]; then
976   . "${MM_EXIT_SCRIPT}"
977 fi
978
979 case "${COMP_CONFS}" in
980 '') ;;
981 *)
982   . ${DESTDIR}/etc/defaults/rc.conf
983
984   (echo ''
985   echo "*** Comparing conf files: ${rc_conf_files}"
986
987   for CONF_FILE in ${rc_conf_files}; do
988     if [ -r "${DESTDIR}${CONF_FILE}" ]; then
989       echo ''
990       echo "*** From ${DESTDIR}${CONF_FILE}"
991       echo "*** From ${DESTDIR}/etc/defaults/rc.conf"
992
993       for RC_CONF_VAR in `grep -i ^[a-z] ${DESTDIR}${CONF_FILE} |
994         cut -d '=' -f 1`; do
995         echo ''
996         grep -w ^${RC_CONF_VAR} ${DESTDIR}${CONF_FILE}
997         grep -w ^${RC_CONF_VAR} ${DESTDIR}/etc/defaults/rc.conf ||
998           echo ' * No default variable with this name'
999       done
1000     fi
1001   done) | ${PAGER}
1002   echo ''
1003   ;;
1004 esac
1005
1006 case "${PRE_WORLD}" in
1007 '') ;;
1008 *)
1009   MAKE_CONF="${SOURCEDIR%etc}share/examples/etc/make.conf"
1010
1011   (echo ''
1012   echo '*** Comparing make variables'
1013   echo ''
1014   echo "*** From ${DESTDIR}/etc/make.conf"
1015   echo "*** From ${MAKE_CONF}"
1016
1017   for MAKE_VAR in `grep -i ^[a-z] /etc/make.conf | cut -d '=' -f 1`; do
1018     echo ''
1019     grep -w ^${MAKE_VAR} ${DESTDIR}/etc/make.conf
1020     grep -w ^#${MAKE_VAR} ${MAKE_CONF} ||
1021       echo ' * No example variable with this name'
1022   done) | ${PAGER}
1023   ;;
1024 esac
1025
1026 exit 0
1027