mergemaster.sh revision 97960
1139825Simp#!/bin/sh 21541Srgrimes 31541Srgrimes# mergemaster 41541Srgrimes 51541Srgrimes# Compare files created by /usr/src/etc/Makefile (or the directory 61541Srgrimes# the user specifies) with the currently installed copies. 71541Srgrimes 81541Srgrimes# Copyright 1998-2002 Douglas Barton 91541Srgrimes# DougB@FreeBSD.org 101541Srgrimes 111541Srgrimes# $FreeBSD: head/usr.sbin/mergemaster/mergemaster.sh 97960 2002-06-06 20:38:22Z dougb $ 121541Srgrimes 131541SrgrimesPATH=/bin:/usr/bin:/usr/sbin 141541Srgrimes 151541Srgrimesdisplay_usage () { 161541Srgrimes VERSION_NUMBER=`grep "[$]FreeBSD:" $0 | cut -d ' ' -f 4` 171541Srgrimes echo "mergemaster version ${VERSION_NUMBER}" 181541Srgrimes echo 'Usage: mergemaster [-scrvahipC] [-m /path]' 191541Srgrimes echo ' [-t /path] [-d] [-u N] [-w N] [-D /path]' 201541Srgrimes echo "Options:" 211541Srgrimes echo " -s Strict comparison (diff every pair of files)" 221541Srgrimes echo " -c Use context diff instead of unified diff" 231541Srgrimes echo " -r Re-run on a previously cleaned directory (skip temproot creation)" 241541Srgrimes echo " -v Be more verbose about the process, include additional checks" 251541Srgrimes echo " -a Leave all files that differ to merge by hand" 261541Srgrimes echo " -h Display more complete help" 271541Srgrimes echo ' -i Automatically install files that do not exist in destination directory' 281541Srgrimes echo ' -p Pre-buildworld mode, only compares crucial files' 291541Srgrimes echo ' -C Compare local rc.conf variables to the defaults' 301541Srgrimes echo " -m /path/directory Specify location of source to do the make in" 311541Srgrimes echo " -t /path/directory Specify temp root directory" 32116226Sobrien echo " -d Add date and time to directory name (e.g., /var/tmp/temproot.`date +%m%d.%H.%M`)" 33116226Sobrien echo " -u N Specify a numeric umask" 34116226Sobrien echo " -w N Specify a screen width in columns to sdiff" 351541Srgrimes echo ' -D /path/directory Specify the destination directory to install files to' 361541Srgrimes echo '' 371541Srgrimes} 3876166Smarkm 3976166Smarkmdisplay_help () { 4076166Smarkm echo "* To specify a directory other than /var/tmp/temproot for the" 4134924Sbde echo " temporary root environment, use -t /path/to/temp/root" 4274927Sjhb echo "* The -w option takes a number as an argument for the column width" 4312662Sdg echo " of the screen. The default is 80." 4493823Sdillon echo '* The -a option causes mergemaster to run without prompting.' 4512662Sdg} 461541Srgrimes 4740794Speter# Loop allowing the user to use sdiff to merge files and display the merged 4812726Sbde# file. 4912662Sdgmerge_loop () { 5012662Sdg case "${VERBOSE}" in 5112662Sdg '') ;; 5212662Sdg *) 531541Srgrimes echo " *** Type h at the sdiff prompt (%) to get usage help" 541541Srgrimes ;; 559759Sbde esac 561541Srgrimes echo '' 5776778Sjhb MERGE_AGAIN=yes 581541Srgrimes while [ "${MERGE_AGAIN}" = "yes" ]; do 5962622Sjhb # Prime file.merged so we don't blat the owner/group id's 6012286Sphk cp -p "${COMPFILE}" "${COMPFILE}.merged" 6162622Sjhb sdiff -o "${COMPFILE}.merged" --text --suppress-common-lines \ 6212286Sphk --width=${SCREEN_WIDTH:-80} "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" 6362622Sjhb INSTALL_MERGED=V 6412286Sphk while [ "${INSTALL_MERGED}" = "v" -o "${INSTALL_MERGED}" = "V" ]; do 6562622Sjhb echo '' 6612286Sphk echo " Use 'i' to install merged file" 6762622Sjhb echo " Use 'r' to re-do the merge" 6812286Sphk echo " Use 'v' to view the merged file" 6962622Sjhb echo " Default is to leave the temporary file to deal with by hand" 7012286Sphk echo '' 7162622Sjhb echo -n " *** How should I deal with the merged file? [Leave it for later] " 7212286Sphk read INSTALL_MERGED 7362622Sjhb 7451337Sdillon case "${INSTALL_MERGED}" in 7512286Sphk [iI]) 76136404Speter mv "${COMPFILE}.merged" "${COMPFILE}" 77136404Speter echo '' 78136404Speter if mm_install "${COMPFILE}"; then 79136404Speter echo " *** Merged version of ${COMPFILE} installed successfully" 80136404Speter else 811541Srgrimes echo " *** Problem installing ${COMPFILE}, it will remain to merge by hand later" 82136404Speter fi 83136404Speter unset MERGE_AGAIN 84136404Speter ;; 85136404Speter [rR]) 86136404Speter rm "${COMPFILE}.merged" 87136404Speter ;; 88136404Speter [vV]) 89136404Speter ${PAGER} "${COMPFILE}.merged" 90136404Speter ;; 91136404Speter '') 92136404Speter echo " *** ${COMPFILE} will remain for your consideration" 93136404Speter unset MERGE_AGAIN 94136404Speter ;; 9512286Sphk *) 9662573Sphk echo "invalid choice: ${INSTALL_MERGED}" 971541Srgrimes INSTALL_MERGED=V 9899072Sjulian ;; 9912286Sphk esac 100164437Sru done 10112286Sphk done 10212286Sphk} 10312286Sphk 1041541Srgrimes# Loop showing user differences between files, allow merge, skip or install 10599072Sjulian# options 106159054Steggediff_loop () { 1071541Srgrimes 108164437Sru HANDLE_COMPFILE=v 1091541Srgrimes 1101541Srgrimes while [ "${HANDLE_COMPFILE}" = "v" -o "${HANDLE_COMPFILE}" = "V" -o \ 1111541Srgrimes "${HANDLE_COMPFILE}" = "NOT V" ]; do 11279224Sdillon if [ -f "${DESTDIR}${COMPFILE#.}" -a -f "${COMPFILE}" ]; then 11395112Salc if [ "${HANDLE_COMPFILE}" = "v" -o "${HANDLE_COMPFILE}" = "V" ]; then 114108551Salc echo '' 115124083Salc echo ' ====================================================================== ' 116124083Salc echo '' 117124083Salc ( 118124083Salc echo '' 119124083Salc echo " *** Displaying differences between ${COMPFILE} and installed version:" 120124083Salc echo '' 121124083Salc diff "${DIFF_FLAG}" "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" 122124083Salc ) | ${PAGER} 12338517Sdfr echo '' 124113448Salc fi 125108551Salc else 12695112Salc echo '' 1271541Srgrimes echo " *** There is no installed version of ${COMPFILE}" 1281541Srgrimes echo '' 1291541Srgrimes case "${AUTO_INSTALL}" in 13074927Sjhb [Yy][Ee][Ss]) 13183366Sjulian echo '' 1321541Srgrimes if mm_install "${COMPFILE}"; then 1331541Srgrimes echo " *** ${COMPFILE} installed successfully" 13472200Sbmilekic echo '' 13599072Sjulian # Make the list print one file per line 13699072Sjulian AUTO_INSTALLED_FILES="${AUTO_INSTALLED_FILES} ${DESTDIR}${COMPFILE#.} 13772200Sbmilekic" 1381541Srgrimes else 1391541Srgrimes echo " *** Problem installing ${COMPFILE}, it will remain to merge by hand" 14099072Sjulian fi 14199072Sjulian return 142103216Sjulian ;; 14399072Sjulian *) 144103216Sjulian NO_INSTALLED=yes 145104387Sjhb ;; 146103216Sjulian esac 147103216Sjulian fi 148164437Sru 149103216Sjulian echo " Use 'd' to delete the temporary ${COMPFILE}" 150103216Sjulian echo " Use 'i' to install the temporary ${COMPFILE}" 151103216Sjulian case "${NO_INSTALLED}" in 15299072Sjulian '') 153164437Sru echo " Use 'm' to merge the temporary and installed versions" 154103216Sjulian echo " Use 'v' to view the diff results again" 155164437Sru ;; 15699072Sjulian esac 15799072Sjulian echo '' 1581541Srgrimes echo " Default is to leave the temporary file to deal with by hand" 159103216Sjulian echo '' 160164437Sru echo -n "How should I deal with this? [Leave it for later] " 161103216Sjulian read HANDLE_COMPFILE 16299072Sjulian 16399072Sjulian case "${HANDLE_COMPFILE}" in 164164437Sru [dD]) 16599072Sjulian rm "${COMPFILE}" 16699072Sjulian echo '' 16799072Sjulian echo " *** Deleting ${COMPFILE}" 16899072Sjulian ;; 16971572Sjhb [iI]) 1701541Srgrimes echo '' 17172200Sbmilekic if mm_install "${COMPFILE}"; then 1721541Srgrimes echo " *** ${COMPFILE} installed successfully" 1731541Srgrimes else 1741541Srgrimes echo " *** Problem installing ${COMPFILE}, it will remain to merge by hand" 1751541Srgrimes fi 176159054Stegge ;; 177159054Stegge [mM]) 178159054Stegge case "${NO_INSTALLED}" in 179159054Stegge '') 180108585Salc # interact with user to merge files 181108585Salc merge_loop 1825455Sdg ;; 18343748Sdillon *) 184108585Salc echo '' 1851541Srgrimes echo " *** There is no installed version of ${COMPFILE}" 186113448Salc echo '' 187108585Salc HANDLE_COMPFILE="NOT V" 188108585Salc ;; 189113448Salc esac # End of "No installed version of file but user selected merge" test 1901541Srgrimes ;; 191108585Salc [vV]) 192159054Stegge continue 1931541Srgrimes ;; 194164437Sru '') 1951541Srgrimes echo '' 19674927Sjhb echo " *** ${COMPFILE} will remain for your consideration" 1971541Srgrimes ;; 1981541Srgrimes *) 1991541Srgrimes # invalid choice, show menu again. 20095112Salc echo "invalid choice: ${HANDLE_COMPFILE}" 20175523Salfred echo '' 20242957Sdillon HANDLE_COMPFILE="NOT V" 203124083Salc continue 204124083Salc ;; 205124083Salc esac # End of "How to handle files that are different" 206124083Salc done 20742957Sdillon unset NO_INSTALLED 208108585Salc echo '' 209124083Salc case "${VERBOSE}" in 210124083Salc '') ;; 211124083Salc *) 21242957Sdillon sleep 3 213108585Salc ;; 214164429Sru esac 215164429Sru} 216164429Sru 217164429Srupress_to_continue () { 218164429Sru local DISCARD 219164429Sru echo -n ' *** Press the [Enter] or [Return] key to continue ' 220164429Sru read DISCARD 221164437Sru} 222164437Sru 2231541Srgrimes# Set the default path for the temporary root environment 224164437Sru# 225164437SruTEMPROOT='/var/tmp/temproot' 2261541Srgrimes 22718169Sdyson# Read /etc/mergemaster.rc first so the one in $HOME can override 2281541Srgrimes# 229164437Sruif [ -r /etc/mergemaster.rc ]; then 230164437Sru . /etc/mergemaster.rc 2311541Srgrimesfi 232164437Sru 233164437Sru# Read .mergemasterrc before command line so CLI can override 2341541Srgrimes# 2351541Srgrimesif [ -r "$HOME/.mergemasterrc" ]; then 2361541Srgrimes . "$HOME/.mergemasterrc" 23795112Salcfi 238164437Sru 239164437Sru# Check the command line options 2401541Srgrimes# 24112286Sphkwhile getopts ":ascrvhipCm:t:du:w:D:" COMMAND_LINE_ARGUMENT ; do 24293823Sdillon case "${COMMAND_LINE_ARGUMENT}" in 24393823Sdillon s) 24493823Sdillon STRICT=yes 24593823Sdillon ;; 24693823Sdillon c) 24793823Sdillon DIFF_FLAG='-c' 24893823Sdillon ;; 24993823Sdillon r) 25093823Sdillon RERUN=yes 25193823Sdillon ;; 25293823Sdillon v) 25393823Sdillon case "${AUTO_RUN}" in 25493823Sdillon '') VERBOSE=yes ;; 25593823Sdillon esac 25693823Sdillon ;; 25793823Sdillon a) 258144970Sjhb AUTO_RUN=yes 25993823Sdillon unset VERBOSE 26093823Sdillon ;; 26193823Sdillon h) 26293823Sdillon display_usage 26393823Sdillon display_help 26493823Sdillon exit 0 26593823Sdillon ;; 266108171Sdillon i) 267108171Sdillon AUTO_INSTALL=yes 26893823Sdillon ;; 269144970Sjhb C) 27093823Sdillon COMP_CONFS=yes 27193823Sdillon ;; 272109097Sdillon p) 27346381Sbillf PRE_WORLD=yes 27446381Sbillf unset COMP_CONFS 275141696Sphk unset AUTO_RUN 276141630Sphk ;; 277141630Sphk m) 278141630Sphk SOURCEDIR=${OPTARG} 279141630Sphk ;; 28040794Speter t) 28193823Sdillon TEMPROOT=${OPTARG} 28293823Sdillon ;; 28393823Sdillon d) 28493823Sdillon TEMPROOT=${TEMPROOT}.`date +%m%d.%H.%M` 28593823Sdillon ;; 28693823Sdillon u) 28793823Sdillon NEW_UMASK=${OPTARG} 28893823Sdillon ;; 28993823Sdillon w) 29093823Sdillon SCREEN_WIDTH=${OPTARG} 29193823Sdillon ;; 29293823Sdillon D) 29393823Sdillon DESTDIR=${OPTARG} 29493823Sdillon ;; 29593823Sdillon *) 29693823Sdillon display_usage 29793823Sdillon exit 1 29893823Sdillon ;; 29993823Sdillon esac 30093823Sdillondone 30193823Sdillon 30293823Sdillonecho '' 30393823Sdillon 30493823Sdillon# If the user has a pager defined, make sure we can run it 30593823Sdillon# 30693823Sdilloncase "${DONT_CHECK_PAGER}" in 30793823Sdillon'') 30893823Sdillon while ! type "${PAGER%% *}" >/dev/null && [ -n "${PAGER}" ]; do 30993823Sdillon echo " *** Your PAGER environment variable specifies '${PAGER}', but" 31093823Sdillon echo " due to the limited PATH that I use for security reasons," 31193823Sdillon echo " I cannot execute it. So, what would you like to do?" 31293823Sdillon echo '' 31393823Sdillon echo " Use 'e' to exit mergemaster and fix your PAGER variable" 31493823Sdillon if [ -x /usr/bin/less -o -x /usr/local/bin/less ]; then 31593823Sdillon echo " Use 'l' to set PAGER to 'less' for this run" 31693823Sdillon fi 31793823Sdillon echo " Use 'm' to use plain old 'more' as your PAGER for this run" 31893823Sdillon echo '' 31993823Sdillon echo " Default is to use plain old 'more' " 32093823Sdillon echo '' 32193823Sdillon echo -n "What should I do? [Use 'more'] " 32293823Sdillon read FIXPAGER 32393823Sdillon 32493823Sdillon case "${FIXPAGER}" in 32593823Sdillon [eE]) 32693823Sdillon exit 0 32793823Sdillon ;; 32893823Sdillon [lL]) 32993823Sdillon if [ -x /usr/bin/less ]; then 33093823Sdillon PAGER=/usr/bin/less 33193823Sdillon elif [ -x /usr/local/bin/less ]; then 33293823Sdillon PAGER=/usr/local/bin/less 33393823Sdillon else 33493823Sdillon echo '' 33593823Sdillon echo " *** Fatal Error:" 33693823Sdillon echo " You asked to use 'less' as your pager, but I can't" 33793823Sdillon echo " find it in /usr/bin or /usr/local/bin" 33893823Sdillon exit 1 33993823Sdillon fi 34093823Sdillon ;; 34193823Sdillon [mM]|'') 34293823Sdillon PAGER=more 34393823Sdillon ;; 34493823Sdillon *) 34593823Sdillon echo '' 34693823Sdillon echo "invalid choice: ${FIXPAGER}" 34793823Sdillon esac 34893823Sdillon echo '' 34993823Sdillon done 35093823Sdillon ;; 35193823Sdillonesac 35293823Sdillon 35393823Sdillon# If user has a pager defined, or got assigned one above, use it. 35493823Sdillon# If not, use more. 35593823Sdillon# 35693823SdillonPAGER=${PAGER:-more} 35793823Sdillon 35893823Sdillonif [ -n "${VERBOSE}" -a ! "${PAGER}" = "more" ]; then 35993823Sdillon echo " *** You have ${PAGER} defined as your pager so we will use that" 36093823Sdillon echo '' 36193823Sdillon sleep 3 36293823Sdillonfi 36393823Sdillon 36493823Sdillon# Assign the diff flag once so we will not have to keep testing it 36593823Sdillon# 36693823SdillonDIFF_FLAG=${DIFF_FLAG:--u} 36793823Sdillon 36893823Sdillon# Assign the source directory 36993823Sdillon# 37093823SdillonSOURCEDIR=${SOURCEDIR:-/usr/src/etc} 37193823Sdillon 37293823Sdillon# Check the width of the user's terminal 37393823Sdillon# 37493823Sdillonif [ -t 0 ]; then 37593823Sdillon w=$(stty -a | sed -ne 's/.* \([0-9][0-9]*\) columns.*/\1/p') 37693823Sdillon case "${w}" in 37793823Sdillon 0|'') ;; # No-op, since the input is not valid 37893823Sdillon *) 37940794Speter case "${SCREEN_WIDTH}" in 38040794Speter '') SCREEN_WIDTH="${w}" ;; 38140794Speter "${w}") ;; # No-op, since they are the same 38240794Speter *) 38340794Speter echo -n "*** You entered ${SCREEN_WIDTH} as your screen width, but stty " 38440794Speter echo "thinks it is ${w}." 38540794Speter echo '' 38640794Speter echo -n "What would you like to use? [${w}] " 38740794Speter read SCREEN_WIDTH 38840794Speter case "${SCREEN_WIDTH}" in 38940794Speter '') SCREEN_WIDTH="${w}" ;; 39040794Speter 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