5 # Compare files created by /usr/src/etc/Makefile (or the directory
6 # the user specifies) with the currently installed copies.
8 # Copyright (c) 1998-2012 Douglas Barton, All rights reserved
9 # Please see detailed copyright below
11 PATH=/bin:/usr/bin:/usr/sbin
14 VERSION_NUMBER=`grep "[$]FreeBSD:" $0 | cut -d ' ' -f 4`
15 echo "mergemaster version ${VERSION_NUMBER}"
16 echo 'Usage: mergemaster [-scrvhpCP] [-a|[-iFU]] [--run-updates=always|never]'
17 echo ' [-m /path] [-t /path] [-d] [-u N] [-w N] [-A arch] [-D /path]'
19 echo " -s Strict comparison (diff every pair of files)"
20 echo " -c Use context diff instead of unified diff"
21 echo " -r Re-run on a previously cleaned directory (skip temproot creation)"
22 echo " -v Be more verbose about the process, include additional checks"
23 echo " -a Leave all files that differ to merge by hand"
24 echo " -h Display more complete help"
25 echo ' -i Automatically install files that do not exist in destination directory'
26 echo ' -p Pre-buildworld mode, only compares crucial files'
27 echo ' -F Install files that differ only by revision control Id ($FreeBSD)'
28 echo ' -C Compare local rc.conf variables to the defaults'
29 echo ' -P Preserve files that are overwritten'
30 echo " -U Attempt to auto upgrade files that have not been user modified"
31 echo ' ***DANGEROUS***'
32 echo ' --run-updates= Specify always or never to run newalises, pwd_mkdb, etc.'
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 installed version and ${COMPFILE}:"
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"
267 RUN_UPDATES=`echo ${var#--run-updates=} | tr [:upper:] [:lower:]`
270 newopts="$newopts $var"
278 # Check the command line options
280 while getopts ":ascrvhipCPm:t:du:w:D:A:FU" COMMAND_LINE_ARGUMENT ; do
281 case "${COMMAND_LINE_ARGUMENT}" in
283 ARCHSTRING='TARGET_ARCH='${OPTARG}
302 case "${AUTO_RUN}" in
336 TEMPROOT=${TEMPROOT}.`date +%m%d.%H.%M`
342 SCREEN_WIDTH=${OPTARG}
354 if [ -n "$AUTO_RUN" ]; then
355 if [ -n "$FREEBSD_ID" -o -n "$AUTO_UPGRADE" -o -n "$AUTO_INSTALL" ]; then
357 echo "*** You have included the -a option along with one or more options"
358 echo ' that indicate that you wish mergemaster to actually make updates'
359 echo ' (-F, -U, or -i), however these options are not compatible.'
360 echo ' Please read mergemaster(8) for more information.'
366 # Assign the location of the mtree database
368 MTREEDB=${MTREEDB:-${DESTDIR}/var/db}
369 MTREEFILE="${MTREEDB}/mergemaster.mtree"
371 # Don't force the user to set this in the mergemaster rc file
372 if [ -n "${PRESERVE_FILES}" -a -z "${PRESERVE_FILES_DIR}" ]; then
373 PRESERVE_FILES_DIR=/var/tmp/mergemaster/preserved-files-`date +%y%m%d-%H%M%S`
374 mkdir -p ${PRESERVE_FILES_DIR}
377 # Check for the mtree database in DESTDIR
378 case "${AUTO_UPGRADE}" in
379 '') ;; # If the option is not set no need to run the test or warn the user
381 if [ ! -s "${MTREEFILE}" ]; then
383 echo "*** Unable to find mtree database (${MTREEFILE})."
384 echo " Skipping auto-upgrade on this run."
385 echo " It will be created for the next run when this one is complete."
387 case "${AUTO_RUN}" in
397 if [ -e "${DESTDIR}/etc/fstab" ]; then
398 if grep -q nodev ${DESTDIR}/etc/fstab; then
400 echo "*** You have the deprecated 'nodev' option in ${DESTDIR}/etc/fstab."
401 echo " This can prevent the filesystem from being mounted on reboot."
402 echo " Please update your fstab before continuing."
403 echo " See fstab(5) for more information."
411 # If the user has a pager defined, make sure we can run it
413 case "${DONT_CHECK_PAGER}" in
416 while ! type "${PAGER%% *}" >/dev/null; do
417 echo " *** Your PAGER environment variable specifies '${PAGER}', but"
418 echo " due to the limited PATH that I use for security reasons,"
419 echo " I cannot execute it. So, what would you like to do?"
421 echo " Use 'e' to exit mergemaster and fix your PAGER variable"
422 echo " Use 'l' to set PAGER to 'less' for this run"
423 echo " Use 'm' to use plain old 'more' as your PAGER for this run"
425 echo " or you may type an absolute path to PAGER for this run"
427 echo " Default is to use 'less' "
429 echo -n "What should I do? [Use 'less'] "
432 case "${FIXPAGER}" in
447 echo "invalid choice: ${FIXPAGER}"
452 if [ -n "${PAGER}" ]; then
458 # If user has a pager defined, or got assigned one above, use it.
463 if [ -n "${VERBOSE}" -a ! "${PAGER}" = "less" ]; then
464 echo " *** You have ${PAGER} defined as your pager so we will use that"
469 # Assign the diff flag once so we will not have to keep testing it
471 DIFF_FLAG=${DIFF_FLAG:--u}
473 # Assign the source directory
475 SOURCEDIR=${SOURCEDIR:-/usr/src}
476 if [ ! -f ${SOURCEDIR}/Makefile.inc1 -a \
477 -f ${SOURCEDIR}/../Makefile.inc1 ]; then
478 echo " *** The source directory you specified (${SOURCEDIR})"
479 echo " will be reset to ${SOURCEDIR}/.."
482 SOURCEDIR=${SOURCEDIR}/..
484 if [ ! -f ${SOURCEDIR}/Makefile.inc1 ]; then
485 echo "*** ${SOURCEDIR} was not found."
486 if [ -f ./Makefile.inc1 ]; then
487 echo " Found Makefile.inc1 in the current directory."
488 echo -n " Would you like to set SOURCEDIR to $(pwd)? [no and exit] "
492 echo " *** Setting SOURCEDIR to $(pwd)"
496 echo " **** No suitable ${SOURCEDIR} found, exiting"
501 echo " **** No suitable ${SOURCEDIR} found, exiting"
505 SOURCEDIR=$(realpath "$SOURCEDIR")
507 # Setup make to use system files from SOURCEDIR
508 MM_MAKE="make ${ARCHSTRING} -m ${SOURCEDIR}/share/mk -DNO_FILEMON"
509 MM_MAKE="${MM_MAKE} -j$(/sbin/sysctl -n hw.ncpu)"
511 # Check DESTDIR against the mergemaster mtree database to see what
512 # files the user changed from the reference files.
514 if [ -n "${AUTO_UPGRADE}" -a -s "${MTREEFILE}" ]; then
515 # Force FreeBSD 9 compatible output when available.
516 if mtree -F freebsd9 -c -p /var/empty/ > /dev/null 2>&1; then
517 MTREE_FLAVOR="-F freebsd9"
522 for file in `mtree -eqL ${MTREE_FLAVOR} -f ${MTREEFILE} -p ${DESTDIR}/ \
523 2>/dev/null | awk '($2 == "changed") {print $1}'`; do
524 if [ -f "${DESTDIR}/$file" ]; then
525 CHANGED="${CHANGED}${DESTDIR}/${file}:"
528 [ "$CHANGED" = ':' ] && unset CHANGED
531 # Check the width of the user's terminal
536 0|'') ;; # No-op, since the input is not valid
538 case "${SCREEN_WIDTH}" in
539 '') SCREEN_WIDTH="${w}" ;;
540 "${w}") ;; # No-op, since they are the same
542 echo -n "*** You entered ${SCREEN_WIDTH} as your screen width, but stty "
543 echo "thinks it is ${w}."
545 echo -n "What would you like to use? [${w}] "
547 case "${SCREEN_WIDTH}" in
548 '') SCREEN_WIDTH="${w}" ;;
555 # Define what $Id tag to look for to aid portability.
560 rm -rf "${TEMPROOT}" 2>/dev/null
561 chflags -R 0 "${TEMPROOT}" 2>/dev/null
562 rm -rf "${TEMPROOT}" || { echo "*** Unable to delete ${TEMPROOT}"; exit 1; }
567 # Set up the loop to test for the existence of the
568 # temp root directory.
571 while [ "${TEST_TEMP_ROOT}" = "yes" ]; do
572 if [ -d "${TEMPROOT}" ]; then
573 echo "*** The directory specified for the temporary root environment,"
574 echo " ${TEMPROOT}, exists. This can be a security risk if untrusted"
575 echo " users have access to the system."
577 case "${AUTO_RUN}" in
579 echo " Use 'd' to delete the old ${TEMPROOT} and continue"
580 echo " Use 't' to select a new temporary root directory"
581 echo " Use 'e' to exit mergemaster"
583 echo " Default is to use ${TEMPROOT} as is"
585 echo -n "How should I deal with this? [Use the existing ${TEMPROOT}] "
588 case "${DELORNOT}" in
591 echo " *** Deleting the old ${TEMPROOT}"
597 echo " *** Enter new directory name for temporary root environment"
605 echo " *** Leaving ${TEMPROOT} intact"
611 echo "invalid choice: ${DELORNOT}"
617 # If this is an auto-run, try a hopefully safe alternative then
619 TEMPROOT=/var/tmp/temproot.`date +%m%d.%H.%M.%S`
627 echo "*** Creating the temporary root environment in ${TEMPROOT}"
629 if mkdir -p "${TEMPROOT}"; then
630 echo " *** ${TEMPROOT} ready for use"
633 if [ ! -d "${TEMPROOT}" ]; then
635 echo " *** FATAL ERROR: Cannot create ${TEMPROOT}"
640 echo " *** Creating and populating directory structure in ${TEMPROOT}"
650 case "${PRE_WORLD}" in
656 ${MM_MAKE} DESTDIR=${DESTDIR} distrib-dirs >/dev/null
659 ${MM_MAKE} DESTDIR=${TEMPROOT} distrib-dirs >/dev/null &&
660 ${MM_MAKE} _obj SUBDIR_OVERRIDE=etc >/dev/null &&
661 ${MM_MAKE} everything SUBDIR_OVERRIDE=etc >/dev/null &&
662 ${MM_MAKE} DESTDIR=${TEMPROOT} distribution >/dev/null;} ||
664 echo " *** FATAL ERROR: Cannot 'cd' to ${SOURCEDIR} and install files to";
665 echo " the temproot environment";
670 # Only set up files that are crucial to {build|install}world
671 { mkdir -p ${TEMPROOT}/etc &&
672 cp -p ${SOURCEDIR}/etc/master.passwd ${TEMPROOT}/etc &&
673 install -p -o root -g wheel -m 0644 ${SOURCEDIR}/etc/group ${TEMPROOT}/etc;} ||
675 echo ' *** FATAL ERROR: Cannot copy files to the temproot environment';
681 # Doing the inventory and removing files that we don't want to compare only
682 # makes sense if we are not doing a rerun, since we have no way of knowing
683 # what happened to the files during previous incarnations.
688 echo ' *** The following files exist only in the installed version of'
689 echo " ${DESTDIR}/etc. In the vast majority of cases these files"
690 echo ' are necessary parts of the system and should not be deleted.'
691 echo ' However because these files are not updated by this process you'
692 echo ' might want to verify their status before rebooting your system.'
695 diff -qr ${DESTDIR}/etc ${TEMPROOT}/etc | grep "^Only in ${DESTDIR}/etc" | ${PAGER}
701 case "${IGNORE_MOTD}" in
705 echo "*** You have the IGNORE_MOTD option set in your mergemaster rc file."
706 echo " This option is deprecated in favor of the IGNORE_FILES option."
707 echo " Please update your rc file accordingly."
713 # Avoid comparing the following user specified files
714 for file in ${IGNORE_FILES}; do
715 test -e ${TEMPROOT}/${file} && unlink ${TEMPROOT}/${file}
718 # We really don't want to have to deal with files like login.conf.db, pwd.db,
719 # or spwd.db. Instead, we want to compare the text versions, and run *_mkdb.
720 # Prompt the user to do so below, as needed.
722 rm -f ${TEMPROOT}/etc/*.db ${TEMPROOT}/etc/passwd \
723 ${TEMPROOT}/var/db/services.db
725 # We only need to compare things like freebsd.cf once
726 find ${TEMPROOT}/usr/obj -type f -delete 2>/dev/null
728 # Delete stuff we do not need to keep the mtree database small,
729 # and to make the actual comparison faster.
730 find ${TEMPROOT}/usr -type l -delete 2>/dev/null
731 find ${TEMPROOT} -type f -size 0 -delete 2>/dev/null
732 find -d ${TEMPROOT} -type d -empty -mindepth 1 -delete 2>/dev/null
734 # Build the mtree database in a temporary location.
735 case "${PRE_WORLD}" in
736 '') MTREENEW=`mktemp -t mergemaster.mtree`
737 mtree -nci -p ${TEMPROOT} -k size,md5digest > ${MTREENEW} 2>/dev/null
739 *) # We don't want to mess with the mtree database on a pre-world run or
740 # when re-scanning a previously-built tree.
743 ;; # End of the "RERUN" test
746 # Get ready to start comparing files
748 # Check umask if not specified on the command line,
749 # and we are not doing an autorun
751 if [ -z "${NEW_UMASK}" -a -z "${AUTO_RUN}" ]; then
753 case "${USER_UMASK}" in
757 echo " *** Your umask is currently set to ${USER_UMASK}. By default, this script"
758 echo " installs all files with the same user, group and modes that"
759 echo " they are created with by ${SOURCEDIR}/etc/Makefile, compared to"
760 echo " a umask of 022. This umask allows world read permission when"
761 echo " the file's default permissions have it."
763 echo " No world permissions can sometimes cause problems. A umask of"
764 echo " 022 will restore the default behavior, but is not mandatory."
765 echo " /etc/master.passwd is a special case. Its file permissions"
766 echo " will be 600 (rw-------) if installed."
768 echo -n "What umask should I use? [${USER_UMASK}] "
771 NEW_UMASK="${NEW_UMASK:-$USER_UMASK}"
777 CONFIRMED_UMASK=${NEW_UMASK:-0022}
780 # Warn users who still have old rc files
782 for file in atm devfs diskless1 diskless2 network network6 pccard \
783 serial syscons sysctl alpha amd64 i386; do
784 if [ -f "${DESTDIR}/etc/rc.${file}" ]; then
790 case "${OLD_RC_PRESENT}" in
793 echo " *** There are elements of the old rc system in ${DESTDIR}/etc/."
795 echo ' While these scripts will not hurt anything, they are not'
796 echo ' functional on an up to date system, and can be removed.'
799 case "${AUTO_RUN}" in
801 echo -n 'Move these files to /var/tmp/mergemaster/old_rc? [yes] '
804 case "${MOVE_OLD_RC}" in
807 mkdir -p /var/tmp/mergemaster/old_rc
808 for file in atm devfs diskless1 diskless2 network network6 pccard \
809 serial syscons sysctl alpha amd64 i386; do
810 if [ -f "${DESTDIR}/etc/rc.${file}" ]; then
811 mv ${DESTDIR}/etc/rc.${file} /var/tmp/mergemaster/old_rc/
814 echo ' The files have been moved'
823 # Use the umask/mode information to install the files
824 # Create directories as needed
827 echo "*** FATAL ERROR: Unable to install ${1} to ${2}"
832 do_install_and_rm () {
833 case "${PRESERVE_FILES}" in
835 if [ -f "${3}/${2##*/}" ]; then
836 mkdir -p ${PRESERVE_FILES_DIR}/${2%/*}
837 cp ${3}/${2##*/} ${PRESERVE_FILES_DIR}/${2%/*}
842 if [ ! -d "${3}/${2##*/}" ]; then
843 if install -m ${1} ${2} ${3}; then
846 install_error ${2} ${3}
849 install_error ${2} ${3}
853 # 4095 = "obase=10;ibase=8;07777" | bc
856 OCTAL=$(( ~$(echo "obase=10; ibase=8; ${CONFIRMED_UMASK}" | bc) & 4095 &
857 $(echo "obase=10; ibase=8; $(stat -f "%OMp%OLp" ${1})" | bc) ))
858 printf "%04o\n" ${OCTAL}
864 INSTALL_DIR=${INSTALL_DIR%/*}
866 case "${INSTALL_DIR}" in
872 if [ -n "${DESTDIR}${INSTALL_DIR}" -a ! -d "${DESTDIR}${INSTALL_DIR}" ]; then
873 DIR_MODE=`find_mode "${TEMPROOT}/${INSTALL_DIR}"`
874 install -d -o root -g wheel -m "${DIR_MODE}" "${DESTDIR}${INSTALL_DIR}" ||
875 install_error $1 ${DESTDIR}${INSTALL_DIR}
878 FILE_MODE=`find_mode "${1}"`
880 if [ ! -x "${1}" ]; then
885 /usr/share/certs/trusted/* | /usr/share/certs/untrusted/*)
892 NEED_SERVICES_MKDB=yes
895 do_install_and_rm 600 "${1}" "${DESTDIR}${INSTALL_DIR}"
902 # install will unlink the file before it installs the new one,
903 # so we have to restore/create the link afterwards.
905 st_nlink=0 # In case the file does not yet exist
906 eval $(stat -s ${DESTDIR}${COMPFILE#.} 2>/dev/null)
908 do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}"
910 if [ -n "${AUTO_INSTALL}" -a $st_nlink -gt 1 ]; then
913 case "${LINK_EXPLAINED}" in
915 echo " *** Historically BSD derived systems have had a"
916 echo " hard link from /.cshrc and /.profile to"
917 echo " their namesakes in /root. Please indicate"
918 echo " your preference below for bringing your"
919 echo " installed files up to date."
925 echo " Use 'd' to delete the temporary ${COMPFILE}"
926 echo " Use 'l' to delete the existing ${DESTDIR}/root/${COMPFILE##*/} and create the link"
928 echo " Default is to leave the temporary file to deal with by hand"
930 echo -n " How should I handle ${COMPFILE}? [Leave it to install later] "
934 case "${HANDLE_LINK}" in
938 echo " *** Deleting ${COMPFILE}"
942 unlink ${DESTDIR}/root/${COMPFILE##*/}
943 if ln ${DESTDIR}${COMPFILE#.} ${DESTDIR}/root/${COMPFILE##*/}; then
944 echo " *** Link from ${DESTDIR}${COMPFILE#.} to ${DESTDIR}/root/${COMPFILE##*/} installed successfully"
946 echo " *** Error linking ${DESTDIR}${COMPFILE#.} to ${DESTDIR}/root/${COMPFILE##*/}"
947 echo " *** ${COMPFILE} will remain for your consideration"
951 echo " *** ${COMPFILE} will remain for your consideration"
958 case "${DONT_INSTALL}" in
960 do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}"
966 else # File matched -x
967 do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}"
972 if [ ! -d "${TEMPROOT}" ]; then
973 echo "*** FATAL ERROR: The temproot directory (${TEMPROOT})"
974 echo ' has disappeared!'
980 echo "*** Beginning comparison"
983 # Pre-world does not populate /etc/rc.d.
984 # It is very possible that a previous run would have deleted files in
985 # ${TEMPROOT}/etc/rc.d, thus creating a lot of false positives.
986 if [ -z "${PRE_WORLD}" -a -z "${RERUN}" ]; then
987 echo " *** Checking ${DESTDIR}/etc/rc.d for stale files"
989 cd "${DESTDIR}/etc/rc.d" &&
991 if [ ! -e "${TEMPROOT}/etc/rc.d/${file}" ]; then
992 STALE_RC_FILES="${STALE_RC_FILES} ${file}"
995 case "${STALE_RC_FILES}" in
997 echo ' *** No stale files found'
1000 echo " *** The following files exist in ${DESTDIR}/etc/rc.d but not in"
1001 echo " ${TEMPROOT}/etc/rc.d/:"
1003 echo "${STALE_RC_FILES}"
1005 echo ' The presence of stale files in this directory can cause the'
1006 echo ' dreaded unpredictable results, and therefore it is highly'
1007 echo ' recommended that you delete them.'
1008 case "${AUTO_RUN}" in
1011 echo -n ' *** Delete them now? [n] '
1012 read DELETE_STALE_RC_FILES
1013 case "${DELETE_STALE_RC_FILES}" in
1015 echo ' *** Deleting ... '
1016 rm ${STALE_RC_FILES}
1020 echo ' *** Files will not be deleted'
1026 if [ -n "${DELETE_STALE_RC_FILES}" ]; then
1027 echo ' *** Deleting ... '
1028 rm ${STALE_RC_FILES}
1039 if [ -r "${MM_PRE_COMPARE_SCRIPT}" ]; then
1040 . "${MM_PRE_COMPARE_SCRIPT}"
1043 # Things that were files/directories/links in one version can sometimes
1044 # change to something else in a newer version. So we need to explicitly
1045 # test for this, and warn the user if what we find does not match.
1047 for COMPFILE in `find . | sort` ; do
1048 if [ -e "${DESTDIR}${COMPFILE#.}" ]; then
1049 INSTALLED_TYPE=`stat -f '%HT' ${DESTDIR}${COMPFILE#.}`
1053 TEMPROOT_TYPE=`stat -f '%HT' $COMPFILE`
1055 if [ ! "$TEMPROOT_TYPE" = "$INSTALLED_TYPE" ]; then
1056 [ "$COMPFILE" = '.' ] && continue
1057 TEMPROOT_TYPE=`echo $TEMPROOT_TYPE | tr [:upper:] [:lower:]`
1058 INSTALLED_TYPE=`echo $INSTALLED_TYPE | tr [:upper:] [:lower:]`
1060 echo "*** The installed file ${DESTDIR}${COMPFILE#.} has the type \"$INSTALLED_TYPE\""
1061 echo " but the new version has the type \"$TEMPROOT_TYPE\""
1063 echo " How would you like to handle this?"
1065 echo " Use 'r' to remove ${DESTDIR}${COMPFILE#.}"
1066 case "$TEMPROOT_TYPE" in
1068 TARGET=`readlink $COMPFILE`
1069 echo " and create a link to $TARGET in its place" ;;
1070 *) echo " You will be able to install it as a \"$TEMPROOT_TYPE\"" ;;
1073 echo " Use 'i' to ignore this"
1075 echo -n " How to proceed? [i] "
1078 [rR]) case "${PRESERVE_FILES}" in
1080 mv ${DESTDIR}${COMPFILE#.} ${PRESERVE_FILES_DIR}/ || exit 1 ;;
1081 *) rm -rf ${DESTDIR}${COMPFILE#.} ;;
1083 case "$TEMPROOT_TYPE" in
1084 'symbolic link') ln -sf $TARGET ${DESTDIR}${COMPFILE#.} ;;
1087 echo "*** See the man page about adding ${COMPFILE#.} to the list of IGNORE_FILES"
1088 press_to_continue ;;
1094 # Compare regular files
1095 for COMPFILE in `find . -type f | sort`; do
1097 # First, check to see if the file exists in DESTDIR. If not, the
1098 # diff_loop function knows how to handle it.
1100 if [ ! -e "${DESTDIR}${COMPFILE#.}" ]; then
1101 case "${AUTO_RUN}" in
1106 case "${AUTO_INSTALL}" in
1108 # If this is an auto run, make it official
1109 echo " *** ${COMPFILE} will remain for your consideration"
1116 esac # Auto run test
1122 # Compare $Id's first so if the file hasn't been modified
1123 # local changes will be ignored.
1124 # If the files have the same $Id, delete the one in temproot so the
1125 # user will have less to wade through if files are left to merge by hand.
1127 ID1=`grep "[$]${ID_TAG}:" ${DESTDIR}${COMPFILE#.} 2>/dev/null`
1128 ID2=`grep "[$]${ID_TAG}:" ${COMPFILE} 2>/dev/null` || ID2=none
1132 echo " *** Temp ${COMPFILE} and installed have the same Id, deleting"
1139 # If the file is still here either because the $Ids are different, the
1140 # file doesn't have an $Id, or we're using STRICT mode; look at the diff.
1142 if [ -f "${COMPFILE}" ]; then
1144 # Do an absolute diff first to see if the files are actually different.
1145 # If they're not different, delete the one in temproot.
1147 if diff -q ${DIFF_OPTIONS} "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" > \
1148 /dev/null 2>&1; then
1149 echo " *** Temp ${COMPFILE} and installed are the same, deleting"
1152 # Ok, the files are different, so show the user where they differ.
1153 # Use user's choice of diff methods; and user's pager if they have one.
1155 # Use unified diffs by default. Context diffs give me a headache. :)
1157 # If the user chose the -F option, test for that before proceeding
1159 if [ -n "$FREEBSD_ID" ]; then
1160 if diff -q -I'[$]FreeBSD.*[$]' "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" > \
1161 /dev/null 2>&1; then
1162 if mm_install "${COMPFILE}"; then
1163 echo "*** Updated revision control Id for ${DESTDIR}${COMPFILE#.}"
1165 echo "*** Problem installing ${COMPFILE}, it will remain to merge by hand later"
1170 case "${AUTO_RUN}" in
1172 # prompt user to install/delete/merge changes
1176 # If this is an auto run, make it official
1177 echo " *** ${COMPFILE} will remain for your consideration"
1179 esac # Auto run test
1180 fi # Yes, the files are different
1181 fi # Yes, the file still remains to be checked
1182 done # This is for the for way up there at the beginning of the comparison
1184 ask_answer_for_symbolic_link () {
1185 HANDLE_COMPSYMLINK=''
1187 echo " Use 'd' to delete the temporary ${COMPSYMLINK}"
1188 echo " Use 'i' to install the temporary ${COMPSYMLINK}"
1190 echo " Default is to leave the temporary symbolic link to deal with by hand"
1192 echo -n "How should I deal with this? [Leave it for later] "
1193 read HANDLE_COMPSYMLINK
1194 case ${HANDLE_COMPSYMLINK} in
1199 echo "invalid choice: ${HANDLE_COMPSYMLINK}"
1201 HANDLE_COMPSYMLINK=''
1207 install_symbolic_link () {
1208 rm -f ${DESTDIR}${COMPSYMLINK#.} > /dev/null 2>&1
1209 if [ -L ${DESTDIR}${COMPSYMLINK#.} ]; then
1212 cp -a ${COMPSYMLINK} ${DESTDIR}${COMPSYMLINK#.} > /dev/null 2>&1
1213 if [ ! -L ${DESTDIR}${COMPSYMLINK#.} ]; then
1219 handle_symbolic_link () {
1220 case ${HANDLE_COMPSYMLINK} in
1224 echo " *** Deleting ${COMPSYMLINK}"
1230 if install_symbolic_link; then
1232 echo " *** ${COMPSYMLINK} installed successfully"
1235 echo " *** Problem installing ${COMPSYMLINK}, it will remain to merge by hand"
1242 echo " *** ${COMPSYMLINK} will remain for your consideration"
1249 # Compare symblic links
1250 for COMPSYMLINK in `find . -type l | sort`; do
1251 if [ ! -L "${DESTDIR}${COMPSYMLINK#.}" ]; then
1252 if [ -n "${AUTO_RUN}" -a -z "${AUTO_INSTALL}" ]; then
1253 echo " *** ${COMPSYMLINK} will remain for your consideration"
1257 echo " *** There is no installed version of ${COMPSYMLINK}"
1259 if [ -n "${AUTO_INSTALL}" ]; then
1260 HANDLE_COMPSYMLINK="i"
1262 ask_answer_for_symbolic_link
1264 handle_symbolic_link
1265 if [ -n "${AUTO_INSTALL}" -a $? -eq 2 ]; then
1266 AUTO_INSTALLED_FILES="${AUTO_INSTALLED_FILES} ${DESTDIR}${COMPSYMLINK#.}
1270 elif [ $(readlink ${COMPSYMLINK}) = $(readlink ${DESTDIR}${COMPSYMLINK#.}) ]; then
1271 echo " *** Temp ${COMPSYMLINK} and installed are the same, deleting"
1274 if [ -n "${AUTO_RUN}" -a -z "${AUTO_UPGRADE}" ]; then
1275 echo " *** ${COMPSYMLINK} will remain for your consideration"
1279 echo " *** Target of temp symbolic link is different from that of installed one"
1280 echo " Temp (${COMPSYMLINK}): $(readlink ${COMPSYMLINK})"
1281 echo " Installed (${DESTDIR}${COMPSYMLINK#.})): $(readlink ${DESTDIR}${COMPSYMLINK#.})"
1283 if [ -n "${AUTO_UPGRADE}" ]; then
1284 HANDLE_COMPSYMLINK="i"
1286 ask_answer_for_symbolic_link
1288 handle_symbolic_link
1289 if [ -n "${AUTO_UPGRADE}" -a $? -eq 2 ]; then
1290 AUTO_UPGRADED_FILES="${AUTO_UPGRADED_FILES} ${DESTDIR}${COMPSYMLINK#.}
1298 echo "*** Comparison complete"
1300 if [ -s "${MTREENEW}" ]; then
1301 echo "*** Saving mtree database for future upgrades"
1302 test -e "${MTREEFILE}" && unlink ${MTREEFILE}
1303 mv ${MTREENEW} ${MTREEFILE}
1308 TEST_FOR_FILES=`find ${TEMPROOT} -type f -size +0 -or -type l 2>/dev/null`
1309 if [ -n "${TEST_FOR_FILES}" ]; then
1310 echo "*** Files that remain for you to merge by hand:"
1311 find "${TEMPROOT}" -type f -size +0 -or -type l | sort
1314 case "${AUTO_RUN}" in
1316 echo -n "Do you wish to delete what is left of ${TEMPROOT}? [no] "
1318 case "${DEL_TEMPROOT}" in
1323 echo " *** ${TEMPROOT} will remain"
1330 echo "*** ${TEMPROOT} is empty, deleting"
1334 case "${AUTO_INSTALLED_FILES}" in
1337 case "${AUTO_RUN}" in
1341 echo '*** You chose the automatic install option for files that did not'
1342 echo ' exist on your system. The following were installed for you:'
1343 echo "${AUTO_INSTALLED_FILES}"
1348 echo '*** You chose the automatic install option for files that did not'
1349 echo ' exist on your system. The following were installed for you:'
1350 echo "${AUTO_INSTALLED_FILES}"
1356 case "${AUTO_UPGRADED_FILES}" in
1359 case "${AUTO_RUN}" in
1363 echo '*** You chose the automatic upgrade option for files that you did'
1364 echo ' not alter on your system. The following were upgraded for you:'
1365 echo "${AUTO_UPGRADED_FILES}"
1370 echo '*** You chose the automatic upgrade option for files that you did'
1371 echo ' not alter on your system. The following were upgraded for you:'
1372 echo "${AUTO_UPGRADED_FILES}"
1379 [ -n "$AUTO_RUN" ] && return
1385 if [ "$RUN_UPDATES" = always ]; then
1387 elif [ "$RUN_UPDATES" = never ]; then
1390 echo -n ' Would you like to run it now? y or n [n] '
1396 echo " Running ${1}"
1402 if [ ! "$RUN_UPDATES" = never ]; then
1404 echo " *** Cancelled"
1407 echo " Make sure to run ${1} yourself"
1412 echo " *** Sorry, I do not understand your answer (${answer})"
1418 case "${NEED_NEWALIASES}" in
1422 if [ -n "${DESTDIR}" ]; then
1423 echo "*** You installed a new aliases file into ${DESTDIR}/etc/mail, but"
1424 echo " the newaliases command is limited to the directories configured"
1425 echo " in sendmail.cf. Make sure to create your aliases database by"
1426 echo " hand when your sendmail configuration is done."
1428 echo "*** You installed a new aliases file, so make sure that you run"
1429 echo " '/usr/bin/newaliases' to rebuild your aliases database"
1430 run_it_now '/usr/bin/newaliases'
1435 case "${NEED_CAP_MKDB}" in
1439 echo "*** You installed a login.conf file, so make sure that you run"
1440 echo " '/usr/bin/cap_mkdb ${DESTDIR}/etc/login.conf'"
1441 echo " to rebuild your login.conf database"
1442 run_it_now "/usr/bin/cap_mkdb ${DESTDIR}/etc/login.conf"
1446 case "${NEED_SERVICES_MKDB}" in
1450 echo "*** You installed a services file, so make sure that you run"
1451 echo " '/usr/sbin/services_mkdb -q -o ${DESTDIR}/var/db/services.db ${DESTDIR}/etc/services'"
1452 echo " to rebuild your services database"
1453 run_it_now "/usr/sbin/services_mkdb -q -o ${DESTDIR}/var/db/services.db ${DESTDIR}/etc/services"
1457 case "${NEED_PWD_MKDB}" in
1461 echo "*** You installed a new master.passwd file, so make sure that you run"
1462 if [ -n "${DESTDIR}" ]; then
1463 echo " '/usr/sbin/pwd_mkdb -d ${DESTDIR}/etc -p ${DESTDIR}/etc/master.passwd'"
1464 echo " to rebuild your password files"
1465 run_it_now "/usr/sbin/pwd_mkdb -d ${DESTDIR}/etc -p ${DESTDIR}/etc/master.passwd"
1467 echo " '/usr/sbin/pwd_mkdb -p /etc/master.passwd'"
1468 echo " to rebuild your password files"
1469 run_it_now '/usr/sbin/pwd_mkdb -p /etc/master.passwd'
1474 case "${NEED_CERTCTL}" in
1478 echo "*** You installed files in /etc/ssl/certs, so make sure that you run"
1479 if [ -n "${DESTDIR}" ]; then
1480 echo " 'env DESTDIR=${DESTDIR} /usr/sbin/certctl rehash'"
1481 echo " to rebuild your certificate authority database"
1482 run_it_now "env DESTDIR=${DESTDIR} /usr/sbin/certctl rehash"
1484 echo " '/usr/sbin/certctl rehash'"
1485 echo " to rebuild your certificate authority database"
1486 run_it_now "/usr/sbin/certctl rehash"
1491 if [ -e "${DESTDIR}/etc/localtime" -a ! -L "${DESTDIR}/etc/localtime" -a -z "${PRE_WORLD}" ]; then # Ignore if TZ == UTC
1493 [ -n "${DESTDIR}" ] && tzs_args="-C ${DESTDIR}"
1494 if [ -f "${DESTDIR}/var/db/zoneinfo" ]; then
1495 echo "*** Reinstalling `cat ${DESTDIR}/var/db/zoneinfo` as ${DESTDIR}/etc/localtime"
1496 tzsetup $tzs_args -r
1498 echo "*** There is no ${DESTDIR}/var/db/zoneinfo file to update ${DESTDIR}/etc/localtime."
1499 echo ' You should run tzsetup'
1500 run_it_now "tzsetup $tzs_args"
1506 if [ -r "${MM_EXIT_SCRIPT}" ]; then
1507 . "${MM_EXIT_SCRIPT}"
1510 case "${COMP_CONFS}" in
1513 . ${DESTDIR}/etc/defaults/rc.conf
1516 echo "*** Comparing conf files: ${rc_conf_files}"
1518 for CONF_FILE in ${rc_conf_files}; do
1519 if [ -r "${DESTDIR}${CONF_FILE}" ]; then
1521 echo "*** From ${DESTDIR}${CONF_FILE}"
1522 echo "*** From ${DESTDIR}/etc/defaults/rc.conf"
1524 for RC_CONF_VAR in `grep -i ^[a-z] ${DESTDIR}${CONF_FILE} |
1525 cut -d '=' -f 1`; do
1527 grep -w ^${RC_CONF_VAR} ${DESTDIR}${CONF_FILE}
1528 grep -w ^${RC_CONF_VAR} ${DESTDIR}/etc/defaults/rc.conf ||
1529 echo ' * No default variable with this name'
1537 if [ -n "${PRESERVE_FILES}" ]; then
1538 find -d $PRESERVE_FILES_DIR -type d -empty -delete 2>/dev/null
1539 rmdir $PRESERVE_FILES_DIR 2>/dev/null
1544 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1546 # Copyright (c) 1998-2012 Douglas Barton
1547 # All rights reserved.
1549 # Redistribution and use in source and binary forms, with or without
1550 # modification, are permitted provided that the following conditions
1552 # 1. Redistributions of source code must retain the above copyright
1553 # notice, this list of conditions and the following disclaimer.
1554 # 2. Redistributions in binary form must reproduce the above copyright
1555 # notice, this list of conditions and the following disclaimer in the
1556 # documentation and/or other materials provided with the distribution.
1558 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1559 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1560 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1561 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1562 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1563 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1564 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1565 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1566 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1567 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF