5 # Compare files created by /usr/src/etc/Makefile (or the directory
6 # the user specifies) with the currently installed copies.
8 # Copyright 1998-2011 Douglas Barton
13 PATH=/bin:/usr/bin:/usr/sbin
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]'
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***'
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'
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.'
53 # Loop allowing the user to use sdiff to merge files and display the merged
59 echo " *** Type h at the sdiff prompt (%) to get usage help"
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}"
70 while [ "${INSTALL_MERGED}" = "v" -o "${INSTALL_MERGED}" = "V" ]; do
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"
77 echo -n " *** How should I deal with the merged file? [Leave it for later] "
80 case "${INSTALL_MERGED}" in
82 mv "${COMPFILE}.merged" "${COMPFILE}"
84 if mm_install "${COMPFILE}"; then
85 echo " *** Merged version of ${COMPFILE} installed successfully"
87 echo " *** Problem installing ${COMPFILE}, it will remain to merge by hand later"
92 rm "${COMPFILE}.merged"
95 ${PAGER} "${COMPFILE}.merged"
98 echo " *** ${COMPFILE} will remain for your consideration"
102 echo "invalid choice: ${INSTALL_MERGED}"
110 # Loop showing user differences between files, allow merge, skip or install
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
121 *:${DESTDIR}${COMPFILE#.}:*) ;; # File has been modified
124 echo " *** ${COMPFILE} has not been user modified."
127 if mm_install "${COMPFILE}"; then
128 echo " *** ${COMPFILE} upgraded successfully"
130 # Make the list print one file per line
131 AUTO_UPGRADED_FILES="${AUTO_UPGRADED_FILES} ${DESTDIR}${COMPFILE#.}
134 echo " *** Problem upgrading ${COMPFILE}, it will remain to merge by hand"
140 if [ "${HANDLE_COMPFILE}" = "v" -o "${HANDLE_COMPFILE}" = "V" ]; then
142 echo ' ====================================================================== '
145 echo " *** Displaying differences between ${COMPFILE} and installed version:"
147 diff ${DIFF_FLAG} ${DIFF_OPTIONS} "${DESTDIR}${COMPFILE#.}" "${COMPFILE}"
153 echo " *** There is no installed version of ${COMPFILE}"
155 case "${AUTO_INSTALL}" in
158 if mm_install "${COMPFILE}"; then
159 echo " *** ${COMPFILE} installed successfully"
161 # Make the list print one file per line
162 AUTO_INSTALLED_FILES="${AUTO_INSTALLED_FILES} ${DESTDIR}${COMPFILE#.}
165 echo " *** Problem installing ${COMPFILE}, it will remain to merge by hand"
175 echo " Use 'd' to delete the temporary ${COMPFILE}"
176 echo " Use 'i' to install the temporary ${COMPFILE}"
177 case "${NO_INSTALLED}" in
179 echo " Use 'm' to merge the temporary and installed versions"
180 echo " Use 'v' to view the diff results again"
184 echo " Default is to leave the temporary file to deal with by hand"
186 echo -n "How should I deal with this? [Leave it for later] "
189 case "${HANDLE_COMPFILE}" in
193 echo " *** Deleting ${COMPFILE}"
197 if mm_install "${COMPFILE}"; then
198 echo " *** ${COMPFILE} installed successfully"
200 echo " *** Problem installing ${COMPFILE}, it will remain to merge by hand"
204 case "${NO_INSTALLED}" in
206 # interact with user to merge files
211 echo " *** There is no installed version of ${COMPFILE}"
213 HANDLE_COMPFILE="NOT V"
215 esac # End of "No installed version of file but user selected merge" test
222 echo " *** ${COMPFILE} will remain for your consideration"
225 # invalid choice, show menu again.
226 echo "invalid choice: ${HANDLE_COMPFILE}"
228 HANDLE_COMPFILE="NOT V"
231 esac # End of "How to handle files that are different"
243 press_to_continue () {
245 echo -n ' *** Press the [Enter] or [Return] key to continue '
249 # Set the default path for the temporary root environment
251 TEMPROOT='/var/tmp/temproot'
253 # Read /etc/mergemaster.rc first so the one in $HOME can override
255 if [ -r /etc/mergemaster.rc ]; then
256 . /etc/mergemaster.rc
259 # Read .mergemasterrc before command line so CLI can override
261 if [ -r "$HOME/.mergemasterrc" ]; then
262 . "$HOME/.mergemasterrc"
265 # Check the command line options
267 while getopts ":ascrvhipCPm:t:du:w:D:A:FU" COMMAND_LINE_ARGUMENT ; do
268 case "${COMMAND_LINE_ARGUMENT}" in
270 ARCHSTRING='TARGET_ARCH='${OPTARG}
289 case "${AUTO_RUN}" in
323 TEMPROOT=${TEMPROOT}.`date +%m%d.%H.%M`
329 SCREEN_WIDTH=${OPTARG}
341 if [ -n "$AUTO_RUN" ]; then
342 if [ -n "$FREEBSD_ID" -o -n "$AUTO_UPGRADE" -o -n "$AUTO_INSTALL" ]; then
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.'
353 # Assign the location of the mtree database
355 MTREEDB=${MTREEDB:-${DESTDIR}/var/db}
356 MTREEFILE="${MTREEDB}/mergemaster.mtree"
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}
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
368 if [ ! -s "${MTREEFILE}" ]; then
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."
374 case "${AUTO_RUN}" in
384 if [ -e "${DESTDIR}/etc/fstab" ]; then
385 if grep -q nodev ${DESTDIR}/etc/fstab; then
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."
398 # If the user has a pager defined, make sure we can run it
400 case "${DONT_CHECK_PAGER}" in
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?"
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"
412 echo " Use 'm' to use plain old 'more' as your PAGER for this run"
414 echo " Default is to use plain old 'more' "
416 echo -n "What should I do? [Use 'more'] "
419 case "${FIXPAGER}" in
424 if [ -x /usr/bin/less ]; then
426 elif [ -x /usr/local/bin/less ]; then
427 PAGER=/usr/local/bin/less
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"
441 echo "invalid choice: ${FIXPAGER}"
446 if [ -n "${PAGER}" ]; then
452 # If user has a pager defined, or got assigned one above, use it.
457 if [ -n "${VERBOSE}" -a ! "${PAGER}" = "more" ]; then
458 echo " *** You have ${PAGER} defined as your pager so we will use that"
463 # Assign the diff flag once so we will not have to keep testing it
465 DIFF_FLAG=${DIFF_FLAG:--u}
467 # Assign the source directory
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}/.."
476 SOURCEDIR=${SOURCEDIR}/..
479 # Setup make to use system files from SOURCEDIR
480 MM_MAKE="make ${ARCHSTRING} -m ${SOURCEDIR}/share/mk"
482 # Check DESTDIR against the mergemaster mtree database to see what
483 # files the user changed from the reference files.
485 if [ -n "${AUTO_UPGRADE}" -a -s "${MTREEFILE}" ]; then
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}:"
493 [ "$CHANGED" = ':' ] && unset CHANGED
496 # Check the width of the user's terminal
501 0|'') ;; # No-op, since the input is not valid
503 case "${SCREEN_WIDTH}" in
504 '') SCREEN_WIDTH="${w}" ;;
505 "${w}") ;; # No-op, since they are the same
507 echo -n "*** You entered ${SCREEN_WIDTH} as your screen width, but stty "
508 echo "thinks it is ${w}."
510 echo -n "What would you like to use? [${w}] "
512 case "${SCREEN_WIDTH}" in
513 '') SCREEN_WIDTH="${w}" ;;
520 # Define what CVS $Id tag to look for to aid portability.
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; }
532 # Set up the loop to test for the existence of the
533 # temp root directory.
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."
542 case "${AUTO_RUN}" in
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"
548 echo " Default is to use ${TEMPROOT} as is"
550 echo -n "How should I deal with this? [Use the existing ${TEMPROOT}] "
553 case "${DELORNOT}" in
556 echo " *** Deleting the old ${TEMPROOT}"
562 echo " *** Enter new directory name for temporary root environment"
570 echo " *** Leaving ${TEMPROOT} intact"
576 echo "invalid choice: ${DELORNOT}"
582 # If this is an auto-run, try a hopefully safe alternative then
584 TEMPROOT=/var/tmp/temproot.`date +%m%d.%H.%M.%S`
592 echo "*** Creating the temporary root environment in ${TEMPROOT}"
594 if mkdir -p "${TEMPROOT}"; then
595 echo " *** ${TEMPROOT} ready for use"
598 if [ ! -d "${TEMPROOT}" ]; then
600 echo " *** FATAL ERROR: Cannot create ${TEMPROOT}"
605 echo " *** Creating and populating directory structure in ${TEMPROOT}"
615 case "${PRE_WORLD}" in
621 ${MM_MAKE} DESTDIR=${DESTDIR} distrib-dirs >/dev/null
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;} ||
630 echo " *** FATAL ERROR: Cannot 'cd' to ${SOURCEDIR} and install files to";
631 echo " the temproot environment";
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;} ||
641 echo ' *** FATAL ERROR: Cannot copy files to the temproot environment';
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.
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.'
661 diff -qr ${DESTDIR}/etc ${TEMPROOT}/etc | grep "^Only in ${DESTDIR}/etc" | ${PAGER}
667 case "${IGNORE_MOTD}" in
671 echo "*** You have the IGNORE_MOTD option set in your mergemaster rc file."
672 echo " This option is deprecated in favor of the IGNORE_FILES option."
673 echo " Please update your rc file accordingly."
679 # Avoid comparing the following user specified files
680 for file in ${IGNORE_FILES}; do
681 test -e ${TEMPROOT}/${file} && unlink ${TEMPROOT}/${file}
684 # We really don't want to have to deal with files like login.conf.db, pwd.db,
685 # or spwd.db. Instead, we want to compare the text versions, and run *_mkdb.
686 # Prompt the user to do so below, as needed.
688 rm -f ${TEMPROOT}/etc/*.db ${TEMPROOT}/etc/passwd
690 # We only need to compare things like freebsd.cf once
691 find ${TEMPROOT}/usr/obj -type f -delete 2>/dev/null
693 # Delete stuff we do not need to keep the mtree database small,
694 # and to make the actual comparison faster.
695 find ${TEMPROOT}/usr -type l -delete 2>/dev/null
696 find ${TEMPROOT} -type f -size 0 -delete 2>/dev/null
697 find -d ${TEMPROOT} -type d -empty -delete 2>/dev/null
699 # Build the mtree database in a temporary location.
700 case "${PRE_WORLD}" in
701 '') MTREENEW=`mktemp -t mergemaster.mtree`
702 mtree -ci -p ${TEMPROOT} -k size,md5digest > ${MTREENEW} 2>/dev/null
704 *) # We don't want to mess with the mtree database on a pre-world run or
705 # when re-scanning a previously-built tree.
708 ;; # End of the "RERUN" test
711 # Get ready to start comparing files
713 # Check umask if not specified on the command line,
714 # and we are not doing an autorun
716 if [ -z "${NEW_UMASK}" -a -z "${AUTO_RUN}" ]; then
718 case "${USER_UMASK}" in
722 echo " *** Your umask is currently set to ${USER_UMASK}. By default, this script"
723 echo " installs all files with the same user, group and modes that"
724 echo " they are created with by ${SOURCEDIR}/etc/Makefile, compared to"
725 echo " a umask of 022. This umask allows world read permission when"
726 echo " the file's default permissions have it."
728 echo " No world permissions can sometimes cause problems. A umask of"
729 echo " 022 will restore the default behavior, but is not mandatory."
730 echo " /etc/master.passwd is a special case. Its file permissions"
731 echo " will be 600 (rw-------) if installed."
733 echo -n "What umask should I use? [${USER_UMASK}] "
736 NEW_UMASK="${NEW_UMASK:-$USER_UMASK}"
742 CONFIRMED_UMASK=${NEW_UMASK:-0022}
745 # Warn users who still have old rc files
747 for file in atm devfs diskless1 diskless2 network network6 pccard \
748 serial syscons sysctl alpha amd64 i386 ia64 sparc64; do
749 if [ -f "${DESTDIR}/etc/rc.${file}" ]; then
755 case "${OLD_RC_PRESENT}" in
758 echo " *** There are elements of the old rc system in ${DESTDIR}/etc/."
760 echo ' While these scripts will not hurt anything, they are not'
761 echo ' functional on an up to date system, and can be removed.'
764 case "${AUTO_RUN}" in
766 echo -n 'Move these files to /var/tmp/mergemaster/old_rc? [yes] '
769 case "${MOVE_OLD_RC}" in
772 mkdir -p /var/tmp/mergemaster/old_rc
773 for file in atm devfs diskless1 diskless2 network network6 pccard \
774 serial syscons sysctl alpha amd64 i386 ia64 sparc64; do
775 if [ -f "${DESTDIR}/etc/rc.${file}" ]; then
776 mv ${DESTDIR}/etc/rc.${file} /var/tmp/mergemaster/old_rc/
779 echo ' The files have been moved'
788 # Use the umask/mode information to install the files
789 # Create directories as needed
792 echo "*** FATAL ERROR: Unable to install ${1} to ${2}"
797 do_install_and_rm () {
798 case "${PRESERVE_FILES}" in
800 if [ -f "${3}/${2##*/}" ]; then
801 mkdir -p ${PRESERVE_FILES_DIR}/${2%/*}
802 cp ${3}/${2##*/} ${PRESERVE_FILES_DIR}/${2%/*}
807 if [ ! -d "${3}/${2##*/}" ]; then
808 if install -m ${1} ${2} ${3}; then
811 install_error ${2} ${3}
814 install_error ${2} ${3}
818 # 4095 = "obase=10;ibase=8;07777" | bc
821 OCTAL=$(( ~$(echo "obase=10; ibase=8; ${CONFIRMED_UMASK}" | bc) & 4095 &
822 $(echo "obase=10; ibase=8; $(stat -f "%OMp%OLp" ${1})" | bc) ))
823 printf "%04o\n" ${OCTAL}
829 INSTALL_DIR=${INSTALL_DIR%/*}
831 case "${INSTALL_DIR}" in
837 if [ -n "${DESTDIR}${INSTALL_DIR}" -a ! -d "${DESTDIR}${INSTALL_DIR}" ]; then
838 DIR_MODE=`find_mode "${TEMPROOT}/${INSTALL_DIR}"`
839 install -d -o root -g wheel -m "${DIR_MODE}" "${DESTDIR}${INSTALL_DIR}" ||
840 install_error $1 ${DESTDIR}${INSTALL_DIR}
843 FILE_MODE=`find_mode "${1}"`
845 if [ ! -x "${1}" ]; then
854 NEED_SERVICES_MKDB=yes
857 do_install_and_rm 600 "${1}" "${DESTDIR}${INSTALL_DIR}"
864 # install will unlink the file before it installs the new one,
865 # so we have to restore/create the link afterwards.
867 st_nlink=0 # In case the file does not yet exist
868 eval $(stat -s ${DESTDIR}${COMPFILE#.} 2>/dev/null)
870 do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}"
872 if [ -n "${AUTO_INSTALL}" -a $st_nlink -gt 1 ]; then
875 case "${LINK_EXPLAINED}" in
877 echo " *** Historically BSD derived systems have had a"
878 echo " hard link from /.cshrc and /.profile to"
879 echo " their namesakes in /root. Please indicate"
880 echo " your preference below for bringing your"
881 echo " installed files up to date."
887 echo " Use 'd' to delete the temporary ${COMPFILE}"
888 echo " Use 'l' to delete the existing ${DESTDIR}/root/${COMPFILE##*/} and create the link"
890 echo " Default is to leave the temporary file to deal with by hand"
892 echo -n " How should I handle ${COMPFILE}? [Leave it to install later] "
896 case "${HANDLE_LINK}" in
900 echo " *** Deleting ${COMPFILE}"
904 unlink ${DESTDIR}/root/${COMPFILE##*/}
905 if ln ${DESTDIR}${COMPFILE#.} ${DESTDIR}/root/${COMPFILE##*/}; then
906 echo " *** Link from ${DESTDIR}${COMPFILE#.} to ${DESTDIR}/root/${COMPFILE##*/} installed successfully"
908 echo " *** Error linking ${DESTDIR}${COMPFILE#.} to ${DESTDIR}/root/${COMPFILE##*/}"
909 echo " *** ${COMPFILE} will remain for your consideration"
913 echo " *** ${COMPFILE} will remain for your consideration"
920 case "${DONT_INSTALL}" in
922 do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}"
928 else # File matched -x
929 do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}"
934 if [ ! -d "${TEMPROOT}" ]; then
935 echo "*** FATAL ERROR: The temproot directory (${TEMPROOT})"
936 echo ' has disappeared!'
942 echo "*** Beginning comparison"
945 # Pre-world does not populate /etc/rc.d.
946 # It is very possible that a previous run would have deleted files in
947 # ${TEMPROOT}/etc/rc.d, thus creating a lot of false positives.
948 if [ -z "${PRE_WORLD}" -a -z "${RERUN}" ]; then
949 echo " *** Checking ${DESTDIR}/etc/rc.d for stale files"
951 cd "${DESTDIR}/etc/rc.d" &&
953 if [ ! -e "${TEMPROOT}/etc/rc.d/${file}" ]; then
954 STALE_RC_FILES="${STALE_RC_FILES} ${file}"
957 case "${STALE_RC_FILES}" in
959 echo ' *** No stale files found'
962 echo " *** The following files exist in ${DESTDIR}/etc/rc.d but not in"
963 echo " ${TEMPROOT}/etc/rc.d/:"
965 echo "${STALE_RC_FILES}"
967 echo ' The presence of stale files in this directory can cause the'
968 echo ' dreaded unpredictable results, and therefore it is highly'
969 echo ' recommended that you delete them.'
970 case "${AUTO_RUN}" in
973 echo -n ' *** Delete them now? [n] '
974 read DELETE_STALE_RC_FILES
975 case "${DELETE_STALE_RC_FILES}" in
977 echo ' *** Deleting ... '
982 echo ' *** Files will not be deleted'
988 if [ -n "${DELETE_STALE_RC_FILES}" ]; then
989 echo ' *** Deleting ... '
1001 if [ -r "${MM_PRE_COMPARE_SCRIPT}" ]; then
1002 . "${MM_PRE_COMPARE_SCRIPT}"
1005 # Things that were files/directories/links in one version can sometimes
1006 # change to something else in a newer version. So we need to explicitly
1007 # test for this, and warn the user if what we find does not match.
1009 for COMPFILE in `find . | sort` ; do
1010 if [ -e "${DESTDIR}${COMPFILE#.}" ]; then
1011 INSTALLED_TYPE=`stat -f '%HT' ${DESTDIR}${COMPFILE#.}`
1015 TEMPROOT_TYPE=`stat -f '%HT' $COMPFILE`
1017 if [ ! "$TEMPROOT_TYPE" = "$INSTALLED_TYPE" ]; then
1018 [ "$COMPFILE" = '.' ] && continue
1019 TEMPROOT_TYPE=`echo $TEMPROOT_TYPE | tr [:upper:] [:lower:]`
1020 INSTALLED_TYPE=`echo $INSTALLED_TYPE | tr [:upper:] [:lower:]`
1022 echo "*** The installed file ${DESTDIR}${COMPFILE#.} has the type \"$INSTALLED_TYPE\""
1023 echo " but the new version has the type \"$TEMPROOT_TYPE\""
1025 echo " How would you like to handle this?"
1027 echo " Use 'r' to remove ${DESTDIR}${COMPFILE#.}"
1028 case "$TEMPROOT_TYPE" in
1030 TARGET=`readlink $COMPFILE`
1031 echo " and create a link to $TARGET in its place" ;;
1032 *) echo " You will be able to install it as a \"$TEMPROOT_TYPE\"" ;;
1035 echo " Use 'i' to ignore this"
1037 echo -n " How to proceed? [i] "
1040 [rR]) case "${PRESERVE_FILES}" in
1042 mv ${DESTDIR}${COMPFILE#.} ${PRESERVE_FILES_DIR}/ || exit 1 ;;
1043 *) rm -rf ${DESTDIR}${COMPFILE#.} ;;
1045 case "$TEMPROOT_TYPE" in
1046 'symbolic link') ln -sf $TARGET ${DESTDIR}${COMPFILE#.} ;;
1049 echo "*** See the man page about adding ${COMPFILE#.} to the list of IGNORE_FILES"
1050 press_to_continue ;;
1056 for COMPFILE in `find . -type f | sort`; do
1058 # First, check to see if the file exists in DESTDIR. If not, the
1059 # diff_loop function knows how to handle it.
1061 if [ ! -e "${DESTDIR}${COMPFILE#.}" ]; then
1062 case "${AUTO_RUN}" in
1067 case "${AUTO_INSTALL}" in
1069 # If this is an auto run, make it official
1070 echo " *** ${COMPFILE} will remain for your consideration"
1077 esac # Auto run test
1083 # Compare CVS $Id's first so if the file hasn't been modified
1084 # local changes will be ignored.
1085 # If the files have the same $Id, delete the one in temproot so the
1086 # user will have less to wade through if files are left to merge by hand.
1088 CVSID1=`grep "[$]${CVS_ID_TAG}:" ${DESTDIR}${COMPFILE#.} 2>/dev/null`
1089 CVSID2=`grep "[$]${CVS_ID_TAG}:" ${COMPFILE} 2>/dev/null` || CVSID2=none
1093 echo " *** Temp ${COMPFILE} and installed have the same CVS Id, deleting"
1100 # If the file is still here either because the $Ids are different, the
1101 # file doesn't have an $Id, or we're using STRICT mode; look at the diff.
1103 if [ -f "${COMPFILE}" ]; then
1105 # Do an absolute diff first to see if the files are actually different.
1106 # If they're not different, delete the one in temproot.
1108 if diff -q ${DIFF_OPTIONS} "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" > \
1109 /dev/null 2>&1; then
1110 echo " *** Temp ${COMPFILE} and installed are the same, deleting"
1113 # Ok, the files are different, so show the user where they differ.
1114 # Use user's choice of diff methods; and user's pager if they have one.
1116 # Use unified diffs by default. Context diffs give me a headache. :)
1118 # If the user chose the -F option, test for that before proceeding
1120 if [ -n "$FREEBSD_ID" ]; then
1121 if diff -q -I'[$]FreeBSD.*[$]' "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" > \
1122 /dev/null 2>&1; then
1123 if mm_install "${COMPFILE}"; then
1124 echo "*** Updated revision control Id for ${DESTDIR}${COMPFILE#.}"
1126 echo "*** Problem installing ${COMPFILE}, it will remain to merge by hand later"
1131 case "${AUTO_RUN}" in
1133 # prompt user to install/delete/merge changes
1137 # If this is an auto run, make it official
1138 echo " *** ${COMPFILE} will remain for your consideration"
1140 esac # Auto run test
1141 fi # Yes, the files are different
1142 fi # Yes, the file still remains to be checked
1143 done # This is for the for way up there at the beginning of the comparison
1146 echo "*** Comparison complete"
1148 if [ -s "${MTREENEW}" ]; then
1149 echo "*** Saving mtree database for future upgrades"
1150 test -e "${MTREEFILE}" && unlink ${MTREEFILE}
1151 mv ${MTREENEW} ${MTREEFILE}
1156 TEST_FOR_FILES=`find ${TEMPROOT} -type f -size +0 2>/dev/null`
1157 if [ -n "${TEST_FOR_FILES}" ]; then
1158 echo "*** Files that remain for you to merge by hand:"
1159 find "${TEMPROOT}" -type f -size +0 | sort
1162 case "${AUTO_RUN}" in
1164 echo -n "Do you wish to delete what is left of ${TEMPROOT}? [no] "
1166 case "${DEL_TEMPROOT}" in
1171 echo " *** ${TEMPROOT} will remain"
1178 echo "*** ${TEMPROOT} is empty, deleting"
1182 case "${AUTO_INSTALLED_FILES}" in
1185 case "${AUTO_RUN}" in
1189 echo '*** You chose the automatic install option for files that did not'
1190 echo ' exist on your system. The following were installed for you:'
1191 echo "${AUTO_INSTALLED_FILES}"
1196 echo '*** You chose the automatic install option for files that did not'
1197 echo ' exist on your system. The following were installed for you:'
1198 echo "${AUTO_INSTALLED_FILES}"
1204 case "${AUTO_UPGRADED_FILES}" in
1207 case "${AUTO_RUN}" in
1211 echo '*** You chose the automatic upgrade option for files that you did'
1212 echo ' not alter on your system. The following were upgraded for you:'
1213 echo "${AUTO_UPGRADED_FILES}"
1218 echo '*** You chose the automatic upgrade option for files that you did'
1219 echo ' not alter on your system. The following were upgraded for you:'
1220 echo "${AUTO_UPGRADED_FILES}"
1227 case "${AUTO_RUN}" in
1231 echo -n ' Would you like to run it now? y or n [n] '
1234 case "${YES_OR_NO}" in
1236 echo " Running ${1}"
1242 echo " *** Cancelled"
1244 echo " Make sure to run ${1} yourself"
1248 echo " *** Sorry, I do not understand your answer (${YES_OR_NO})"
1250 echo " Make sure to run ${1} yourself"
1257 case "${NEED_NEWALIASES}" in
1261 if [ -n "${DESTDIR}" ]; then
1262 echo "*** You installed a new aliases file into ${DESTDIR}/etc/mail, but"
1263 echo " the newaliases command is limited to the directories configured"
1264 echo " in sendmail.cf. Make sure to create your aliases database by"
1265 echo " hand when your sendmail configuration is done."
1267 echo "*** You installed a new aliases file, so make sure that you run"
1268 echo " '/usr/bin/newaliases' to rebuild your aliases database"
1269 run_it_now '/usr/bin/newaliases'
1274 case "${NEED_CAP_MKDB}" in
1278 echo "*** You installed a login.conf file, so make sure that you run"
1279 echo " '/usr/bin/cap_mkdb ${DESTDIR}/etc/login.conf'"
1280 echo " to rebuild your login.conf database"
1281 run_it_now "/usr/bin/cap_mkdb ${DESTDIR}/etc/login.conf"
1285 case "${NEED_SERVICES_MKDB}" in
1289 echo "*** You installed a services file, so make sure that you run"
1290 echo " '/usr/sbin/services_mkdb -q -o ${DESTDIR}/var/db/services.db ${DESTDIR}/etc/services'"
1291 echo " to rebuild your services database"
1292 run_it_now "/usr/sbin/services_mkdb -q -o ${DESTDIR}/var/db/services.db ${DESTDIR}/etc/services"
1296 case "${NEED_PWD_MKDB}" in
1300 echo "*** You installed a new master.passwd file, so make sure that you run"
1301 if [ -n "${DESTDIR}" ]; then
1302 echo " '/usr/sbin/pwd_mkdb -d ${DESTDIR}/etc -p ${DESTDIR}/etc/master.passwd'"
1303 echo " to rebuild your password files"
1304 run_it_now "/usr/sbin/pwd_mkdb -d ${DESTDIR}/etc -p ${DESTDIR}/etc/master.passwd"
1306 echo " '/usr/sbin/pwd_mkdb -p /etc/master.passwd'"
1307 echo " to rebuild your password files"
1308 run_it_now '/usr/sbin/pwd_mkdb -p /etc/master.passwd'
1315 if [ -r "${MM_EXIT_SCRIPT}" ]; then
1316 . "${MM_EXIT_SCRIPT}"
1319 case "${COMP_CONFS}" in
1322 . ${DESTDIR}/etc/defaults/rc.conf
1325 echo "*** Comparing conf files: ${rc_conf_files}"
1327 for CONF_FILE in ${rc_conf_files}; do
1328 if [ -r "${DESTDIR}${CONF_FILE}" ]; then
1330 echo "*** From ${DESTDIR}${CONF_FILE}"
1331 echo "*** From ${DESTDIR}/etc/defaults/rc.conf"
1333 for RC_CONF_VAR in `grep -i ^[a-z] ${DESTDIR}${CONF_FILE} |
1334 cut -d '=' -f 1`; do
1336 grep -w ^${RC_CONF_VAR} ${DESTDIR}${CONF_FILE}
1337 grep -w ^${RC_CONF_VAR} ${DESTDIR}/etc/defaults/rc.conf ||
1338 echo ' * No default variable with this name'
1346 case "${PRE_WORLD}" in
1349 MAKE_CONF="${SOURCEDIR}/share/examples/etc/make.conf"
1352 echo '*** Comparing make variables'
1354 echo "*** From ${DESTDIR}/etc/make.conf"
1355 echo "*** From ${MAKE_CONF}"
1357 for MAKE_VAR in `grep -i ^[a-z] ${DESTDIR}/etc/make.conf | cut -d '=' -f 1`; do
1359 grep -w ^${MAKE_VAR} ${DESTDIR}/etc/make.conf
1360 grep -w ^#${MAKE_VAR} ${MAKE_CONF} ||
1361 echo ' * No example variable with this name'
1366 if [ -n "${PRESERVE_FILES}" ]; then
1367 find -d $PRESERVE_FILES_DIR -type d -empty -delete 2>/dev/null
1368 rmdir $PRESERVE_FILES_DIR 2>/dev/null