mergemaster.sh revision 205145
1#!/bin/sh 2 3# mergemaster 4 5# Compare files created by /usr/src/etc/Makefile (or the directory 6# the user specifies) with the currently installed copies. 7 8# Copyright 1998-2010 Douglas Barton 9# DougB@FreeBSD.org 10 11# $FreeBSD: head/usr.sbin/mergemaster/mergemaster.sh 205145 2010-03-14 05:22:46Z dougb $ 12 13PATH=/bin:/usr/bin:/usr/sbin 14 15display_usage () { 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]' 20 echo "Options:" 21 echo " -s Strict comparison (diff every pair of files)" 22 echo " -c Use context diff instead of unified diff" 23 echo " -r Re-run on a previously cleaned directory (skip temproot creation)" 24 echo " -v Be more verbose about the process, include additional checks" 25 echo " -a Leave all files that differ to merge by hand" 26 echo " -h Display more complete help" 27 echo ' -i Automatically install files that do not exist in destination directory' 28 echo ' -p Pre-buildworld mode, only compares crucial files' 29 echo ' -F Install files that differ only by revision control Id ($FreeBSD)' 30 echo ' -C Compare local rc.conf variables to the defaults' 31 echo ' -P Preserve files that are overwritten' 32 echo " -U Attempt to auto upgrade files that have not been user modified" 33 echo '' 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' 41 echo '' 42} 43 44display_help () { 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.' 50} 51 52# Loop allowing the user to use sdiff to merge files and display the merged 53# file. 54merge_loop () { 55 case "${VERBOSE}" in 56 '') ;; 57 *) 58 echo " *** Type h at the sdiff prompt (%) to get usage help" 59 ;; 60 esac 61 echo '' 62 MERGE_AGAIN=yes 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}" 68 INSTALL_MERGED=V 69 while [ "${INSTALL_MERGED}" = "v" -o "${INSTALL_MERGED}" = "V" ]; do 70 echo '' 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" 75 echo '' 76 echo -n " *** How should I deal with the merged file? [Leave it for later] " 77 read INSTALL_MERGED 78 79 case "${INSTALL_MERGED}" in 80 [iI]) 81 mv "${COMPFILE}.merged" "${COMPFILE}" 82 echo '' 83 if mm_install "${COMPFILE}"; then 84 echo " *** Merged version of ${COMPFILE} installed successfully" 85 else 86 echo " *** Problem installing ${COMPFILE}, it will remain to merge by hand later" 87 fi 88 unset MERGE_AGAIN 89 ;; 90 [rR]) 91 rm "${COMPFILE}.merged" 92 ;; 93 [vV]) 94 ${PAGER} "${COMPFILE}.merged" 95 ;; 96 '') 97 echo " *** ${COMPFILE} will remain for your consideration" 98 unset MERGE_AGAIN 99 ;; 100 *) 101 echo "invalid choice: ${INSTALL_MERGED}" 102 INSTALL_MERGED=V 103 ;; 104 esac 105 done 106 done 107} 108 109# Loop showing user differences between files, allow merge, skip or install 110# options 111diff_loop () { 112 113 HANDLE_COMPFILE=v 114 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 119 case "${CHANGED}" in 120 *:${DESTDIR}${COMPFILE#.}:*) ;; # File has been modified 121 *) 122 echo '' 123 echo " *** ${COMPFILE} has not been user modified." 124 echo '' 125 126 if mm_install "${COMPFILE}"; then 127 echo " *** ${COMPFILE} upgraded successfully" 128 echo '' 129 # Make the list print one file per line 130 AUTO_UPGRADED_FILES="${AUTO_UPGRADED_FILES} ${DESTDIR}${COMPFILE#.} 131" 132 else 133 echo " *** Problem upgrading ${COMPFILE}, it will remain to merge by hand" 134 fi 135 return 136 ;; 137 esac 138 fi 139 if [ "${HANDLE_COMPFILE}" = "v" -o "${HANDLE_COMPFILE}" = "V" ]; then 140 echo '' 141 echo ' ====================================================================== ' 142 echo '' 143 ( 144 echo " *** Displaying differences between ${COMPFILE} and installed version:" 145 echo '' 146 diff ${DIFF_FLAG} ${DIFF_OPTIONS} "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" 147 ) | ${PAGER} 148 echo '' 149 fi 150 else 151 echo '' 152 echo " *** There is no installed version of ${COMPFILE}" 153 echo '' 154 case "${AUTO_INSTALL}" in 155 [Yy][Ee][Ss]) 156 echo '' 157 if mm_install "${COMPFILE}"; then 158 echo " *** ${COMPFILE} installed successfully" 159 echo '' 160 # Make the list print one file per line 161 AUTO_INSTALLED_FILES="${AUTO_INSTALLED_FILES} ${DESTDIR}${COMPFILE#.} 162" 163 else 164 echo " *** Problem installing ${COMPFILE}, it will remain to merge by hand" 165 fi 166 return 167 ;; 168 *) 169 NO_INSTALLED=yes 170 ;; 171 esac 172 fi 173 174 echo " Use 'd' to delete the temporary ${COMPFILE}" 175 echo " Use 'i' to install the temporary ${COMPFILE}" 176 case "${NO_INSTALLED}" in 177 '') 178 echo " Use 'm' to merge the temporary and installed versions" 179 echo " Use 'v' to view the diff results again" 180 ;; 181 esac 182 echo '' 183 echo " Default is to leave the temporary file to deal with by hand" 184 echo '' 185 echo -n "How should I deal with this? [Leave it for later] " 186 read HANDLE_COMPFILE 187 188 case "${HANDLE_COMPFILE}" in 189 [dD]) 190 rm "${COMPFILE}" 191 echo '' 192 echo " *** Deleting ${COMPFILE}" 193 ;; 194 [iI]) 195 echo '' 196 if mm_install "${COMPFILE}"; then 197 echo " *** ${COMPFILE} installed successfully" 198 else 199 echo " *** Problem installing ${COMPFILE}, it will remain to merge by hand" 200 fi 201 ;; 202 [mM]) 203 case "${NO_INSTALLED}" in 204 '') 205 # interact with user to merge files 206 merge_loop 207 ;; 208 *) 209 echo '' 210 echo " *** There is no installed version of ${COMPFILE}" 211 echo '' 212 HANDLE_COMPFILE="NOT V" 213 ;; 214 esac # End of "No installed version of file but user selected merge" test 215 ;; 216 [vV]) 217 continue 218 ;; 219 '') 220 echo '' 221 echo " *** ${COMPFILE} will remain for your consideration" 222 ;; 223 *) 224 # invalid choice, show menu again. 225 echo "invalid choice: ${HANDLE_COMPFILE}" 226 echo '' 227 HANDLE_COMPFILE="NOT V" 228 continue 229 ;; 230 esac # End of "How to handle files that are different" 231 done 232 unset NO_INSTALLED 233 echo '' 234 case "${VERBOSE}" in 235 '') ;; 236 *) 237 sleep 3 238 ;; 239 esac 240} 241 242press_to_continue () { 243 local DISCARD 244 echo -n ' *** Press the [Enter] or [Return] key to continue ' 245 read DISCARD 246} 247 248# Set the default path for the temporary root environment 249# 250TEMPROOT='/var/tmp/temproot' 251 252# Read /etc/mergemaster.rc first so the one in $HOME can override 253# 254if [ -r /etc/mergemaster.rc ]; then 255 . /etc/mergemaster.rc 256fi 257 258# Read .mergemasterrc before command line so CLI can override 259# 260if [ -r "$HOME/.mergemasterrc" ]; then 261 . "$HOME/.mergemasterrc" 262fi 263 264# Check the command line options 265# 266while getopts ":ascrvhipCPm:t:du:w:D:A:FU" COMMAND_LINE_ARGUMENT ; do 267 case "${COMMAND_LINE_ARGUMENT}" in 268 A) 269 ARCHSTRING='TARGET_ARCH='${OPTARG} 270 ;; 271 F) 272 FREEBSD_ID=yes 273 ;; 274 U) 275 AUTO_UPGRADE=yes 276 ;; 277 s) 278 STRICT=yes 279 unset DIFF_OPTIONS 280 ;; 281 c) 282 DIFF_FLAG='-c' 283 ;; 284 r) 285 RERUN=yes 286 ;; 287 v) 288 case "${AUTO_RUN}" in 289 '') VERBOSE=yes ;; 290 esac 291 ;; 292 a) 293 AUTO_RUN=yes 294 unset VERBOSE 295 ;; 296 h) 297 display_usage 298 display_help 299 exit 0 300 ;; 301 i) 302 AUTO_INSTALL=yes 303 ;; 304 C) 305 COMP_CONFS=yes 306 ;; 307 P) 308 PRESERVE_FILES=yes 309 ;; 310 p) 311 PRE_WORLD=yes 312 unset COMP_CONFS 313 unset AUTO_RUN 314 ;; 315 m) 316 SOURCEDIR=${OPTARG} 317 ;; 318 t) 319 TEMPROOT=${OPTARG} 320 ;; 321 d) 322 TEMPROOT=${TEMPROOT}.`date +%m%d.%H.%M` 323 ;; 324 u) 325 NEW_UMASK=${OPTARG} 326 ;; 327 w) 328 SCREEN_WIDTH=${OPTARG} 329 ;; 330 D) 331 DESTDIR=${OPTARG} 332 ;; 333 *) 334 display_usage 335 exit 1 336 ;; 337 esac 338done 339 340if [ -n "$AUTO_RUN" ]; then 341 if [ -n "$FREEBSD_ID" -o -n "$AUTO_UPGRADE" -o -n "$AUTO_INSTALL" ]; then 342 echo '' 343 echo "*** You have included the -a option along with one or more options" 344 echo ' that indicate that you wish mergemaster to actually make updates' 345 echo ' (-F, -U, or -i), however these options are not compatible.' 346 echo ' Please read mergemaster(8) for more information.' 347 echo '' 348 exit 1 349 fi 350fi 351 352# Assign the location of the mtree database 353# 354MTREEDB=${MTREEDB:-${DESTDIR}/var/db} 355MTREEFILE="${MTREEDB}/mergemaster.mtree" 356 357# Don't force the user to set this in the mergemaster rc file 358if [ -n "${PRESERVE_FILES}" -a -z "${PRESERVE_FILES_DIR}" ]; then 359 PRESERVE_FILES_DIR=/var/tmp/mergemaster/preserved-files-`date +%y%m%d-%H%M%S` 360 mkdir -p ${PRESERVE_FILES_DIR} 361fi 362 363# Check for the mtree database in DESTDIR 364case "${AUTO_UPGRADE}" in 365'') ;; # If the option is not set no need to run the test or warn the user 366*) 367 if [ ! -s "${MTREEFILE}" ]; then 368 echo '' 369 echo "*** Unable to find mtree database (${MTREEFILE})." 370 echo " Skipping auto-upgrade on this run." 371 echo " It will be created for the next run when this one is complete." 372 echo '' 373 case "${AUTO_RUN}" in 374 '') 375 press_to_continue 376 ;; 377 esac 378 unset AUTO_UPGRADE 379 fi 380 ;; 381esac 382 383if [ -e "${DESTDIR}/etc/fstab" ]; then 384 if grep -q nodev ${DESTDIR}/etc/fstab; then 385 echo '' 386 echo "*** You have the deprecated 'nodev' option in ${DESTDIR}/etc/fstab." 387 echo " This can prevent the filesystem from being mounted on reboot." 388 echo " Please update your fstab before continuing." 389 echo " See fstab(5) for more information." 390 echo '' 391 exit 1 392 fi 393fi 394 395echo '' 396 397# If the user has a pager defined, make sure we can run it 398# 399case "${DONT_CHECK_PAGER}" in 400'') 401check_pager () { 402 while ! type "${PAGER%% *}" >/dev/null; do 403 echo " *** Your PAGER environment variable specifies '${PAGER}', but" 404 echo " due to the limited PATH that I use for security reasons," 405 echo " I cannot execute it. So, what would you like to do?" 406 echo '' 407 echo " Use 'e' to exit mergemaster and fix your PAGER variable" 408 if [ -x /usr/bin/less -o -x /usr/local/bin/less ]; then 409 echo " Use 'l' to set PAGER to 'less' for this run" 410 fi 411 echo " Use 'm' to use plain old 'more' as your PAGER for this run" 412 echo '' 413 echo " Default is to use plain old 'more' " 414 echo '' 415 echo -n "What should I do? [Use 'more'] " 416 read FIXPAGER 417 418 case "${FIXPAGER}" in 419 [eE]) 420 exit 0 421 ;; 422 [lL]) 423 if [ -x /usr/bin/less ]; then 424 PAGER=/usr/bin/less 425 elif [ -x /usr/local/bin/less ]; then 426 PAGER=/usr/local/bin/less 427 else 428 echo '' 429 echo " *** Fatal Error:" 430 echo " You asked to use 'less' as your pager, but I can't" 431 echo " find it in /usr/bin or /usr/local/bin" 432 exit 1 433 fi 434 ;; 435 [mM]|'') 436 PAGER=more 437 ;; 438 *) 439 echo '' 440 echo "invalid choice: ${FIXPAGER}" 441 esac 442 echo '' 443 done 444} 445 if [ -n "${PAGER}" ]; then 446 check_pager 447 fi 448 ;; 449esac 450 451# If user has a pager defined, or got assigned one above, use it. 452# If not, use more. 453# 454PAGER=${PAGER:-more} 455 456if [ -n "${VERBOSE}" -a ! "${PAGER}" = "more" ]; then 457 echo " *** You have ${PAGER} defined as your pager so we will use that" 458 echo '' 459 sleep 3 460fi 461 462# Assign the diff flag once so we will not have to keep testing it 463# 464DIFF_FLAG=${DIFF_FLAG:--u} 465 466# Assign the source directory 467# 468SOURCEDIR=${SOURCEDIR:-/usr/src} 469if [ ! -f ${SOURCEDIR}/Makefile.inc1 -a \ 470 -f ${SOURCEDIR}/../Makefile.inc1 ]; then 471 echo " *** The source directory you specified (${SOURCEDIR})" 472 echo " will be reset to ${SOURCEDIR}/.." 473 echo '' 474 sleep 3 475 SOURCEDIR=${SOURCEDIR}/.. 476fi 477 478# Setup make to use system files from SOURCEDIR 479MM_MAKE="make ${ARCHSTRING} -m ${SOURCEDIR}/share/mk" 480 481# Check DESTDIR against the mergemaster mtree database to see what 482# files the user changed from the reference files. 483# 484if [ -n "${AUTO_UPGRADE}" -a -s "${MTREEFILE}" ]; then 485 CHANGED=: 486 for file in `mtree -eqL -f ${MTREEFILE} -p ${DESTDIR}/ \ 487 2>/dev/null | awk '($2 == "changed") {print $1}'`; do 488 if [ -f "${DESTDIR}/$file" ]; then 489 CHANGED="${CHANGED}${DESTDIR}/${file}:" 490 fi 491 done 492 [ "$CHANGED" = ':' ] && unset CHANGED 493fi 494 495# Check the width of the user's terminal 496# 497if [ -t 0 ]; then 498 w=`tput columns` 499 case "${w}" in 500 0|'') ;; # No-op, since the input is not valid 501 *) 502 case "${SCREEN_WIDTH}" in 503 '') SCREEN_WIDTH="${w}" ;; 504 "${w}") ;; # No-op, since they are the same 505 *) 506 echo -n "*** You entered ${SCREEN_WIDTH} as your screen width, but stty " 507 echo "thinks it is ${w}." 508 echo '' 509 echo -n "What would you like to use? [${w}] " 510 read SCREEN_WIDTH 511 case "${SCREEN_WIDTH}" in 512 '') SCREEN_WIDTH="${w}" ;; 513 esac 514 ;; 515 esac 516 esac 517fi 518 519# Define what CVS $Id tag to look for to aid portability. 520# 521CVS_ID_TAG=FreeBSD 522 523delete_temproot () { 524 rm -rf "${TEMPROOT}" 2>/dev/null 525 chflags -R 0 "${TEMPROOT}" 2>/dev/null 526 rm -rf "${TEMPROOT}" || { echo "*** Unable to delete ${TEMPROOT}"; exit 1; } 527} 528 529case "${RERUN}" in 530'') 531 # Set up the loop to test for the existence of the 532 # temp root directory. 533 # 534 TEST_TEMP_ROOT=yes 535 while [ "${TEST_TEMP_ROOT}" = "yes" ]; do 536 if [ -d "${TEMPROOT}" ]; then 537 echo "*** The directory specified for the temporary root environment," 538 echo " ${TEMPROOT}, exists. This can be a security risk if untrusted" 539 echo " users have access to the system." 540 echo '' 541 case "${AUTO_RUN}" in 542 '') 543 echo " Use 'd' to delete the old ${TEMPROOT} and continue" 544 echo " Use 't' to select a new temporary root directory" 545 echo " Use 'e' to exit mergemaster" 546 echo '' 547 echo " Default is to use ${TEMPROOT} as is" 548 echo '' 549 echo -n "How should I deal with this? [Use the existing ${TEMPROOT}] " 550 read DELORNOT 551 552 case "${DELORNOT}" in 553 [dD]) 554 echo '' 555 echo " *** Deleting the old ${TEMPROOT}" 556 echo '' 557 delete_temproot 558 unset TEST_TEMP_ROOT 559 ;; 560 [tT]) 561 echo " *** Enter new directory name for temporary root environment" 562 read TEMPROOT 563 ;; 564 [eE]) 565 exit 0 566 ;; 567 '') 568 echo '' 569 echo " *** Leaving ${TEMPROOT} intact" 570 echo '' 571 unset TEST_TEMP_ROOT 572 ;; 573 *) 574 echo '' 575 echo "invalid choice: ${DELORNOT}" 576 echo '' 577 ;; 578 esac 579 ;; 580 *) 581 # If this is an auto-run, try a hopefully safe alternative then 582 # re-test anyway. 583 TEMPROOT=/var/tmp/temproot.`date +%m%d.%H.%M.%S` 584 ;; 585 esac 586 else 587 unset TEST_TEMP_ROOT 588 fi 589 done 590 591 echo "*** Creating the temporary root environment in ${TEMPROOT}" 592 593 if mkdir -p "${TEMPROOT}"; then 594 echo " *** ${TEMPROOT} ready for use" 595 fi 596 597 if [ ! -d "${TEMPROOT}" ]; then 598 echo '' 599 echo " *** FATAL ERROR: Cannot create ${TEMPROOT}" 600 echo '' 601 exit 1 602 fi 603 604 echo " *** Creating and populating directory structure in ${TEMPROOT}" 605 echo '' 606 607 case "${VERBOSE}" in 608 '') ;; 609 *) 610 press_to_continue 611 ;; 612 esac 613 614 case "${PRE_WORLD}" in 615 '') 616 { cd ${SOURCEDIR} && 617 case "${DESTDIR}" in 618 '') ;; 619 *) 620 ${MM_MAKE} DESTDIR=${DESTDIR} distrib-dirs 621 ;; 622 esac 623 od=${TEMPROOT}/usr/obj 624 ${MM_MAKE} DESTDIR=${TEMPROOT} distrib-dirs && 625 MAKEOBJDIRPREFIX=$od ${MM_MAKE} _obj SUBDIR_OVERRIDE=etc && 626 MAKEOBJDIRPREFIX=$od ${MM_MAKE} everything SUBDIR_OVERRIDE=etc && 627 MAKEOBJDIRPREFIX=$od ${MM_MAKE} DESTDIR=${TEMPROOT} distribution;} || 628 { echo ''; 629 echo " *** FATAL ERROR: Cannot 'cd' to ${SOURCEDIR} and install files to"; 630 echo " the temproot environment"; 631 echo ''; 632 exit 1;} 633 ;; 634 *) 635 # Only set up files that are crucial to {build|install}world 636 { mkdir -p ${TEMPROOT}/etc && 637 cp -p ${SOURCEDIR}/etc/master.passwd ${TEMPROOT}/etc && 638 cp -p ${SOURCEDIR}/etc/group ${TEMPROOT}/etc;} || 639 { echo ''; 640 echo ' *** FATAL ERROR: Cannot copy files to the temproot environment'; 641 echo ''; 642 exit 1;} 643 ;; 644 esac 645 646 # Doing the inventory and removing files that we don't want to compare only 647 # makes sense if we are not doing a rerun, since we have no way of knowing 648 # what happened to the files during previous incarnations. 649 case "${VERBOSE}" in 650 '') ;; 651 *) 652 echo '' 653 echo ' *** The following files exist only in the installed version of' 654 echo " ${DESTDIR}/etc. In the vast majority of cases these files" 655 echo ' are necessary parts of the system and should not be deleted.' 656 echo ' However because these files are not updated by this process you' 657 echo ' might want to verify their status before rebooting your system.' 658 echo '' 659 press_to_continue 660 diff -qr ${DESTDIR}/etc ${TEMPROOT}/etc | grep "^Only in ${DESTDIR}/etc" | ${PAGER} 661 echo '' 662 press_to_continue 663 ;; 664 esac 665 666 case "${IGNORE_MOTD}" in 667 '') ;; 668 *) 669 echo '' 670 echo "*** You have the IGNORE_MOTD option set in your mergemaster rc file." 671 echo " This option is deprecated in favor of the IGNORE_FILES option." 672 echo " Please update your rc file accordingly." 673 echo '' 674 exit 1 675 ;; 676 esac 677 678 # Avoid comparing the following user specified files 679 for file in ${IGNORE_FILES}; do 680 test -e ${TEMPROOT}/${file} && unlink ${TEMPROOT}/${file} 681 done 682 683 # We really don't want to have to deal with files like login.conf.db, pwd.db, 684 # or spwd.db. Instead, we want to compare the text versions, and run *_mkdb. 685 # Prompt the user to do so below, as needed. 686 # 687 rm -f ${TEMPROOT}/etc/*.db ${TEMPROOT}/etc/passwd 688 689 # We only need to compare things like freebsd.cf once 690 find ${TEMPROOT}/usr/obj -type f -delete 2>/dev/null 691 692 # Delete stuff we do not need to keep the mtree database small, 693 # and to make the actual comparison faster. 694 find ${TEMPROOT}/usr -type l -delete 2>/dev/null 695 find ${TEMPROOT} -type f -size 0 -delete 2>/dev/null 696 find -d ${TEMPROOT} -type d -empty -delete 2>/dev/null 697 698 # Build the mtree database in a temporary location. 699 case "${PRE_WORLD}" in 700 '') MTREENEW=`mktemp -t mergemaster.mtree` 701 mtree -ci -p ${TEMPROOT} -k size,md5digest > ${MTREENEW} 2>/dev/null 702 ;; 703 *) # We don't want to mess with the mtree database on a pre-world run or 704 # when re-scanning a previously-built tree. 705 ;; 706 esac 707 ;; # End of the "RERUN" test 708esac 709 710# Get ready to start comparing files 711 712# Check umask if not specified on the command line, 713# and we are not doing an autorun 714# 715if [ -z "${NEW_UMASK}" -a -z "${AUTO_RUN}" ]; then 716 USER_UMASK=`umask` 717 case "${USER_UMASK}" in 718 0022|022) ;; 719 *) 720 echo '' 721 echo " *** Your umask is currently set to ${USER_UMASK}. By default, this script" 722 echo " installs all files with the same user, group and modes that" 723 echo " they are created with by ${SOURCEDIR}/etc/Makefile, compared to" 724 echo " a umask of 022. This umask allows world read permission when" 725 echo " the file's default permissions have it." 726 echo '' 727 echo " No world permissions can sometimes cause problems. A umask of" 728 echo " 022 will restore the default behavior, but is not mandatory." 729 echo " /etc/master.passwd is a special case. Its file permissions" 730 echo " will be 600 (rw-------) if installed." 731 echo '' 732 echo -n "What umask should I use? [${USER_UMASK}] " 733 read NEW_UMASK 734 735 NEW_UMASK="${NEW_UMASK:-$USER_UMASK}" 736 ;; 737 esac 738 echo '' 739fi 740 741CONFIRMED_UMASK=${NEW_UMASK:-0022} 742 743# 744# Warn users who still have old rc files 745# 746for file in atm devfs diskless1 diskless2 network network6 pccard \ 747 serial syscons sysctl alpha amd64 i386 ia64 sparc64; do 748 if [ -f "${DESTDIR}/etc/rc.${file}" ]; then 749 OLD_RC_PRESENT=1 750 break 751 fi 752done 753 754case "${OLD_RC_PRESENT}" in 7551) 756 echo '' 757 echo " *** There are elements of the old rc system in ${DESTDIR}/etc/." 758 echo '' 759 echo ' While these scripts will not hurt anything, they are not' 760 echo ' functional on an up to date system, and can be removed.' 761 echo '' 762 763 case "${AUTO_RUN}" in 764 '') 765 echo -n 'Move these files to /var/tmp/mergemaster/old_rc? [yes] ' 766 read MOVE_OLD_RC 767 768 case "${MOVE_OLD_RC}" in 769 [nN]*) ;; 770 *) 771 mkdir -p /var/tmp/mergemaster/old_rc 772 for file in atm devfs diskless1 diskless2 network network6 pccard \ 773 serial syscons sysctl alpha amd64 i386 ia64 sparc64; do 774 if [ -f "${DESTDIR}/etc/rc.${file}" ]; then 775 mv ${DESTDIR}/etc/rc.${file} /var/tmp/mergemaster/old_rc/ 776 fi 777 done 778 echo ' The files have been moved' 779 press_to_continue 780 ;; 781 esac 782 ;; 783 *) ;; 784 esac 785esac 786 787# Use the umask/mode information to install the files 788# Create directories as needed 789# 790install_error () { 791 echo "*** FATAL ERROR: Unable to install ${1} to ${2}" 792 echo '' 793 exit 1 794} 795 796do_install_and_rm () { 797 case "${PRESERVE_FILES}" in 798 [Yy][Ee][Ss]) 799 if [ -f "${3}/${2##*/}" ]; then 800 mkdir -p ${PRESERVE_FILES_DIR}/${2%/*} 801 cp ${3}/${2##*/} ${PRESERVE_FILES_DIR}/${2%/*} 802 fi 803 ;; 804 esac 805 806 if [ ! -d "${3}/${2##*/}" ]; then 807 if install -m ${1} ${2} ${3}; then 808 unlink ${2} 809 else 810 install_error ${2} ${3} 811 fi 812 else 813 install_error ${2} ${3} 814 fi 815} 816 817# 4095 = "obase=10;ibase=8;07777" | bc 818find_mode () { 819 local OCTAL 820 OCTAL=$(( ~$(echo "obase=10; ibase=8; ${CONFIRMED_UMASK}" | bc) & 4095 & 821 $(echo "obase=10; ibase=8; $(stat -f "%OMp%OLp" ${1})" | bc) )) 822 printf "%04o\n" ${OCTAL} 823} 824 825mm_install () { 826 local INSTALL_DIR 827 INSTALL_DIR=${1#.} 828 INSTALL_DIR=${INSTALL_DIR%/*} 829 830 case "${INSTALL_DIR}" in 831 '') 832 INSTALL_DIR=/ 833 ;; 834 esac 835 836 if [ -n "${DESTDIR}${INSTALL_DIR}" -a ! -d "${DESTDIR}${INSTALL_DIR}" ]; then 837 DIR_MODE=`find_mode "${TEMPROOT}/${INSTALL_DIR}"` 838 install -d -o root -g wheel -m "${DIR_MODE}" "${DESTDIR}${INSTALL_DIR}" || 839 install_error $1 ${DESTDIR}${INSTALL_DIR} 840 fi 841 842 FILE_MODE=`find_mode "${1}"` 843 844 if [ ! -x "${1}" ]; then 845 case "${1#.}" in 846 /etc/mail/aliases) 847 NEED_NEWALIASES=yes 848 ;; 849 /etc/login.conf) 850 NEED_CAP_MKDB=yes 851 ;; 852 /etc/master.passwd) 853 do_install_and_rm 600 "${1}" "${DESTDIR}${INSTALL_DIR}" 854 NEED_PWD_MKDB=yes 855 DONT_INSTALL=yes 856 ;; 857 /.cshrc | /.profile) 858 local st_nlink 859 860 # install will unlink the file before it installs the new one, 861 # so we have to restore/create the link afterwards. 862 # 863 st_nlink=0 # In case the file does not yet exist 864 eval $(stat -s ${DESTDIR}${COMPFILE#.} 2>/dev/null) 865 866 do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}" 867 868 if [ -n "${AUTO_INSTALL}" -a $st_nlink -gt 1 ]; then 869 HANDLE_LINK=l 870 else 871 case "${LINK_EXPLAINED}" in 872 '') 873 echo " *** Historically BSD derived systems have had a" 874 echo " hard link from /.cshrc and /.profile to" 875 echo " their namesakes in /root. Please indicate" 876 echo " your preference below for bringing your" 877 echo " installed files up to date." 878 echo '' 879 LINK_EXPLAINED=yes 880 ;; 881 esac 882 883 echo " Use 'd' to delete the temporary ${COMPFILE}" 884 echo " Use 'l' to delete the existing ${DESTDIR}/root/${COMPFILE##*/} and create the link" 885 echo '' 886 echo " Default is to leave the temporary file to deal with by hand" 887 echo '' 888 echo -n " How should I handle ${COMPFILE}? [Leave it to install later] " 889 read HANDLE_LINK 890 fi 891 892 case "${HANDLE_LINK}" in 893 [dD]*) 894 rm "${COMPFILE}" 895 echo '' 896 echo " *** Deleting ${COMPFILE}" 897 ;; 898 [lL]*) 899 echo '' 900 unlink ${DESTDIR}/root/${COMPFILE##*/} 901 if ln ${DESTDIR}${COMPFILE#.} ${DESTDIR}/root/${COMPFILE##*/}; then 902 echo " *** Link from ${DESTDIR}${COMPFILE#.} to ${DESTDIR}/root/${COMPFILE##*/} installed successfully" 903 else 904 echo " *** Error linking ${DESTDIR}${COMPFILE#.} to ${DESTDIR}/root/${COMPFILE##*/}" 905 echo " *** ${COMPFILE} will remain for your consideration" 906 fi 907 ;; 908 *) 909 echo " *** ${COMPFILE} will remain for your consideration" 910 ;; 911 esac 912 return 913 ;; 914 esac 915 916 case "${DONT_INSTALL}" in 917 '') 918 do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}" 919 ;; 920 *) 921 unset DONT_INSTALL 922 ;; 923 esac 924 else # File matched -x 925 do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}" 926 fi 927 return $? 928} 929 930if [ ! -d "${TEMPROOT}" ]; then 931 echo "*** FATAL ERROR: The temproot directory (${TEMPROOT})" 932 echo ' has disappeared!' 933 echo '' 934 exit 1 935fi 936 937echo '' 938echo "*** Beginning comparison" 939echo '' 940 941# Pre-world does not populate /etc/rc.d. 942# It is very possible that a previous run would have deleted files in 943# ${TEMPROOT}/etc/rc.d, thus creating a lot of false positives. 944if [ -z "${PRE_WORLD}" -a -z "${RERUN}" ]; then 945 echo " *** Checking ${DESTDIR}/etc/rc.d for stale files" 946 echo '' 947 cd "${DESTDIR}/etc/rc.d" && 948 for file in *; do 949 if [ ! -e "${TEMPROOT}/etc/rc.d/${file}" ]; then 950 STALE_RC_FILES="${STALE_RC_FILES} ${file}" 951 fi 952 done 953 case "${STALE_RC_FILES}" in 954 ''|' *') 955 echo ' *** No stale files found' 956 ;; 957 *) 958 echo " *** The following files exist in ${DESTDIR}/etc/rc.d but not in" 959 echo " ${TEMPROOT}/etc/rc.d/:" 960 echo '' 961 echo "${STALE_RC_FILES}" 962 echo '' 963 echo ' The presence of stale files in this directory can cause the' 964 echo ' dreaded unpredictable results, and therefore it is highly' 965 echo ' recommended that you delete them.' 966 case "${AUTO_RUN}" in 967 '') 968 echo '' 969 echo -n ' *** Delete them now? [n] ' 970 read DELETE_STALE_RC_FILES 971 case "${DELETE_STALE_RC_FILES}" in 972 [yY]) 973 echo ' *** Deleting ... ' 974 rm ${STALE_RC_FILES} 975 echo ' done.' 976 ;; 977 *) 978 echo ' *** Files will not be deleted' 979 ;; 980 esac 981 sleep 2 982 ;; 983 *) 984 if [ -n "${DELETE_STALE_RC_FILES}" ]; then 985 echo ' *** Deleting ... ' 986 rm ${STALE_RC_FILES} 987 echo ' done.' 988 fi 989 esac 990 ;; 991 esac 992 echo '' 993fi 994 995cd "${TEMPROOT}" 996 997if [ -r "${MM_PRE_COMPARE_SCRIPT}" ]; then 998 . "${MM_PRE_COMPARE_SCRIPT}" 999fi 1000 1001# Things that were files/directories/links in one version can sometimes 1002# change to something else in a newer version. So we need to explicitly 1003# test for this, and warn the user if what we find does not match. 1004# 1005for COMPFILE in `find . | sort` ; do 1006 if [ -e "${DESTDIR}${COMPFILE#.}" ]; then 1007 INSTALLED_TYPE=`stat -f '%HT' ${DESTDIR}${COMPFILE#.}` 1008 else 1009 continue 1010 fi 1011 TEMPROOT_TYPE=`stat -f '%HT' $COMPFILE` 1012 1013 if [ ! "$TEMPROOT_TYPE" = "$INSTALLED_TYPE" ]; then 1014 [ "$COMPFILE" = '.' ] && continue 1015 TEMPROOT_TYPE=`echo $TEMPROOT_TYPE | tr [:upper:] [:lower:]` 1016 INSTALLED_TYPE=`echo $INSTALLED_TYPE | tr [:upper:] [:lower:]` 1017 1018 echo "*** The installed file ${DESTDIR}${COMPFILE#.} has the type \"$INSTALLED_TYPE\"" 1019 echo " but the new version has the type \"$TEMPROOT_TYPE\"" 1020 echo '' 1021 echo " How would you like to handle this?" 1022 echo '' 1023 echo " Use 'r' to remove ${DESTDIR}${COMPFILE#.}" 1024 case "$TEMPROOT_TYPE" in 1025 'symbolic link') 1026 TARGET=`readlink $COMPFILE` 1027 echo " and create a link to $TARGET in its place" ;; 1028 *) echo " You will be able to install it as a \"$TEMPROOT_TYPE\"" ;; 1029 esac 1030 echo '' 1031 echo " Use 'i' to ignore this" 1032 echo '' 1033 echo -n " How to proceed? [i] " 1034 read ANSWER 1035 case "$ANSWER" in 1036 [rR]) case "${PRESERVE_FILES}" in 1037 [Yy][Ee][Ss]) 1038 mv ${DESTDIR}${COMPFILE#.} ${PRESERVE_FILES_DIR}/ || exit 1 ;; 1039 *) rm -rf ${DESTDIR}${COMPFILE#.} ;; 1040 esac 1041 case "$TEMPROOT_TYPE" in 1042 'symbolic link') ln -sf $TARGET ${DESTDIR}${COMPFILE#.} ;; 1043 esac ;; 1044 *) echo '' 1045 echo "*** See the man page about adding ${COMPFILE#.} to the list of IGNORE_FILES" 1046 press_to_continue ;; 1047 esac 1048 echo '' 1049 fi 1050done 1051 1052for COMPFILE in `find . -type f | sort`; do 1053 1054 # First, check to see if the file exists in DESTDIR. If not, the 1055 # diff_loop function knows how to handle it. 1056 # 1057 if [ ! -e "${DESTDIR}${COMPFILE#.}" ]; then 1058 case "${AUTO_RUN}" in 1059 '') 1060 diff_loop 1061 ;; 1062 *) 1063 case "${AUTO_INSTALL}" in 1064 '') 1065 # If this is an auto run, make it official 1066 echo " *** ${COMPFILE} will remain for your consideration" 1067 ;; 1068 *) 1069 diff_loop 1070 ;; 1071 esac 1072 ;; 1073 esac # Auto run test 1074 continue 1075 fi 1076 1077 case "${STRICT}" in 1078 '' | [Nn][Oo]) 1079 # Compare CVS $Id's first so if the file hasn't been modified 1080 # local changes will be ignored. 1081 # If the files have the same $Id, delete the one in temproot so the 1082 # user will have less to wade through if files are left to merge by hand. 1083 # 1084 CVSID1=`grep "[$]${CVS_ID_TAG}:" ${DESTDIR}${COMPFILE#.} 2>/dev/null` 1085 CVSID2=`grep "[$]${CVS_ID_TAG}:" ${COMPFILE} 2>/dev/null` || CVSID2=none 1086 1087 case "${CVSID2}" in 1088 "${CVSID1}") 1089 echo " *** Temp ${COMPFILE} and installed have the same CVS Id, deleting" 1090 rm "${COMPFILE}" 1091 ;; 1092 esac 1093 ;; 1094 esac 1095 1096 # If the file is still here either because the $Ids are different, the 1097 # file doesn't have an $Id, or we're using STRICT mode; look at the diff. 1098 # 1099 if [ -f "${COMPFILE}" ]; then 1100 1101 # Do an absolute diff first to see if the files are actually different. 1102 # If they're not different, delete the one in temproot. 1103 # 1104 if diff -q ${DIFF_OPTIONS} "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" > \ 1105 /dev/null 2>&1; then 1106 echo " *** Temp ${COMPFILE} and installed are the same, deleting" 1107 rm "${COMPFILE}" 1108 else 1109 # Ok, the files are different, so show the user where they differ. 1110 # Use user's choice of diff methods; and user's pager if they have one. 1111 # Use more if not. 1112 # Use unified diffs by default. Context diffs give me a headache. :) 1113 # 1114 # If the user chose the -F option, test for that before proceeding 1115 # 1116 if [ -n "$FREEBSD_ID" ]; then 1117 if diff -q -I'[$]FreeBSD.*[$]' "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" > \ 1118 /dev/null 2>&1; then 1119 if mm_install "${COMPFILE}"; then 1120 echo "*** Updated revision control Id for ${DESTDIR}${COMPFILE#.}" 1121 else 1122 echo "*** Problem installing ${COMPFILE}, it will remain to merge by hand later" 1123 fi 1124 continue 1125 fi 1126 fi 1127 case "${AUTO_RUN}" in 1128 '') 1129 # prompt user to install/delete/merge changes 1130 diff_loop 1131 ;; 1132 *) 1133 # If this is an auto run, make it official 1134 echo " *** ${COMPFILE} will remain for your consideration" 1135 ;; 1136 esac # Auto run test 1137 fi # Yes, the files are different 1138 fi # Yes, the file still remains to be checked 1139done # This is for the for way up there at the beginning of the comparison 1140 1141echo '' 1142echo "*** Comparison complete" 1143 1144if [ -s "${MTREENEW}" ]; then 1145 echo "*** Saving mtree database for future upgrades" 1146 test -e "${MTREEFILE}" && unlink ${MTREEFILE} 1147 mv ${MTREENEW} ${MTREEFILE} 1148fi 1149 1150echo '' 1151 1152TEST_FOR_FILES=`find ${TEMPROOT} -type f -size +0 2>/dev/null` 1153if [ -n "${TEST_FOR_FILES}" ]; then 1154 echo "*** Files that remain for you to merge by hand:" 1155 find "${TEMPROOT}" -type f -size +0 | sort 1156 echo '' 1157 1158 case "${AUTO_RUN}" in 1159 '') 1160 echo -n "Do you wish to delete what is left of ${TEMPROOT}? [no] " 1161 read DEL_TEMPROOT 1162 case "${DEL_TEMPROOT}" in 1163 [yY]*) 1164 delete_temproot 1165 ;; 1166 *) 1167 echo " *** ${TEMPROOT} will remain" 1168 ;; 1169 esac 1170 ;; 1171 *) ;; 1172 esac 1173else 1174 echo "*** ${TEMPROOT} is empty, deleting" 1175 delete_temproot 1176fi 1177 1178case "${AUTO_INSTALLED_FILES}" in 1179'') ;; 1180*) 1181 case "${AUTO_RUN}" in 1182 '') 1183 ( 1184 echo '' 1185 echo '*** You chose the automatic install option for files that did not' 1186 echo ' exist on your system. The following were installed for you:' 1187 echo "${AUTO_INSTALLED_FILES}" 1188 ) | ${PAGER} 1189 ;; 1190 *) 1191 echo '' 1192 echo '*** You chose the automatic install option for files that did not' 1193 echo ' exist on your system. The following were installed for you:' 1194 echo "${AUTO_INSTALLED_FILES}" 1195 ;; 1196 esac 1197 ;; 1198esac 1199 1200case "${AUTO_UPGRADED_FILES}" in 1201'') ;; 1202*) 1203 case "${AUTO_RUN}" in 1204 '') 1205 ( 1206 echo '' 1207 echo '*** You chose the automatic upgrade option for files that you did' 1208 echo ' not alter on your system. The following were upgraded for you:' 1209 echo "${AUTO_UPGRADED_FILES}" 1210 ) | ${PAGER} 1211 ;; 1212 *) 1213 echo '' 1214 echo '*** You chose the automatic upgrade option for files that you did' 1215 echo ' not alter on your system. The following were upgraded for you:' 1216 echo "${AUTO_UPGRADED_FILES}" 1217 ;; 1218 esac 1219 ;; 1220esac 1221 1222run_it_now () { 1223 case "${AUTO_RUN}" in 1224 '') 1225 unset YES_OR_NO 1226 echo '' 1227 echo -n ' Would you like to run it now? y or n [n] ' 1228 read YES_OR_NO 1229 1230 case "${YES_OR_NO}" in 1231 y) 1232 echo " Running ${1}" 1233 echo '' 1234 eval "${1}" 1235 ;; 1236 ''|n) 1237 echo '' 1238 echo " *** Cancelled" 1239 echo '' 1240 echo " Make sure to run ${1} yourself" 1241 ;; 1242 *) 1243 echo '' 1244 echo " *** Sorry, I do not understand your answer (${YES_OR_NO})" 1245 echo '' 1246 echo " Make sure to run ${1} yourself" 1247 esac 1248 ;; 1249 *) ;; 1250 esac 1251} 1252 1253case "${NEED_NEWALIASES}" in 1254'') ;; 1255*) 1256 echo '' 1257 if [ -n "${DESTDIR}" ]; then 1258 echo "*** You installed a new aliases file into ${DESTDIR}/etc/mail, but" 1259 echo " the newaliases command is limited to the directories configured" 1260 echo " in sendmail.cf. Make sure to create your aliases database by" 1261 echo " hand when your sendmail configuration is done." 1262 else 1263 echo "*** You installed a new aliases file, so make sure that you run" 1264 echo " '/usr/bin/newaliases' to rebuild your aliases database" 1265 run_it_now '/usr/bin/newaliases' 1266 fi 1267 ;; 1268esac 1269 1270case "${NEED_CAP_MKDB}" in 1271'') ;; 1272*) 1273 echo '' 1274 echo "*** You installed a login.conf file, so make sure that you run" 1275 echo " '/usr/bin/cap_mkdb ${DESTDIR}/etc/login.conf'" 1276 echo " to rebuild your login.conf database" 1277 run_it_now "/usr/bin/cap_mkdb ${DESTDIR}/etc/login.conf" 1278 ;; 1279esac 1280 1281case "${NEED_PWD_MKDB}" in 1282'') ;; 1283*) 1284 echo '' 1285 echo "*** You installed a new master.passwd file, so make sure that you run" 1286 if [ -n "${DESTDIR}" ]; then 1287 echo " '/usr/sbin/pwd_mkdb -d ${DESTDIR}/etc -p ${DESTDIR}/etc/master.passwd'" 1288 echo " to rebuild your password files" 1289 run_it_now "/usr/sbin/pwd_mkdb -d ${DESTDIR}/etc -p ${DESTDIR}/etc/master.passwd" 1290 else 1291 echo " '/usr/sbin/pwd_mkdb -p /etc/master.passwd'" 1292 echo " to rebuild your password files" 1293 run_it_now '/usr/sbin/pwd_mkdb -p /etc/master.passwd' 1294 fi 1295 ;; 1296esac 1297 1298echo '' 1299 1300if [ -r "${MM_EXIT_SCRIPT}" ]; then 1301 . "${MM_EXIT_SCRIPT}" 1302fi 1303 1304case "${COMP_CONFS}" in 1305'') ;; 1306*) 1307 . ${DESTDIR}/etc/defaults/rc.conf 1308 1309 (echo '' 1310 echo "*** Comparing conf files: ${rc_conf_files}" 1311 1312 for CONF_FILE in ${rc_conf_files}; do 1313 if [ -r "${DESTDIR}${CONF_FILE}" ]; then 1314 echo '' 1315 echo "*** From ${DESTDIR}${CONF_FILE}" 1316 echo "*** From ${DESTDIR}/etc/defaults/rc.conf" 1317 1318 for RC_CONF_VAR in `grep -i ^[a-z] ${DESTDIR}${CONF_FILE} | 1319 cut -d '=' -f 1`; do 1320 echo '' 1321 grep -w ^${RC_CONF_VAR} ${DESTDIR}${CONF_FILE} 1322 grep -w ^${RC_CONF_VAR} ${DESTDIR}/etc/defaults/rc.conf || 1323 echo ' * No default variable with this name' 1324 done 1325 fi 1326 done) | ${PAGER} 1327 echo '' 1328 ;; 1329esac 1330 1331case "${PRE_WORLD}" in 1332'') ;; 1333*) 1334 MAKE_CONF="${SOURCEDIR}/share/examples/etc/make.conf" 1335 1336 (echo '' 1337 echo '*** Comparing make variables' 1338 echo '' 1339 echo "*** From ${DESTDIR}/etc/make.conf" 1340 echo "*** From ${MAKE_CONF}" 1341 1342 for MAKE_VAR in `grep -i ^[a-z] ${DESTDIR}/etc/make.conf | cut -d '=' -f 1`; do 1343 echo '' 1344 grep -w ^${MAKE_VAR} ${DESTDIR}/etc/make.conf 1345 grep -w ^#${MAKE_VAR} ${MAKE_CONF} || 1346 echo ' * No example variable with this name' 1347 done) | ${PAGER} 1348 ;; 1349esac 1350 1351if [ -n "${PRESERVE_FILES}" ]; then 1352 find -d $PRESERVE_FILES_DIR -type d -empty -delete 2>/dev/null 1353 rmdir $PRESERVE_FILES_DIR 2>/dev/null 1354fi 1355 1356exit 0 1357