5 # Compare files created by /usr/src/etc/Makefile (or the directory
6 # the user specifies) with the currently installed copies.
8 # Copyright 1998-2010 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 [-scrvahipFCPU]'
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"
34 echo " -m /path/directory Specify location of source to do the make in"
35 echo " -t /path/directory Specify temp root directory"
36 echo " -d Add date and time to directory name (e.g., /var/tmp/temproot.`date +%m%d.%H.%M`)"
37 echo " -u N Specify a numeric umask"
38 echo " -w N Specify a screen width in columns to sdiff"
39 echo " -A architecture Alternative architecture name to pass to make"
40 echo ' -D /path/directory Specify the destination directory to install files to'
45 echo "* To specify a directory other than /var/tmp/temproot for the"
46 echo " temporary root environment, use -t /path/to/temp/root"
47 echo "* The -w option takes a number as an argument for the column width"
48 echo " of the screen. The default is 80."
49 echo '* The -a option causes mergemaster to run without prompting.'
52 # Loop allowing the user to use sdiff to merge files and display the merged
58 echo " *** Type h at the sdiff prompt (%) to get usage help"
63 while [ "${MERGE_AGAIN}" = "yes" ]; do
64 # Prime file.merged so we don't blat the owner/group id's
65 cp -p "${COMPFILE}" "${COMPFILE}.merged"
66 sdiff -o "${COMPFILE}.merged" --text --suppress-common-lines \
67 --width=${SCREEN_WIDTH:-80} "${DESTDIR}${COMPFILE#.}" "${COMPFILE}"
69 while [ "${INSTALL_MERGED}" = "v" -o "${INSTALL_MERGED}" = "V" ]; do
71 echo " Use 'i' to install merged file"
72 echo " Use 'r' to re-do the merge"
73 echo " Use 'v' to view the merged file"
74 echo " Default is to leave the temporary file to deal with by hand"
76 echo -n " *** How should I deal with the merged file? [Leave it for later] "
79 case "${INSTALL_MERGED}" in
81 mv "${COMPFILE}.merged" "${COMPFILE}"
83 if mm_install "${COMPFILE}"; then
84 echo " *** Merged version of ${COMPFILE} installed successfully"
86 echo " *** Problem installing ${COMPFILE}, it will remain to merge by hand later"
91 rm "${COMPFILE}.merged"
94 ${PAGER} "${COMPFILE}.merged"
97 echo " *** ${COMPFILE} will remain for your consideration"
101 echo "invalid choice: ${INSTALL_MERGED}"
109 # Loop showing user differences between files, allow merge, skip or install
115 while [ "${HANDLE_COMPFILE}" = "v" -o "${HANDLE_COMPFILE}" = "V" -o \
116 "${HANDLE_COMPFILE}" = "NOT V" ]; do
117 if [ -f "${DESTDIR}${COMPFILE#.}" -a -f "${COMPFILE}" ]; then
118 if [ -n "${AUTO_UPGRADE}" -a -n "${CHANGED}" ]; then
120 *:${DESTDIR}${COMPFILE#.}:*) ;; # File has been modified
123 echo " *** ${COMPFILE} has not been user modified."
126 if mm_install "${COMPFILE}"; then
127 echo " *** ${COMPFILE} upgraded successfully"
129 # Make the list print one file per line
130 AUTO_UPGRADED_FILES="${AUTO_UPGRADED_FILES} ${DESTDIR}${COMPFILE#.}
133 echo " *** Problem upgrading ${COMPFILE}, it will remain to merge by hand"
139 if [ "${HANDLE_COMPFILE}" = "v" -o "${HANDLE_COMPFILE}" = "V" ]; then
141 echo ' ====================================================================== '
144 echo " *** Displaying differences between ${COMPFILE} and installed version:"
146 diff ${DIFF_FLAG} ${DIFF_OPTIONS} "${DESTDIR}${COMPFILE#.}" "${COMPFILE}"
152 echo " *** There is no installed version of ${COMPFILE}"
154 case "${AUTO_INSTALL}" in
157 if mm_install "${COMPFILE}"; then
158 echo " *** ${COMPFILE} installed successfully"
160 # Make the list print one file per line
161 AUTO_INSTALLED_FILES="${AUTO_INSTALLED_FILES} ${DESTDIR}${COMPFILE#.}
164 echo " *** Problem installing ${COMPFILE}, it will remain to merge by hand"
174 echo " Use 'd' to delete the temporary ${COMPFILE}"
175 echo " Use 'i' to install the temporary ${COMPFILE}"
176 case "${NO_INSTALLED}" in
178 echo " Use 'm' to merge the temporary and installed versions"
179 echo " Use 'v' to view the diff results again"
183 echo " Default is to leave the temporary file to deal with by hand"
185 echo -n "How should I deal with this? [Leave it for later] "
188 case "${HANDLE_COMPFILE}" in
192 echo " *** Deleting ${COMPFILE}"
196 if mm_install "${COMPFILE}"; then
197 echo " *** ${COMPFILE} installed successfully"
199 echo " *** Problem installing ${COMPFILE}, it will remain to merge by hand"
203 case "${NO_INSTALLED}" in
205 # interact with user to merge files
210 echo " *** There is no installed version of ${COMPFILE}"
212 HANDLE_COMPFILE="NOT V"
214 esac # End of "No installed version of file but user selected merge" test
221 echo " *** ${COMPFILE} will remain for your consideration"
224 # invalid choice, show menu again.
225 echo "invalid choice: ${HANDLE_COMPFILE}"
227 HANDLE_COMPFILE="NOT V"
230 esac # End of "How to handle files that are different"
242 press_to_continue () {
244 echo -n ' *** Press the [Enter] or [Return] key to continue '
248 # Set the default path for the temporary root environment
250 TEMPROOT='/var/tmp/temproot'
252 # Read /etc/mergemaster.rc first so the one in $HOME can override
254 if [ -r /etc/mergemaster.rc ]; then
255 . /etc/mergemaster.rc
258 # Read .mergemasterrc before command line so CLI can override
260 if [ -r "$HOME/.mergemasterrc" ]; then
261 . "$HOME/.mergemasterrc"
264 # Assign the location of the mtree database
266 MTREEDB=${MTREEDB:-${DESTDIR}/var/db}
267 MTREEFILE="${MTREEDB}/mergemaster.mtree"
269 # Check the command line options
271 while getopts ":ascrvhipCPm:t:du:w:D:A:FU" COMMAND_LINE_ARGUMENT ; do
272 case "${COMMAND_LINE_ARGUMENT}" in
274 ARCHSTRING='TARGET_ARCH='${OPTARG}
293 case "${AUTO_RUN}" in
327 TEMPROOT=${TEMPROOT}.`date +%m%d.%H.%M`
333 SCREEN_WIDTH=${OPTARG}
345 # Don't force the user to set this in the mergemaster rc file
346 if [ -n "${PRESERVE_FILES}" -a -z "${PRESERVE_FILES_DIR}" ]; then
347 PRESERVE_FILES_DIR=/var/tmp/mergemaster/preserved-files-`date +%y%m%d-%H%M%S`
348 mkdir -p ${PRESERVE_FILES_DIR}
351 # Check for the mtree database in DESTDIR
352 case "${AUTO_UPGRADE}" in
353 '') ;; # If the option is not set no need to run the test or warn the user
355 if [ ! -s "${MTREEFILE}" ]; then
357 echo "*** Unable to find mtree database (${MTREEFILE})."
358 echo " Skipping auto-upgrade on this run."
359 echo " It will be created for the next run when this one is complete."
361 case "${AUTO_RUN}" in
371 if [ -e "${DESTDIR}/etc/fstab" ]; then
372 if grep -q nodev ${DESTDIR}/etc/fstab; then
374 echo "*** You have the deprecated 'nodev' option in ${DESTDIR}/etc/fstab."
375 echo " This can prevent the filesystem from being mounted on reboot."
376 echo " Please update your fstab before continuing."
377 echo " See fstab(5) for more information."
385 # If the user has a pager defined, make sure we can run it
387 case "${DONT_CHECK_PAGER}" in
390 while ! type "${PAGER%% *}" >/dev/null; do
391 echo " *** Your PAGER environment variable specifies '${PAGER}', but"
392 echo " due to the limited PATH that I use for security reasons,"
393 echo " I cannot execute it. So, what would you like to do?"
395 echo " Use 'e' to exit mergemaster and fix your PAGER variable"
396 if [ -x /usr/bin/less -o -x /usr/local/bin/less ]; then
397 echo " Use 'l' to set PAGER to 'less' for this run"
399 echo " Use 'm' to use plain old 'more' as your PAGER for this run"
401 echo " Default is to use plain old 'more' "
403 echo -n "What should I do? [Use 'more'] "
406 case "${FIXPAGER}" in
411 if [ -x /usr/bin/less ]; then
413 elif [ -x /usr/local/bin/less ]; then
414 PAGER=/usr/local/bin/less
417 echo " *** Fatal Error:"
418 echo " You asked to use 'less' as your pager, but I can't"
419 echo " find it in /usr/bin or /usr/local/bin"
428 echo "invalid choice: ${FIXPAGER}"
433 if [ -n "${PAGER}" ]; then
439 # If user has a pager defined, or got assigned one above, use it.
444 if [ -n "${VERBOSE}" -a ! "${PAGER}" = "more" ]; then
445 echo " *** You have ${PAGER} defined as your pager so we will use that"
450 # Assign the diff flag once so we will not have to keep testing it
452 DIFF_FLAG=${DIFF_FLAG:--u}
454 # Assign the source directory
456 SOURCEDIR=${SOURCEDIR:-/usr/src}
457 if [ ! -f ${SOURCEDIR}/Makefile.inc1 -a \
458 -f ${SOURCEDIR}/../Makefile.inc1 ]; then
459 echo " *** The source directory you specified (${SOURCEDIR})"
460 echo " will be reset to ${SOURCEDIR}/.."
463 SOURCEDIR=${SOURCEDIR}/..
466 # Setup make to use system files from SOURCEDIR
467 MM_MAKE="make ${ARCHSTRING} -m ${SOURCEDIR}/share/mk"
469 # Check DESTDIR against the mergemaster mtree database to see what
470 # files the user changed from the reference files.
472 if [ -n "${AUTO_UPGRADE}" -a -s "${MTREEFILE}" ]; then
474 for file in `mtree -eqL -f ${MTREEFILE} -p ${DESTDIR}/ \
475 2>/dev/null | awk '($2 == "changed") {print $1}'`; do
476 if [ -f "${DESTDIR}/$file" ]; then
477 CHANGED="${CHANGED}${DESTDIR}/${file}:"
480 [ "$CHANGED" = ':' ] && unset CHANGED
483 # Check the width of the user's terminal
488 0|'') ;; # No-op, since the input is not valid
490 case "${SCREEN_WIDTH}" in
491 '') SCREEN_WIDTH="${w}" ;;
492 "${w}") ;; # No-op, since they are the same
494 echo -n "*** You entered ${SCREEN_WIDTH} as your screen width, but stty "
495 echo "thinks it is ${w}."
497 echo -n "What would you like to use? [${w}] "
499 case "${SCREEN_WIDTH}" in
500 '') SCREEN_WIDTH="${w}" ;;
507 # Define what CVS $Id tag to look for to aid portability.
512 rm -rf "${TEMPROOT}" 2>/dev/null
513 chflags -R 0 "${TEMPROOT}" 2>/dev/null
514 rm -rf "${TEMPROOT}" || { echo "*** Unable to delete ${TEMPROOT}"; exit 1; }
519 # Set up the loop to test for the existence of the
520 # temp root directory.
523 while [ "${TEST_TEMP_ROOT}" = "yes" ]; do
524 if [ -d "${TEMPROOT}" ]; then
525 echo "*** The directory specified for the temporary root environment,"
526 echo " ${TEMPROOT}, exists. This can be a security risk if untrusted"
527 echo " users have access to the system."
529 case "${AUTO_RUN}" in
531 echo " Use 'd' to delete the old ${TEMPROOT} and continue"
532 echo " Use 't' to select a new temporary root directory"
533 echo " Use 'e' to exit mergemaster"
535 echo " Default is to use ${TEMPROOT} as is"
537 echo -n "How should I deal with this? [Use the existing ${TEMPROOT}] "
540 case "${DELORNOT}" in
543 echo " *** Deleting the old ${TEMPROOT}"
549 echo " *** Enter new directory name for temporary root environment"
557 echo " *** Leaving ${TEMPROOT} intact"
563 echo "invalid choice: ${DELORNOT}"
569 # If this is an auto-run, try a hopefully safe alternative then
571 TEMPROOT=/var/tmp/temproot.`date +%m%d.%H.%M.%S`
579 echo "*** Creating the temporary root environment in ${TEMPROOT}"
581 if mkdir -p "${TEMPROOT}"; then
582 echo " *** ${TEMPROOT} ready for use"
585 if [ ! -d "${TEMPROOT}" ]; then
587 echo " *** FATAL ERROR: Cannot create ${TEMPROOT}"
592 echo " *** Creating and populating directory structure in ${TEMPROOT}"
602 case "${PRE_WORLD}" in
608 ${MM_MAKE} DESTDIR=${DESTDIR} distrib-dirs
611 od=${TEMPROOT}/usr/obj
612 ${MM_MAKE} DESTDIR=${TEMPROOT} distrib-dirs &&
613 MAKEOBJDIRPREFIX=$od ${MM_MAKE} _obj SUBDIR_OVERRIDE=etc &&
614 MAKEOBJDIRPREFIX=$od ${MM_MAKE} everything SUBDIR_OVERRIDE=etc &&
615 MAKEOBJDIRPREFIX=$od ${MM_MAKE} DESTDIR=${TEMPROOT} distribution;} ||
617 echo " *** FATAL ERROR: Cannot 'cd' to ${SOURCEDIR} and install files to";
618 echo " the temproot environment";
623 # Only set up files that are crucial to {build|install}world
624 { mkdir -p ${TEMPROOT}/etc &&
625 cp -p ${SOURCEDIR}/etc/master.passwd ${TEMPROOT}/etc &&
626 cp -p ${SOURCEDIR}/etc/group ${TEMPROOT}/etc;} ||
628 echo ' *** FATAL ERROR: Cannot copy files to the temproot environment';
634 # Doing the inventory and removing files that we don't want to compare only
635 # makes sense if we are not doing a rerun, since we have no way of knowing
636 # what happened to the files during previous incarnations.
641 echo ' *** The following files exist only in the installed version of'
642 echo " ${DESTDIR}/etc. In the vast majority of cases these files"
643 echo ' are necessary parts of the system and should not be deleted.'
644 echo ' However because these files are not updated by this process you'
645 echo ' might want to verify their status before rebooting your system.'
648 diff -qr ${DESTDIR}/etc ${TEMPROOT}/etc | grep "^Only in ${DESTDIR}/etc" | ${PAGER}
654 # Avoid comparing the motd if the user specifies it in .mergemasterrc
655 # Compatibility shim to be removed in FreeBSD 9.x
656 case "${IGNORE_MOTD}" in
658 *) IGNORE_FILES="${IGNORE_FILES} /etc/motd"
660 echo "*** You have the IGNORE_MOTD option set in your mergemaster rc file."
661 echo " This option is deprecated in favor of the IGNORE_FILES option."
662 echo " Please update your rc file accordingly."
668 # Avoid comparing the following user specified files
669 for file in ${IGNORE_FILES}; do
670 test -e ${TEMPROOT}/${file} && unlink ${TEMPROOT}/${file}
673 # We really don't want to have to deal with files like login.conf.db, pwd.db,
674 # or spwd.db. Instead, we want to compare the text versions, and run *_mkdb.
675 # Prompt the user to do so below, as needed.
677 rm -f ${TEMPROOT}/etc/*.db ${TEMPROOT}/etc/passwd
679 # We only need to compare things like freebsd.cf once
680 find ${TEMPROOT}/usr/obj -type f -delete 2>/dev/null
682 # Delete stuff we do not need to keep the mtree database small,
683 # and to make the actual comparison faster.
684 find ${TEMPROOT}/usr -type l -delete 2>/dev/null
685 find ${TEMPROOT} -type f -size 0 -delete 2>/dev/null
686 find -d ${TEMPROOT} -type d -empty -delete 2>/dev/null
688 # Build the mtree database in a temporary location.
689 case "${PRE_WORLD}" in
690 '') MTREENEW=`mktemp -t mergemaster.mtree`
691 mtree -ci -p ${TEMPROOT} -k size,md5digest > ${MTREENEW} 2>/dev/null
693 *) # We don't want to mess with the mtree database on a pre-world run or
694 # when re-scanning a previously-built tree.
697 ;; # End of the "RERUN" test
700 # Get ready to start comparing files
702 # Check umask if not specified on the command line,
703 # and we are not doing an autorun
705 if [ -z "${NEW_UMASK}" -a -z "${AUTO_RUN}" ]; then
707 case "${USER_UMASK}" in
711 echo " *** Your umask is currently set to ${USER_UMASK}. By default, this script"
712 echo " installs all files with the same user, group and modes that"
713 echo " they are created with by ${SOURCEDIR}/etc/Makefile, compared to"
714 echo " a umask of 022. This umask allows world read permission when"
715 echo " the file's default permissions have it."
717 echo " No world permissions can sometimes cause problems. A umask of"
718 echo " 022 will restore the default behavior, but is not mandatory."
719 echo " /etc/master.passwd is a special case. Its file permissions"
720 echo " will be 600 (rw-------) if installed."
722 echo -n "What umask should I use? [${USER_UMASK}] "
725 NEW_UMASK="${NEW_UMASK:-$USER_UMASK}"
731 CONFIRMED_UMASK=${NEW_UMASK:-0022}
734 # Warn users who still have old rc files
736 for file in atm devfs diskless1 diskless2 network network6 pccard \
737 serial syscons sysctl alpha amd64 i386 ia64 sparc64; do
738 if [ -f "${DESTDIR}/etc/rc.${file}" ]; then
744 case "${OLD_RC_PRESENT}" in
747 echo " *** There are elements of the old rc system in ${DESTDIR}/etc/."
749 echo ' While these scripts will not hurt anything, they are not'
750 echo ' functional on an up to date system, and can be removed.'
753 case "${AUTO_RUN}" in
755 echo -n 'Move these files to /var/tmp/mergemaster/old_rc? [yes] '
758 case "${MOVE_OLD_RC}" in
761 mkdir -p /var/tmp/mergemaster/old_rc
762 for file in atm devfs diskless1 diskless2 network network6 pccard \
763 serial syscons sysctl alpha amd64 i386 ia64 sparc64; do
764 if [ -f "${DESTDIR}/etc/rc.${file}" ]; then
765 mv ${DESTDIR}/etc/rc.${file} /var/tmp/mergemaster/old_rc/
768 echo ' The files have been moved'
777 # Use the umask/mode information to install the files
778 # Create directories as needed
781 echo "*** FATAL ERROR: Unable to install ${1} to ${2}"
786 do_install_and_rm () {
787 case "${PRESERVE_FILES}" in
789 if [ -f "${3}/${2##*/}" ]; then
790 mkdir -p ${PRESERVE_FILES_DIR}/${2%/*}
791 cp ${3}/${2##*/} ${PRESERVE_FILES_DIR}/${2%/*}
796 if [ ! -d "${3}/${2##*/}" ]; then
797 if install -m ${1} ${2} ${3}; then
800 install_error ${2} ${3}
803 install_error ${2} ${3}
807 # 4095 = "obase=10;ibase=8;07777" | bc
810 OCTAL=$(( ~$(echo "obase=10; ibase=8; ${CONFIRMED_UMASK}" | bc) & 4095 &
811 $(echo "obase=10; ibase=8; $(stat -f "%OMp%OLp" ${1})" | bc) ))
812 printf "%04o\n" ${OCTAL}
818 INSTALL_DIR=${INSTALL_DIR%/*}
820 case "${INSTALL_DIR}" in
826 if [ -n "${DESTDIR}${INSTALL_DIR}" -a ! -d "${DESTDIR}${INSTALL_DIR}" ]; then
827 DIR_MODE=`find_mode "${TEMPROOT}/${INSTALL_DIR}"`
828 install -d -o root -g wheel -m "${DIR_MODE}" "${DESTDIR}${INSTALL_DIR}" ||
829 install_error $1 ${DESTDIR}${INSTALL_DIR}
832 FILE_MODE=`find_mode "${1}"`
834 if [ ! -x "${1}" ]; then
843 do_install_and_rm 600 "${1}" "${DESTDIR}${INSTALL_DIR}"
850 # install will unlink the file before it installs the new one,
851 # so we have to restore/create the link afterwards.
853 st_nlink=0 # In case the file does not yet exist
854 eval $(stat -s ${DESTDIR}${COMPFILE#.} 2>/dev/null)
856 do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}"
858 if [ -n "${AUTO_INSTALL}" -a $st_nlink -gt 1 ]; then
861 case "${LINK_EXPLAINED}" in
863 echo " *** Historically BSD derived systems have had a"
864 echo " hard link from /.cshrc and /.profile to"
865 echo " their namesakes in /root. Please indicate"
866 echo " your preference below for bringing your"
867 echo " installed files up to date."
873 echo " Use 'd' to delete the temporary ${COMPFILE}"
874 echo " Use 'l' to delete the existing ${DESTDIR}/root/${COMPFILE##*/} and create the link"
876 echo " Default is to leave the temporary file to deal with by hand"
878 echo -n " How should I handle ${COMPFILE}? [Leave it to install later] "
882 case "${HANDLE_LINK}" in
886 echo " *** Deleting ${COMPFILE}"
890 unlink ${DESTDIR}/root/${COMPFILE##*/}
891 if ln ${DESTDIR}${COMPFILE#.} ${DESTDIR}/root/${COMPFILE##*/}; then
892 echo " *** Link from ${DESTDIR}${COMPFILE#.} to ${DESTDIR}/root/${COMPFILE##*/} installed successfully"
894 echo " *** Error linking ${DESTDIR}${COMPFILE#.} to ${DESTDIR}/root/${COMPFILE##*/}"
895 echo " *** ${COMPFILE} will remain for your consideration"
899 echo " *** ${COMPFILE} will remain for your consideration"
906 case "${DONT_INSTALL}" in
908 do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}"
914 else # File matched -x
915 do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}"
920 if [ ! -d "${TEMPROOT}" ]; then
921 echo "*** FATAL ERROR: The temproot directory (${TEMPROOT})"
922 echo ' has disappeared!'
928 echo "*** Beginning comparison"
931 # Pre-world does not populate /etc/rc.d.
932 # It is very possible that a previous run would have deleted files in
933 # ${TEMPROOT}/etc/rc.d, thus creating a lot of false positives.
934 if [ -z "${PRE_WORLD}" -a -z "${RERUN}" ]; then
935 echo " *** Checking ${DESTDIR}/etc/rc.d for stale files"
937 cd "${DESTDIR}/etc/rc.d" &&
939 if [ ! -e "${TEMPROOT}/etc/rc.d/${file}" ]; then
940 STALE_RC_FILES="${STALE_RC_FILES} ${file}"
943 case "${STALE_RC_FILES}" in
945 echo ' *** No stale files found'
948 echo " *** The following files exist in ${DESTDIR}/etc/rc.d but not in"
949 echo " ${TEMPROOT}/etc/rc.d/:"
951 echo "${STALE_RC_FILES}"
953 echo ' The presence of stale files in this directory can cause the'
954 echo ' dreaded unpredictable results, and therefore it is highly'
955 echo ' recommended that you delete them.'
956 case "${AUTO_RUN}" in
959 echo -n ' *** Delete them now? [n] '
960 read DELETE_STALE_RC_FILES
961 case "${DELETE_STALE_RC_FILES}" in
963 echo ' *** Deleting ... '
968 echo ' *** Files will not be deleted'
974 if [ -n "${DELETE_STALE_RC_FILES}" ]; then
975 echo ' *** Deleting ... '
987 if [ -r "${MM_PRE_COMPARE_SCRIPT}" ]; then
988 . "${MM_PRE_COMPARE_SCRIPT}"
991 # Things that were files/directories/links in one version can sometimes
992 # change to something else in a newer version. So we need to explicitly
993 # test for this, and warn the user if what we find does not match.
995 for COMPFILE in `find . | sort` ; do
996 if [ -e "${DESTDIR}${COMPFILE#.}" ]; then
997 INSTALLED_TYPE=`stat -f '%HT' ${DESTDIR}${COMPFILE#.}`
1001 TEMPROOT_TYPE=`stat -f '%HT' $COMPFILE`
1003 if [ ! "$TEMPROOT_TYPE" = "$INSTALLED_TYPE" ]; then
1004 [ "$COMPFILE" = '.' ] && continue
1005 TEMPROOT_TYPE=`echo $TEMPROOT_TYPE | tr [:upper:] [:lower:]`
1006 INSTALLED_TYPE=`echo $INSTALLED_TYPE | tr [:upper:] [:lower:]`
1008 echo "*** The installed file ${DESTDIR}${COMPFILE#.} has the type \"$INSTALLED_TYPE\""
1009 echo " but the new version has the type \"$TEMPROOT_TYPE\""
1011 echo " How would you like to handle this?"
1013 echo " Use 'r' to remove ${DESTDIR}${COMPFILE#.}"
1014 case "$TEMPROOT_TYPE" in
1016 TARGET=`readlink $COMPFILE`
1017 echo " and create a link to $TARGET in its place" ;;
1018 *) echo " You will be able to install it as a \"$TEMPROOT_TYPE\"" ;;
1021 echo " Use 'i' to ignore this"
1023 echo -n " How to proceed? [i] "
1026 [rR]) case "${PRESERVE_FILES}" in
1028 mv ${DESTDIR}${COMPFILE#.} ${PRESERVE_FILES_DIR}/ || exit 1 ;;
1029 *) rm -rf ${DESTDIR}${COMPFILE#.} ;;
1031 case "$TEMPROOT_TYPE" in
1032 'symbolic link') ln -sf $TARGET ${DESTDIR}${COMPFILE#.} ;;
1035 echo "*** See the man page about adding ${COMPFILE#.} to the list of IGNORE_FILES"
1036 press_to_continue ;;
1042 for COMPFILE in `find . -type f | sort`; do
1044 # First, check to see if the file exists in DESTDIR. If not, the
1045 # diff_loop function knows how to handle it.
1047 if [ ! -e "${DESTDIR}${COMPFILE#.}" ]; then
1048 case "${AUTO_RUN}" in
1053 case "${AUTO_INSTALL}" in
1055 # If this is an auto run, make it official
1056 echo " *** ${COMPFILE} will remain for your consideration"
1063 esac # Auto run test
1069 # Compare CVS $Id's first so if the file hasn't been modified
1070 # local changes will be ignored.
1071 # If the files have the same $Id, delete the one in temproot so the
1072 # user will have less to wade through if files are left to merge by hand.
1074 CVSID1=`grep "[$]${CVS_ID_TAG}:" ${DESTDIR}${COMPFILE#.} 2>/dev/null`
1075 CVSID2=`grep "[$]${CVS_ID_TAG}:" ${COMPFILE} 2>/dev/null` || CVSID2=none
1079 echo " *** Temp ${COMPFILE} and installed have the same CVS Id, deleting"
1086 # If the file is still here either because the $Ids are different, the
1087 # file doesn't have an $Id, or we're using STRICT mode; look at the diff.
1089 if [ -f "${COMPFILE}" ]; then
1091 # Do an absolute diff first to see if the files are actually different.
1092 # If they're not different, delete the one in temproot.
1094 if diff -q ${DIFF_OPTIONS} "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" > \
1095 /dev/null 2>&1; then
1096 echo " *** Temp ${COMPFILE} and installed are the same, deleting"
1099 # Ok, the files are different, so show the user where they differ.
1100 # Use user's choice of diff methods; and user's pager if they have one.
1102 # Use unified diffs by default. Context diffs give me a headache. :)
1104 # If the user chose the -F option, test for that before proceeding
1106 if [ -n "$FREEBSD_ID" ]; then
1107 if diff -q -I'[$]FreeBSD.*[$]' "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" > \
1108 /dev/null 2>&1; then
1109 if mm_install "${COMPFILE}"; then
1110 echo "*** Updated revision control Id for ${DESTDIR}${COMPFILE#.}"
1112 echo "*** Problem installing ${COMPFILE}, it will remain to merge by hand later"
1117 case "${AUTO_RUN}" in
1119 # prompt user to install/delete/merge changes
1123 # If this is an auto run, make it official
1124 echo " *** ${COMPFILE} will remain for your consideration"
1126 esac # Auto run test
1127 fi # Yes, the files are different
1128 fi # Yes, the file still remains to be checked
1129 done # This is for the for way up there at the beginning of the comparison
1132 echo "*** Comparison complete"
1134 if [ -s "${MTREENEW}" ]; then
1135 echo "*** Saving mtree database for future upgrades"
1136 test -e "${MTREEFILE}" && unlink ${MTREEFILE}
1137 mv ${MTREENEW} ${MTREEFILE}
1142 TEST_FOR_FILES=`find ${TEMPROOT} -type f -size +0 2>/dev/null`
1143 if [ -n "${TEST_FOR_FILES}" ]; then
1144 echo "*** Files that remain for you to merge by hand:"
1145 find "${TEMPROOT}" -type f -size +0 | sort
1148 case "${AUTO_RUN}" in
1150 echo -n "Do you wish to delete what is left of ${TEMPROOT}? [no] "
1152 case "${DEL_TEMPROOT}" in
1157 echo " *** ${TEMPROOT} will remain"
1164 echo "*** ${TEMPROOT} is empty, deleting"
1168 case "${AUTO_INSTALLED_FILES}" in
1171 case "${AUTO_RUN}" in
1175 echo '*** You chose the automatic install option for files that did not'
1176 echo ' exist on your system. The following were installed for you:'
1177 echo "${AUTO_INSTALLED_FILES}"
1182 echo '*** You chose the automatic install option for files that did not'
1183 echo ' exist on your system. The following were installed for you:'
1184 echo "${AUTO_INSTALLED_FILES}"
1190 case "${AUTO_UPGRADED_FILES}" in
1193 case "${AUTO_RUN}" in
1197 echo '*** You chose the automatic upgrade option for files that you did'
1198 echo ' not alter on your system. The following were upgraded for you:'
1199 echo "${AUTO_UPGRADED_FILES}"
1204 echo '*** You chose the automatic upgrade option for files that you did'
1205 echo ' not alter on your system. The following were upgraded for you:'
1206 echo "${AUTO_UPGRADED_FILES}"
1213 case "${AUTO_RUN}" in
1217 echo -n ' Would you like to run it now? y or n [n] '
1220 case "${YES_OR_NO}" in
1222 echo " Running ${1}"
1228 echo " *** Cancelled"
1230 echo " Make sure to run ${1} yourself"
1234 echo " *** Sorry, I do not understand your answer (${YES_OR_NO})"
1236 echo " Make sure to run ${1} yourself"
1243 case "${NEED_NEWALIASES}" in
1247 if [ -n "${DESTDIR}" ]; then
1248 echo "*** You installed a new aliases file into ${DESTDIR}/etc/mail, but"
1249 echo " the newaliases command is limited to the directories configured"
1250 echo " in sendmail.cf. Make sure to create your aliases database by"
1251 echo " hand when your sendmail configuration is done."
1253 echo "*** You installed a new aliases file, so make sure that you run"
1254 echo " '/usr/bin/newaliases' to rebuild your aliases database"
1255 run_it_now '/usr/bin/newaliases'
1260 case "${NEED_CAP_MKDB}" in
1264 echo "*** You installed a login.conf file, so make sure that you run"
1265 echo " '/usr/bin/cap_mkdb ${DESTDIR}/etc/login.conf'"
1266 echo " to rebuild your login.conf database"
1267 run_it_now "/usr/bin/cap_mkdb ${DESTDIR}/etc/login.conf"
1271 case "${NEED_PWD_MKDB}" in
1275 echo "*** You installed a new master.passwd file, so make sure that you run"
1276 if [ -n "${DESTDIR}" ]; then
1277 echo " '/usr/sbin/pwd_mkdb -d ${DESTDIR}/etc -p ${DESTDIR}/etc/master.passwd'"
1278 echo " to rebuild your password files"
1279 run_it_now "/usr/sbin/pwd_mkdb -d ${DESTDIR}/etc -p ${DESTDIR}/etc/master.passwd"
1281 echo " '/usr/sbin/pwd_mkdb -p /etc/master.passwd'"
1282 echo " to rebuild your password files"
1283 run_it_now '/usr/sbin/pwd_mkdb -p /etc/master.passwd'
1290 if [ -r "${MM_EXIT_SCRIPT}" ]; then
1291 . "${MM_EXIT_SCRIPT}"
1294 case "${COMP_CONFS}" in
1297 . ${DESTDIR}/etc/defaults/rc.conf
1300 echo "*** Comparing conf files: ${rc_conf_files}"
1302 for CONF_FILE in ${rc_conf_files}; do
1303 if [ -r "${DESTDIR}${CONF_FILE}" ]; then
1305 echo "*** From ${DESTDIR}${CONF_FILE}"
1306 echo "*** From ${DESTDIR}/etc/defaults/rc.conf"
1308 for RC_CONF_VAR in `grep -i ^[a-z] ${DESTDIR}${CONF_FILE} |
1309 cut -d '=' -f 1`; do
1311 grep -w ^${RC_CONF_VAR} ${DESTDIR}${CONF_FILE}
1312 grep -w ^${RC_CONF_VAR} ${DESTDIR}/etc/defaults/rc.conf ||
1313 echo ' * No default variable with this name'
1321 case "${PRE_WORLD}" in
1324 MAKE_CONF="${SOURCEDIR}/share/examples/etc/make.conf"
1327 echo '*** Comparing make variables'
1329 echo "*** From ${DESTDIR}/etc/make.conf"
1330 echo "*** From ${MAKE_CONF}"
1332 for MAKE_VAR in `grep -i ^[a-z] ${DESTDIR}/etc/make.conf | cut -d '=' -f 1`; do
1334 grep -w ^${MAKE_VAR} ${DESTDIR}/etc/make.conf
1335 grep -w ^#${MAKE_VAR} ${MAKE_CONF} ||
1336 echo ' * No example variable with this name'
1341 if [ -n "${PRESERVE_FILES}" ]; then
1342 find -d $PRESERVE_FILES_DIR -type d -empty -delete 2>/dev/null
1343 rmdir $PRESERVE_FILES_DIR 2>/dev/null