mergemaster.sh revision 97960
1178171Simp#!/bin/sh 2178171Simp 3178171Simp# mergemaster 4178171Simp 5178171Simp# Compare files created by /usr/src/etc/Makefile (or the directory 6178171Simp# the user specifies) with the currently installed copies. 7178171Simp 8178171Simp# Copyright 1998-2002 Douglas Barton 9178171Simp# DougB@FreeBSD.org 10178171Simp 11178171Simp# $FreeBSD: head/usr.sbin/mergemaster/mergemaster.sh 97960 2002-06-06 20:38:22Z dougb $ 12178171Simp 13178171SimpPATH=/bin:/usr/bin:/usr/sbin 14178171Simp 15178171Simpdisplay_usage () { 16178171Simp VERSION_NUMBER=`grep "[$]FreeBSD:" $0 | cut -d ' ' -f 4` 17178171Simp echo "mergemaster version ${VERSION_NUMBER}" 18178171Simp echo 'Usage: mergemaster [-scrvahipC] [-m /path]' 19178171Simp echo ' [-t /path] [-d] [-u N] [-w N] [-D /path]' 20178171Simp echo "Options:" 21178171Simp echo " -s Strict comparison (diff every pair of files)" 22178171Simp echo " -c Use context diff instead of unified diff" 23178171Simp echo " -r Re-run on a previously cleaned directory (skip temproot creation)" 24178171Simp echo " -v Be more verbose about the process, include additional checks" 25178171Simp echo " -a Leave all files that differ to merge by hand" 26178171Simp echo " -h Display more complete help" 27178171Simp echo ' -i Automatically install files that do not exist in destination directory' 28178171Simp echo ' -p Pre-buildworld mode, only compares crucial files' 29178171Simp echo ' -C Compare local rc.conf variables to the defaults' 30191954Skuriyama echo " -m /path/directory Specify location of source to do the make in" 31191954Skuriyama echo " -t /path/directory Specify temp root directory" 32178171Simp echo " -d Add date and time to directory name (e.g., /var/tmp/temproot.`date +%m%d.%H.%M`)" 33191954Skuriyama echo " -u N Specify a numeric umask" 34191954Skuriyama echo " -w N Specify a screen width in columns to sdiff" 35221753Sgonzo echo ' -D /path/directory Specify the destination directory to install files to' 36221753Sgonzo echo '' 37191954Skuriyama} 38191954Skuriyama 39178171Simpdisplay_help () { 40178171Simp echo "* To specify a directory other than /var/tmp/temproot for the" 41203938Sattilio echo " temporary root environment, use -t /path/to/temp/root" 42191954Skuriyama echo "* The -w option takes a number as an argument for the column width" 43191954Skuriyama echo " of the screen. The default is 80." 44191954Skuriyama echo '* The -a option causes mergemaster to run without prompting.' 45191954Skuriyama} 46178171Simp 47178171Simp# Loop allowing the user to use sdiff to merge files and display the merged 48178171Simp# file. 49178171Simpmerge_loop () { 50 case "${VERBOSE}" in 51 '') ;; 52 *) 53 echo " *** Type h at the sdiff prompt (%) to get usage help" 54 ;; 55 esac 56 echo '' 57 MERGE_AGAIN=yes 58 while [ "${MERGE_AGAIN}" = "yes" ]; do 59 # Prime file.merged so we don't blat the owner/group id's 60 cp -p "${COMPFILE}" "${COMPFILE}.merged" 61 sdiff -o "${COMPFILE}.merged" --text --suppress-common-lines \ 62 --width=${SCREEN_WIDTH:-80} "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" 63 INSTALL_MERGED=V 64 while [ "${INSTALL_MERGED}" = "v" -o "${INSTALL_MERGED}" = "V" ]; do 65 echo '' 66 echo " Use 'i' to install merged file" 67 echo " Use 'r' to re-do the merge" 68 echo " Use 'v' to view the merged file" 69 echo " Default is to leave the temporary file to deal with by hand" 70 echo '' 71 echo -n " *** How should I deal with the merged file? [Leave it for later] " 72 read INSTALL_MERGED 73 74 case "${INSTALL_MERGED}" in 75 [iI]) 76 mv "${COMPFILE}.merged" "${COMPFILE}" 77 echo '' 78 if mm_install "${COMPFILE}"; then 79 echo " *** Merged version of ${COMPFILE} installed successfully" 80 else 81 echo " *** Problem installing ${COMPFILE}, it will remain to merge by hand later" 82 fi 83 unset MERGE_AGAIN 84 ;; 85 [rR]) 86 rm "${COMPFILE}.merged" 87 ;; 88 [vV]) 89 ${PAGER} "${COMPFILE}.merged" 90 ;; 91 '') 92 echo " *** ${COMPFILE} will remain for your consideration" 93 unset MERGE_AGAIN 94 ;; 95 *) 96 echo "invalid choice: ${INSTALL_MERGED}" 97 INSTALL_MERGED=V 98 ;; 99 esac 100 done 101 done 102} 103 104# Loop showing user differences between files, allow merge, skip or install 105# options 106diff_loop () { 107 108 HANDLE_COMPFILE=v 109 110 while [ "${HANDLE_COMPFILE}" = "v" -o "${HANDLE_COMPFILE}" = "V" -o \ 111 "${HANDLE_COMPFILE}" = "NOT V" ]; do 112 if [ -f "${DESTDIR}${COMPFILE#.}" -a -f "${COMPFILE}" ]; then 113 if [ "${HANDLE_COMPFILE}" = "v" -o "${HANDLE_COMPFILE}" = "V" ]; then 114 echo '' 115 echo ' ====================================================================== ' 116 echo '' 117 ( 118 echo '' 119 echo " *** Displaying differences between ${COMPFILE} and installed version:" 120 echo '' 121 diff "${DIFF_FLAG}" "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" 122 ) | ${PAGER} 123 echo '' 124 fi 125 else 126 echo '' 127 echo " *** There is no installed version of ${COMPFILE}" 128 echo '' 129 case "${AUTO_INSTALL}" in 130 [Yy][Ee][Ss]) 131 echo '' 132 if mm_install "${COMPFILE}"; then 133 echo " *** ${COMPFILE} installed successfully" 134 echo '' 135 # Make the list print one file per line 136 AUTO_INSTALLED_FILES="${AUTO_INSTALLED_FILES} ${DESTDIR}${COMPFILE#.} 137" 138 else 139 echo " *** Problem installing ${COMPFILE}, it will remain to merge by hand" 140 fi 141 return 142 ;; 143 *) 144 NO_INSTALLED=yes 145 ;; 146 esac 147 fi 148 149 echo " Use 'd' to delete the temporary ${COMPFILE}" 150 echo " Use 'i' to install the temporary ${COMPFILE}" 151 case "${NO_INSTALLED}" in 152 '') 153 echo " Use 'm' to merge the temporary and installed versions" 154 echo " Use 'v' to view the diff results again" 155 ;; 156 esac 157 echo '' 158 echo " Default is to leave the temporary file to deal with by hand" 159 echo '' 160 echo -n "How should I deal with this? [Leave it for later] " 161 read HANDLE_COMPFILE 162 163 case "${HANDLE_COMPFILE}" in 164 [dD]) 165 rm "${COMPFILE}" 166 echo '' 167 echo " *** Deleting ${COMPFILE}" 168 ;; 169 [iI]) 170 echo '' 171 if mm_install "${COMPFILE}"; then 172 echo " *** ${COMPFILE} installed successfully" 173 else 174 echo " *** Problem installing ${COMPFILE}, it will remain to merge by hand" 175 fi 176 ;; 177 [mM]) 178 case "${NO_INSTALLED}" in 179 '') 180 # interact with user to merge files 181 merge_loop 182 ;; 183 *) 184 echo '' 185 echo " *** There is no installed version of ${COMPFILE}" 186 echo '' 187 HANDLE_COMPFILE="NOT V" 188 ;; 189 esac # End of "No installed version of file but user selected merge" test 190 ;; 191 [vV]) 192 continue 193 ;; 194 '') 195 echo '' 196 echo " *** ${COMPFILE} will remain for your consideration" 197 ;; 198 *) 199 # invalid choice, show menu again. 200 echo "invalid choice: ${HANDLE_COMPFILE}" 201 echo '' 202 HANDLE_COMPFILE="NOT V" 203 continue 204 ;; 205 esac # End of "How to handle files that are different" 206 done 207 unset NO_INSTALLED 208 echo '' 209 case "${VERBOSE}" in 210 '') ;; 211 *) 212 sleep 3 213 ;; 214 esac 215} 216 217press_to_continue () { 218 local DISCARD 219 echo -n ' *** Press the [Enter] or [Return] key to continue ' 220 read DISCARD 221} 222 223# Set the default path for the temporary root environment 224# 225TEMPROOT='/var/tmp/temproot' 226 227# Read /etc/mergemaster.rc first so the one in $HOME can override 228# 229if [ -r /etc/mergemaster.rc ]; then 230 . /etc/mergemaster.rc 231fi 232 233# Read .mergemasterrc before command line so CLI can override 234# 235if [ -r "$HOME/.mergemasterrc" ]; then 236 . "$HOME/.mergemasterrc" 237fi 238 239# Check the command line options 240# 241while getopts ":ascrvhipCm:t:du:w:D:" COMMAND_LINE_ARGUMENT ; do 242 case "${COMMAND_LINE_ARGUMENT}" in 243 s) 244 STRICT=yes 245 ;; 246 c) 247 DIFF_FLAG='-c' 248 ;; 249 r) 250 RERUN=yes 251 ;; 252 v) 253 case "${AUTO_RUN}" in 254 '') VERBOSE=yes ;; 255 esac 256 ;; 257 a) 258 AUTO_RUN=yes 259 unset VERBOSE 260 ;; 261 h) 262 display_usage 263 display_help 264 exit 0 265 ;; 266 i) 267 AUTO_INSTALL=yes 268 ;; 269 C) 270 COMP_CONFS=yes 271 ;; 272 p) 273 PRE_WORLD=yes 274 unset COMP_CONFS 275 unset AUTO_RUN 276 ;; 277 m) 278 SOURCEDIR=${OPTARG} 279 ;; 280 t) 281 TEMPROOT=${OPTARG} 282 ;; 283 d) 284 TEMPROOT=${TEMPROOT}.`date +%m%d.%H.%M` 285 ;; 286 u) 287 NEW_UMASK=${OPTARG} 288 ;; 289 w) 290 SCREEN_WIDTH=${OPTARG} 291 ;; 292 D) 293 DESTDIR=${OPTARG} 294 ;; 295 *) 296 display_usage 297 exit 1 298 ;; 299 esac 300done 301 302echo '' 303 304# If the user has a pager defined, make sure we can run it 305# 306case "${DONT_CHECK_PAGER}" in 307'') 308 while ! type "${PAGER%% *}" >/dev/null && [ -n "${PAGER}" ]; do 309 echo " *** Your PAGER environment variable specifies '${PAGER}', but" 310 echo " due to the limited PATH that I use for security reasons," 311 echo " I cannot execute it. So, what would you like to do?" 312 echo '' 313 echo " Use 'e' to exit mergemaster and fix your PAGER variable" 314 if [ -x /usr/bin/less -o -x /usr/local/bin/less ]; then 315 echo " Use 'l' to set PAGER to 'less' for this run" 316 fi 317 echo " Use 'm' to use plain old 'more' as your PAGER for this run" 318 echo '' 319 echo " Default is to use plain old 'more' " 320 echo '' 321 echo -n "What should I do? [Use 'more'] " 322 read FIXPAGER 323 324 case "${FIXPAGER}" in 325 [eE]) 326 exit 0 327 ;; 328 [lL]) 329 if [ -x /usr/bin/less ]; then 330 PAGER=/usr/bin/less 331 elif [ -x /usr/local/bin/less ]; then 332 PAGER=/usr/local/bin/less 333 else 334 echo '' 335 echo " *** Fatal Error:" 336 echo " You asked to use 'less' as your pager, but I can't" 337 echo " find it in /usr/bin or /usr/local/bin" 338 exit 1 339 fi 340 ;; 341 [mM]|'') 342 PAGER=more 343 ;; 344 *) 345 echo '' 346 echo "invalid choice: ${FIXPAGER}" 347 esac 348 echo '' 349 done 350 ;; 351esac 352 353# If user has a pager defined, or got assigned one above, use it. 354# If not, use more. 355# 356PAGER=${PAGER:-more} 357 358if [ -n "${VERBOSE}" -a ! "${PAGER}" = "more" ]; then 359 echo " *** You have ${PAGER} defined as your pager so we will use that" 360 echo '' 361 sleep 3 362fi 363 364# Assign the diff flag once so we will not have to keep testing it 365# 366DIFF_FLAG=${DIFF_FLAG:--u} 367 368# Assign the source directory 369# 370SOURCEDIR=${SOURCEDIR:-/usr/src/etc} 371 372# Check the width of the user's terminal 373# 374if [ -t 0 ]; then 375 w=$(stty -a | sed -ne 's/.* \([0-9][0-9]*\) columns.*/\1/p') 376 case "${w}" in 377 0|'') ;; # No-op, since the input is not valid 378 *) 379 case "${SCREEN_WIDTH}" in 380 '') SCREEN_WIDTH="${w}" ;; 381 "${w}") ;; # No-op, since they are the same 382 *) 383 echo -n "*** You entered ${SCREEN_WIDTH} as your screen width, but stty " 384 echo "thinks it is ${w}." 385 echo '' 386 echo -n "What would you like to use? [${w}] " 387 read SCREEN_WIDTH 388 case "${SCREEN_WIDTH}" in 389 '') SCREEN_WIDTH="${w}" ;; 390 esac 391 ;; 392 esac 393 esac 394fi 395 396# Define what CVS $Id tag to look for to aid portability. 397# 398CVS_ID_TAG=FreeBSD 399 400case "${RERUN}" in 401'') 402 # Set up the loop to test for the existence of the 403 # temp root directory. 404 # 405 TEST_TEMP_ROOT=yes 406 while [ "${TEST_TEMP_ROOT}" = "yes" ]; do 407 if [ -d "${TEMPROOT}" ]; then 408 echo "*** The directory specified for the temporary root environment," 409 echo " ${TEMPROOT}, exists. This can be a security risk if untrusted" 410 echo " users have access to the system." 411 echo '' 412 case "${AUTO_RUN}" in 413 '') 414 echo " Use 'd' to delete the old ${TEMPROOT} and continue" 415 echo " Use 't' to select a new temporary root directory" 416 echo " Use 'e' to exit mergemaster" 417 echo '' 418 echo " Default is to use ${TEMPROOT} as is" 419 echo '' 420 echo -n "How should I deal with this? [Use the existing ${TEMPROOT}] " 421 read DELORNOT 422 423 case "${DELORNOT}" in 424 [dD]) 425 echo '' 426 echo " *** Deleting the old ${TEMPROOT}" 427 echo '' 428 rm -rf "${TEMPROOT}" 429 unset TEST_TEMP_ROOT 430 ;; 431 [tT]) 432 echo " *** Enter new directory name for temporary root environment" 433 read TEMPROOT 434 ;; 435 [eE]) 436 exit 0 437 ;; 438 '') 439 echo '' 440 echo " *** Leaving ${TEMPROOT} intact" 441 echo '' 442 unset TEST_TEMP_ROOT 443 ;; 444 *) 445 echo '' 446 echo "invalid choice: ${DELORNOT}" 447 echo '' 448 ;; 449 esac 450 ;; 451 *) 452 # If this is an auto-run, try a hopefully safe alternative then 453 # re-test anyway. 454 TEMPROOT=/var/tmp/temproot.`date +%m%d.%H.%M.%S` 455 ;; 456 esac 457 else 458 unset TEST_TEMP_ROOT 459 fi 460 done 461 462 echo "*** Creating the temporary root environment in ${TEMPROOT}" 463 464 if mkdir -p "${TEMPROOT}"; then 465 echo " *** ${TEMPROOT} ready for use" 466 fi 467 468 if [ ! -d "${TEMPROOT}" ]; then 469 echo '' 470 echo " *** FATAL ERROR: Cannot create ${TEMPROOT}" 471 echo '' 472 exit 1 473 fi 474 475 echo " *** Creating and populating directory structure in ${TEMPROOT}" 476 echo '' 477 478 case "${VERBOSE}" in 479 '') ;; 480 *) 481 press_to_continue 482 ;; 483 esac 484 485 case "${PRE_WORLD}" in 486 '') 487 { cd ${SOURCEDIR} && 488 case "${DESTDIR}" in 489 '') ;; 490 *) 491 make DESTDIR=${DESTDIR} distrib-dirs 492 ;; 493 esac 494 make DESTDIR=${TEMPROOT} distrib-dirs && 495 make MAKEOBJDIRPREFIX=${TEMPROOT}/usr/obj obj && 496 make MAKEOBJDIRPREFIX=${TEMPROOT}/usr/obj DESTDIR=${TEMPROOT} \ 497 -DNO_MAKEDEV_RUN distribution;} || 498 { echo ''; 499 echo " *** FATAL ERROR: Cannot 'cd' to ${SOURCEDIR} and install files to"; 500 echo " the temproot environment"; 501 echo ''; 502 exit 1;} 503 ;; 504 *) 505 # Only set up files that are crucial to {build|install}world 506 { mkdir -p ${TEMPROOT}/etc && 507 cp -p ${SOURCEDIR}/master.passwd ${TEMPROOT}/etc && 508 cp -p ${SOURCEDIR}/group ${TEMPROOT}/etc;} || 509 { echo ''; 510 echo ' *** FATAL ERROR: Cannot copy files to the temproot environment'; 511 echo ''; 512 exit 1;} 513 ;; 514 esac 515 516 # Doing the inventory and removing files that we don't want to compare only 517 # makes sense if we are not doing a rerun, since we have no way of knowing 518 # what happened to the files during previous incarnations. 519 case "${VERBOSE}" in 520 '') ;; 521 *) 522 echo '' 523 echo ' *** The following files exist only in the installed version of' 524 echo " ${DESTDIR}/etc. In the vast majority of cases these files" 525 echo ' are necessary parts of the system and should not be deleted.' 526 echo ' However because these files are not updated by this process you' 527 echo ' might want to verify their status before rebooting your system.' 528 echo '' 529 press_to_continue 530 diff -qr ${DESTDIR}/etc ${TEMPROOT}/etc | grep "^Only in /etc" | ${PAGER} 531 echo '' 532 press_to_continue 533 ;; 534 esac 535 536 # Avoid comparing the motd if the user specifies it in .mergemasterrc 537 case "${IGNORE_MOTD}" in 538 '') ;; 539 *) rm -f ${TEMPROOT}/etc/motd 540 ;; 541 esac 542 543 # Avoid trying to update MAKEDEV if /dev is on a devfs 544 if /sbin/sysctl vfs.devfs.generation > /dev/null 2>&1 ; then 545 rm -f ${TEMPROOT}/dev/MAKEDEV ${TEMPROOT}/dev/MAKEDEV.local 546 fi 547 548 ;; # End of the "RERUN" test 549esac 550 551# We really don't want to have to deal with these files, since 552# master.passwd is the real file that should be compared, then 553# the user should run pwd_mkdb if necessary. 554# 555rm -f ${TEMPROOT}/etc/spwd.db ${TEMPROOT}/etc/passwd ${TEMPROOT}/etc/pwd.db 556 557# We only need to compare things like freebsd.cf once 558find ${TEMPROOT}/usr/obj -type f -delete 2>/dev/null 559 560# Get ready to start comparing files 561 562# Check umask if we are not doing an autorun 563# 564case "${AUTO_RUN}" in 565'') 566 case "${NEW_UMASK}" in 567 '') 568 USER_UMASK=`umask` 569 ;; 570 *) 571 USER_UMASK="${NEW_UMASK}" 572 ;; 573 esac 574 575 case "${USER_UMASK}" in 576 0022|022) ;; 577 *) 578 echo '' 579 echo " *** Your umask is currently set to ${USER_UMASK}. This script installs" 580 echo ' all files with the same user, group, and modes that they' 581 echo " are created with by ${SOURCEDIR}/Makefile." 582 echo '' 583 echo ' If you would like different permissions for the files or' 584 echo ' directories, you will have to set them after installation.' 585 echo '' 586 press_to_continue 587 ;; 588 esac 589 echo '' 590 ;; 591esac 592 593# Warn users who still have ${DESTDIR}/etc/sysconfig 594# 595if [ -e "${DESTDIR}/etc/sysconfig" ]; then 596 echo '' 597 echo " *** There is a sysconfig file on this system in ${DESTDIR}/etc/." 598 echo '' 599 echo ' Starting with FreeBSD version 2.2.2 those settings moved from' 600 echo ' /etc/sysconfig to /etc/rc.conf. If you are upgrading an older' 601 echo ' system make sure that you transfer your settings by hand from' 602 echo ' sysconfig to rc.conf and install the rc.conf file. If you' 603 echo ' have already made this transition, you should consider' 604 echo ' renaming or deleting the sysconfig file.' 605 echo '' 606 case "${AUTO_RUN}" in 607 '') 608 echo -n "Continue with the merge process? [yes] " 609 read CONT_OR_NOT 610 611 case "${CONT_OR_NOT}" in 612 [nN]*) 613 exit 0 614 ;; 615 *) 616 echo " *** Continuing" 617 echo '' 618 ;; 619 esac 620 ;; 621 *) ;; 622 esac 623fi 624 625# Use the mode information to install the files 626# Create directories as needed 627# 628do_install_and_rm () { 629 install -m "${1}" "${2}" "${3}" && 630 rm -f "${2}" 631} 632 633mm_install () { 634 local INSTALL_DIR 635 INSTALL_DIR=${1#.} 636 INSTALL_DIR=${INSTALL_DIR%/*} 637 638 case "${INSTALL_DIR}" in 639 '') 640 INSTALL_DIR=/ 641 ;; 642 esac 643 644 if [ -n "${DESTDIR}${INSTALL_DIR}" -a ! -d "${DESTDIR}${INSTALL_DIR}" ]; then 645 DIR_MODE=`stat -f "%OMp%OLp" "${TEMPROOT}/${INSTALL_DIR}"` 646 install -d -o root -g wheel -m "${DIR_MODE}" "${DESTDIR}${INSTALL_DIR}" 647 fi 648 649 FILE_MODE=`stat -f "%OMp%OLp" "${1}"` 650 651 if [ ! -x "${1}" ]; then 652 case "${1#.}" in 653 /etc/mail/aliases) 654 NEED_NEWALIASES=yes 655 ;; 656 /etc/login.conf) 657 NEED_CAP_MKDB=yes 658 ;; 659 /etc/master.passwd) 660 do_install_and_rm 600 "${1}" "${DESTDIR}${INSTALL_DIR}" 661 NEED_PWD_MKDB=yes 662 DONT_INSTALL=yes 663 ;; 664 /.cshrc | /.profile) 665 case "${AUTO_INSTALL}" in 666 '') 667 case "${LINK_EXPLAINED}" in 668 '') 669 echo " *** Historically BSD derived systems have had a" 670 echo " hard link from /.cshrc and /.profile to" 671 echo " their namesakes in /root. Please indicate" 672 echo " your preference below for bringing your" 673 echo " installed files up to date." 674 echo '' 675 LINK_EXPLAINED=yes 676 ;; 677 esac 678 679 echo " Use 'd' to delete the temporary ${COMPFILE}" 680 echo " Use 'l' to delete the existing ${DESTDIR}${COMPFILE#.} and create the link" 681 echo '' 682 echo " Default is to leave the temporary file to deal with by hand" 683 echo '' 684 echo -n " How should I handle ${COMPFILE}? [Leave it to install later] " 685 read HANDLE_LINK 686 ;; 687 *) # Part of AUTO_INSTALL 688 HANDLE_LINK=l 689 ;; 690 esac 691 692 case "${HANDLE_LINK}" in 693 [dD]*) 694 rm "${COMPFILE}" 695 echo '' 696 echo " *** Deleting ${COMPFILE}" 697 ;; 698 [lL]*) 699 echo '' 700 rm -f "${DESTDIR}${COMPFILE#.}" 701 if ln "${DESTDIR}/root/${COMPFILE##*/}" "${DESTDIR}${COMPFILE#.}"; then 702 echo " *** Link from ${DESTDIR}${COMPFILE#.} to ${DESTDIR}/root/${COMPFILE##*/} installed successfully" 703 rm "${COMPFILE}" 704 else 705 echo " *** Error linking ${DESTDIR}${COMPFILE#.} to ${DESTDIR}/root/${COMPFILE##*/}, ${COMPFILE} will remain to install by hand" 706 fi 707 ;; 708 *) 709 echo " *** ${COMPFILE} will remain for your consideration" 710 ;; 711 esac 712 DONT_INSTALL=yes 713 ;; 714 esac 715 716 case "${DONT_INSTALL}" in 717 '') 718 do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}" 719 ;; 720 *) 721 unset DONT_INSTALL 722 ;; 723 esac 724 else # File matched -x 725 case "${1#.}" in 726 /dev/MAKEDEV) 727 NEED_MAKEDEV=yes 728 ;; 729 esac 730 do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}" 731 fi 732 return $? 733} 734 735echo '' 736echo "*** Beginning comparison" 737echo '' 738 739cd "${TEMPROOT}" 740 741if [ -r "${MM_PRE_COMPARE_SCRIPT}" ]; then 742 . "${MM_PRE_COMPARE_SCRIPT}" 743fi 744 745# Using -size +0 avoids uselessly checking the empty log files created 746# by ${SOURCEDIR}/Makefile and the device entries in ./dev, but does 747# check the scripts in ./dev, as we'd like (assuming no devfs of course). 748# 749for COMPFILE in `find . -type f -size +0`; do 750 751 # First, check to see if the file exists in DESTDIR. If not, the 752 # diff_loop function knows how to handle it. 753 # 754 if [ ! -e "${DESTDIR}${COMPFILE#.}" ]; then 755 case "${AUTO_RUN}" in 756 '') 757 diff_loop 758 ;; 759 *) 760 case "${AUTO_INSTALL}" in 761 '') 762 # If this is an auto run, make it official 763 echo " *** ${COMPFILE} will remain for your consideration" 764 ;; 765 *) 766 diff_loop 767 ;; 768 esac 769 ;; 770 esac # Auto run test 771 continue 772 fi 773 774 case "${STRICT}" in 775 '' | [Nn][Oo]) 776 # Compare CVS $Id's first so if the file hasn't been modified 777 # local changes will be ignored. 778 # If the files have the same $Id, delete the one in temproot so the 779 # user will have less to wade through if files are left to merge by hand. 780 # 781 CVSID1=`grep "[$]${CVS_ID_TAG}:" ${DESTDIR}${COMPFILE#.} 2>/dev/null` 782 CVSID2=`grep "[$]${CVS_ID_TAG}:" ${COMPFILE} 2>/dev/null` || CVSID2=none 783 784 case "${CVSID2}" in 785 "${CVSID1}") 786 echo " *** Temp ${COMPFILE} and installed have the same CVS Id, deleting" 787 rm "${COMPFILE}" 788 ;; 789 esac 790 ;; 791 esac 792 793 # If the file is still here either because the $Ids are different, the 794 # file doesn't have an $Id, or we're using STRICT mode; look at the diff. 795 # 796 if [ -f "${COMPFILE}" ]; then 797 798 # Do an absolute diff first to see if the files are actually different. 799 # If they're not different, delete the one in temproot. 800 # 801 if diff -q "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" > /dev/null 2>&1; then 802 echo " *** Temp ${COMPFILE} and installed are the same, deleting" 803 rm "${COMPFILE}" 804 else 805 # Ok, the files are different, so show the user where they differ. 806 # Use user's choice of diff methods; and user's pager if they have one. 807 # Use more if not. 808 # Use unified diffs by default. Context diffs give me a headache. :) 809 # 810 case "${AUTO_RUN}" in 811 '') 812 # prompt user to install/delete/merge changes 813 diff_loop 814 ;; 815 *) 816 # If this is an auto run, make it official 817 echo " *** ${COMPFILE} will remain for your consideration" 818 ;; 819 esac # Auto run test 820 fi # Yes, the files are different 821 fi # Yes, the file still remains to be checked 822done # This is for the do way up there at the beginning of the comparison 823 824echo '' 825echo "*** Comparison complete" 826echo '' 827 828TEST_FOR_FILES=`find ${TEMPROOT} -type f -size +0 2>/dev/null` 829if [ -n "${TEST_FOR_FILES}" ]; then 830 echo "*** Files that remain for you to merge by hand:" 831 find "${TEMPROOT}" -type f -size +0 832 echo '' 833fi 834 835case "${AUTO_RUN}" in 836'') 837 echo -n "Do you wish to delete what is left of ${TEMPROOT}? [no] " 838 read DEL_TEMPROOT 839 840 case "${DEL_TEMPROOT}" in 841 [yY]*) 842 if rm -rf "${TEMPROOT}"; then 843 echo " *** ${TEMPROOT} has been deleted" 844 else 845 echo " *** Unable to delete ${TEMPROOT}" 846 fi 847 ;; 848 *) 849 echo " *** ${TEMPROOT} will remain" 850 ;; 851 esac 852 ;; 853*) ;; 854esac 855 856case "${AUTO_INSTALLED_FILES}" in 857'') ;; 858*) 859 case "${AUTO_RUN}" in 860 '') 861 ( 862 echo '' 863 echo '*** You chose the automatic install option for files that did not' 864 echo ' exist on your system. The following were installed for you:' 865 echo "${AUTO_INSTALLED_FILES}" 866 ) | ${PAGER} 867 ;; 868 *) 869 echo '' 870 echo '*** You chose the automatic install option for files that did not' 871 echo ' exist on your system. The following were installed for you:' 872 echo "${AUTO_INSTALLED_FILES}" 873 ;; 874 esac 875 ;; 876esac 877 878run_it_now () { 879 case "${AUTO_RUN}" in 880 '') 881 unset YES_OR_NO 882 echo '' 883 echo -n ' Would you like to run it now? y or n [n] ' 884 read YES_OR_NO 885 886 case "${YES_OR_NO}" in 887 y) 888 echo " Running ${1}" 889 echo '' 890 eval "${1}" 891 ;; 892 ''|n) 893 echo '' 894 echo " *** Cancelled" 895 echo '' 896 echo " Make sure to run ${1} yourself" 897 ;; 898 *) 899 echo '' 900 echo " *** Sorry, I do not understand your answer (${YES_OR_NO})" 901 echo '' 902 echo " Make sure to run ${1} yourself" 903 esac 904 ;; 905 *) ;; 906 esac 907} 908 909case "${NEED_MAKEDEV}" in 910'') ;; 911*) 912 echo '' 913 echo "*** You installed a new ${DESTDIR}/dev/MAKEDEV script, so make sure that you run" 914 echo " 'cd ${DESTDIR}/dev && /bin/sh MAKEDEV all' to rebuild your devices" 915 run_it_now "cd ${DESTDIR}/dev && /bin/sh MAKEDEV all" 916 ;; 917esac 918 919case "${NEED_NEWALIASES}" in 920'') ;; 921*) 922 echo '' 923 if [ -n "${DESTDIR}" ]; then 924 echo "*** You installed a new aliases file into ${DESTDIR}/etc/mail, but" 925 echo " the newaliases command is limited to the directories configured" 926 echo " in sendmail.cf. Make sure to create your aliases database by" 927 echo " hand when your sendmail configuration is done." 928 else 929 echo "*** You installed a new aliases file, so make sure that you run" 930 echo " '/usr/bin/newaliases' to rebuild your aliases database" 931 run_it_now '/usr/bin/newaliases' 932 fi 933 ;; 934esac 935 936case "${NEED_CAP_MKDB}" in 937'') ;; 938*) 939 echo '' 940 echo "*** You installed a login.conf file, so make sure that you run" 941 echo " '/usr/bin/cap_mkdb ${DESTDIR}/etc/login.conf'" 942 echo " to rebuild your login.conf database" 943 run_it_now "/usr/bin/cap_mkdb ${DESTDIR}/etc/login.conf" 944 ;; 945esac 946 947case "${NEED_PWD_MKDB}" in 948'') ;; 949*) 950 echo '' 951 echo "*** You installed a new master.passwd file, so make sure that you run" 952 if [ -n "${DESTDIR}" ]; then 953 echo " '/usr/sbin/pwd_mkdb -d ${DESTDIR}/etc -p ${DESTDIR}/etc/master.passwd'" 954 echo " to rebuild your password files" 955 run_it_now "/usr/sbin/pwd_mkdb -d ${DESTDIR}/etc -p ${DESTDIR}/etc/master.passwd" 956 else 957 echo " '/usr/sbin/pwd_mkdb -p /etc/master.passwd'" 958 echo " to rebuild your password files" 959 run_it_now '/usr/sbin/pwd_mkdb -p /etc/master.passwd' 960 fi 961 ;; 962esac 963 964echo '' 965 966if [ -r "${MM_EXIT_SCRIPT}" ]; then 967 . "${MM_EXIT_SCRIPT}" 968fi 969 970case "${COMP_CONFS}" in 971'') ;; 972*) 973 . ${DESTDIR}/etc/defaults/rc.conf 974 975 (echo '' 976 echo "*** Comparing conf files: ${rc_conf_files}" 977 978 for CONF_FILE in ${rc_conf_files}; do 979 if [ -r "${DESTDIR}${CONF_FILE}" ]; then 980 echo '' 981 echo "*** From ${DESTDIR}${CONF_FILE}" 982 echo "*** From ${DESTDIR}/etc/defaults/rc.conf" 983 984 for RC_CONF_VAR in `grep -i ^[a-z] ${DESTDIR}${CONF_FILE} | 985 cut -d '=' -f 1`; do 986 echo '' 987 grep -w ^${RC_CONF_VAR} ${DESTDIR}${CONF_FILE} 988 grep -w ^${RC_CONF_VAR} ${DESTDIR}/etc/defaults/rc.conf || 989 echo ' * No default variable with this name' 990 done 991 fi 992 done) | ${PAGER} 993 echo '' 994 ;; 995esac 996 997case "${PRE_WORLD}" in 998'') ;; 999*) 1000 MAKE_CONF="${SOURCEDIR%etc}share/examples/etc/make.conf" 1001 1002 (echo '' 1003 echo '*** Comparing make variables' 1004 echo '' 1005 echo "*** From ${DESTDIR}/etc/make.conf" 1006 echo "*** From ${MAKE_CONF}" 1007 1008 for MAKE_VAR in `grep -i ^[a-z] /etc/make.conf | cut -d '=' -f 1`; do 1009 echo '' 1010 grep -w ^${MAKE_VAR} ${DESTDIR}/etc/make.conf 1011 grep -w ^#${MAKE_VAR} ${MAKE_CONF} || 1012 echo ' * No example variable with this name' 1013 done) | ${PAGER} 1014 ;; 1015esac 1016 1017exit 0 1018 1019