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