mergemaster.sh revision 224726
152400Sbillf#!/bin/sh 252400Sbillf 352400Sbillf# mergemaster 452400Sbillf 552400Sbillf# Compare files created by /usr/src/etc/Makefile (or the directory 652400Sbillf# the user specifies) with the currently installed copies. 752400Sbillf 8224726Sdougb# Copyright 1998-2011 Douglas Barton 9224726Sdougb# dougb@FreeBSD.org 1052400Sbillf 1152495Sbillf# $FreeBSD: head/usr.sbin/mergemaster/mergemaster.sh 224726 2011-08-09 07:42:19Z dougb $ 1252400Sbillf 1368507SdougbPATH=/bin:/usr/bin:/usr/sbin 1452400Sbillf 1552400Sbillfdisplay_usage () { 1652533Sbillf VERSION_NUMBER=`grep "[$]FreeBSD:" $0 | cut -d ' ' -f 4` 1752400Sbillf echo "mergemaster version ${VERSION_NUMBER}" 18205145Sdougb echo 'Usage: mergemaster [-scrvhpCP] [-a|[-iFU]]' 19189763Sdougb echo ' [-m /path] [-t /path] [-d] [-u N] [-w N] [-A arch] [-D /path]' 2052400Sbillf echo "Options:" 2152400Sbillf echo " -s Strict comparison (diff every pair of files)" 2252400Sbillf echo " -c Use context diff instead of unified diff" 2352400Sbillf echo " -r Re-run on a previously cleaned directory (skip temproot creation)" 2452400Sbillf echo " -v Be more verbose about the process, include additional checks" 2552400Sbillf echo " -a Leave all files that differ to merge by hand" 2652400Sbillf echo " -h Display more complete help" 2767949Sdougb echo ' -i Automatically install files that do not exist in destination directory' 2891193Sdougb echo ' -p Pre-buildworld mode, only compares crucial files' 29190320Sdougb echo ' -F Install files that differ only by revision control Id ($FreeBSD)' 3091193Sdougb echo ' -C Compare local rc.conf variables to the defaults' 31114501Sdougb echo ' -P Preserve files that are overwritten' 32189763Sdougb echo " -U Attempt to auto upgrade files that have not been user modified" 33224726Sdougb echo ' ***DANGEROUS***' 34189763Sdougb echo '' 3552400Sbillf echo " -m /path/directory Specify location of source to do the make in" 3652400Sbillf echo " -t /path/directory Specify temp root directory" 3752400Sbillf echo " -d Add date and time to directory name (e.g., /var/tmp/temproot.`date +%m%d.%H.%M`)" 3852400Sbillf echo " -u N Specify a numeric umask" 3952400Sbillf echo " -w N Specify a screen width in columns to sdiff" 40155309Srwatson echo " -A architecture Alternative architecture name to pass to make" 4167949Sdougb echo ' -D /path/directory Specify the destination directory to install files to' 4252400Sbillf echo '' 4352400Sbillf} 4452400Sbillf 4552400Sbillfdisplay_help () { 4652400Sbillf echo "* To specify a directory other than /var/tmp/temproot for the" 4752400Sbillf echo " temporary root environment, use -t /path/to/temp/root" 4852400Sbillf echo "* The -w option takes a number as an argument for the column width" 4967859Sdougb echo " of the screen. The default is 80." 5067949Sdougb echo '* The -a option causes mergemaster to run without prompting.' 5152400Sbillf} 5252400Sbillf 5358910Salfred# Loop allowing the user to use sdiff to merge files and display the merged 5458910Salfred# file. 5558910Salfredmerge_loop () { 5667850Sdougb case "${VERBOSE}" in 5767850Sdougb '') ;; 5867850Sdougb *) 5967850Sdougb echo " *** Type h at the sdiff prompt (%) to get usage help" 6067850Sdougb ;; 6167850Sdougb esac 6267850Sdougb echo '' 6367850Sdougb MERGE_AGAIN=yes 6467850Sdougb while [ "${MERGE_AGAIN}" = "yes" ]; do 6567850Sdougb # Prime file.merged so we don't blat the owner/group id's 6667850Sdougb cp -p "${COMPFILE}" "${COMPFILE}.merged" 6767850Sdougb sdiff -o "${COMPFILE}.merged" --text --suppress-common-lines \ 6867949Sdougb --width=${SCREEN_WIDTH:-80} "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" 6967850Sdougb INSTALL_MERGED=V 7067850Sdougb while [ "${INSTALL_MERGED}" = "v" -o "${INSTALL_MERGED}" = "V" ]; do 7167850Sdougb echo '' 7267850Sdougb echo " Use 'i' to install merged file" 7367850Sdougb echo " Use 'r' to re-do the merge" 7467850Sdougb echo " Use 'v' to view the merged file" 7567850Sdougb echo " Default is to leave the temporary file to deal with by hand" 7667850Sdougb echo '' 7767859Sdougb echo -n " *** How should I deal with the merged file? [Leave it for later] " 7867859Sdougb read INSTALL_MERGED 7958910Salfred 8067850Sdougb case "${INSTALL_MERGED}" in 8167850Sdougb [iI]) 8267850Sdougb mv "${COMPFILE}.merged" "${COMPFILE}" 8367850Sdougb echo '' 8467850Sdougb if mm_install "${COMPFILE}"; then 8567850Sdougb echo " *** Merged version of ${COMPFILE} installed successfully" 8667859Sdougb else 8767850Sdougb echo " *** Problem installing ${COMPFILE}, it will remain to merge by hand later" 8867859Sdougb fi 8967850Sdougb unset MERGE_AGAIN 9067850Sdougb ;; 9167850Sdougb [rR]) 9267850Sdougb rm "${COMPFILE}.merged" 9367859Sdougb ;; 9467850Sdougb [vV]) 9567850Sdougb ${PAGER} "${COMPFILE}.merged" 9667850Sdougb ;; 9767850Sdougb '') 9867850Sdougb echo " *** ${COMPFILE} will remain for your consideration" 9967850Sdougb unset MERGE_AGAIN 10067850Sdougb ;; 10167850Sdougb *) 10267850Sdougb echo "invalid choice: ${INSTALL_MERGED}" 10367850Sdougb INSTALL_MERGED=V 10467850Sdougb ;; 10567850Sdougb esac 10667850Sdougb done 10767850Sdougb done 10858910Salfred} 10958910Salfred 11058910Salfred# Loop showing user differences between files, allow merge, skip or install 11158910Salfred# options 11258910Salfreddiff_loop () { 11358910Salfred 11467850Sdougb HANDLE_COMPFILE=v 11558910Salfred 11677323Sdougb while [ "${HANDLE_COMPFILE}" = "v" -o "${HANDLE_COMPFILE}" = "V" -o \ 11777323Sdougb "${HANDLE_COMPFILE}" = "NOT V" ]; do 11867949Sdougb if [ -f "${DESTDIR}${COMPFILE#.}" -a -f "${COMPFILE}" ]; then 119192230Sdougb if [ -n "${AUTO_UPGRADE}" -a -n "${CHANGED}" ]; then 120192230Sdougb case "${CHANGED}" in 121192230Sdougb *:${DESTDIR}${COMPFILE#.}:*) ;; # File has been modified 122192230Sdougb *) 123158149Sgordon echo '' 124158149Sgordon echo " *** ${COMPFILE} has not been user modified." 125158149Sgordon echo '' 126158149Sgordon 127158149Sgordon if mm_install "${COMPFILE}"; then 128158149Sgordon echo " *** ${COMPFILE} upgraded successfully" 129158149Sgordon echo '' 130158149Sgordon # Make the list print one file per line 131158149Sgordon AUTO_UPGRADED_FILES="${AUTO_UPGRADED_FILES} ${DESTDIR}${COMPFILE#.} 132158149Sgordon" 133158149Sgordon else 134192230Sdougb echo " *** Problem upgrading ${COMPFILE}, it will remain to merge by hand" 135158149Sgordon fi 136158149Sgordon return 137192230Sdougb ;; 138192230Sdougb esac 139158149Sgordon fi 14067850Sdougb if [ "${HANDLE_COMPFILE}" = "v" -o "${HANDLE_COMPFILE}" = "V" ]; then 14190564Sdougb echo '' 142109993Sdillon echo ' ====================================================================== ' 143109993Sdillon echo '' 144109993Sdillon ( 145109993Sdillon echo " *** Displaying differences between ${COMPFILE} and installed version:" 146109993Sdillon echo '' 147110377Sdougb diff ${DIFF_FLAG} ${DIFF_OPTIONS} "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" 148109993Sdillon ) | ${PAGER} 149109993Sdillon echo '' 15067850Sdougb fi 15167850Sdougb else 152109993Sdillon echo '' 15367850Sdougb echo " *** There is no installed version of ${COMPFILE}" 15491193Sdougb echo '' 15567949Sdougb case "${AUTO_INSTALL}" in 15667949Sdougb [Yy][Ee][Ss]) 15767949Sdougb echo '' 15867949Sdougb if mm_install "${COMPFILE}"; then 15967949Sdougb echo " *** ${COMPFILE} installed successfully" 16068507Sdougb echo '' 16167949Sdougb # Make the list print one file per line 16267949Sdougb AUTO_INSTALLED_FILES="${AUTO_INSTALLED_FILES} ${DESTDIR}${COMPFILE#.} 16367949Sdougb" 16467949Sdougb else 16567949Sdougb echo " *** Problem installing ${COMPFILE}, it will remain to merge by hand" 16667949Sdougb fi 16767949Sdougb return 16867949Sdougb ;; 16967949Sdougb *) 17067949Sdougb NO_INSTALLED=yes 17167949Sdougb ;; 17267949Sdougb esac 17367850Sdougb fi 17467859Sdougb 17567850Sdougb echo " Use 'd' to delete the temporary ${COMPFILE}" 17667850Sdougb echo " Use 'i' to install the temporary ${COMPFILE}" 17767850Sdougb case "${NO_INSTALLED}" in 17867850Sdougb '') 17977326Sdougb echo " Use 'm' to merge the temporary and installed versions" 180109993Sdillon echo " Use 'v' to view the diff results again" 18167850Sdougb ;; 18267850Sdougb esac 18367850Sdougb echo '' 18467850Sdougb echo " Default is to leave the temporary file to deal with by hand" 18567850Sdougb echo '' 18667859Sdougb echo -n "How should I deal with this? [Leave it for later] " 18767859Sdougb read HANDLE_COMPFILE 18867859Sdougb 18967850Sdougb case "${HANDLE_COMPFILE}" in 19067850Sdougb [dD]) 19167850Sdougb rm "${COMPFILE}" 19267850Sdougb echo '' 19367850Sdougb echo " *** Deleting ${COMPFILE}" 19467850Sdougb ;; 19567850Sdougb [iI]) 19667850Sdougb echo '' 19767850Sdougb if mm_install "${COMPFILE}"; then 19867850Sdougb echo " *** ${COMPFILE} installed successfully" 19967850Sdougb else 20067850Sdougb echo " *** Problem installing ${COMPFILE}, it will remain to merge by hand" 20167850Sdougb fi 20267850Sdougb ;; 20367850Sdougb [mM]) 20467850Sdougb case "${NO_INSTALLED}" in 20567850Sdougb '') 20667850Sdougb # interact with user to merge files 20767850Sdougb merge_loop 20867850Sdougb ;; 20967850Sdougb *) 21067850Sdougb echo '' 21167850Sdougb echo " *** There is no installed version of ${COMPFILE}" 21267850Sdougb echo '' 21367850Sdougb HANDLE_COMPFILE="NOT V" 21467850Sdougb ;; 21567850Sdougb esac # End of "No installed version of file but user selected merge" test 21667850Sdougb ;; 21767850Sdougb [vV]) 21867850Sdougb continue 21967850Sdougb ;; 22067850Sdougb '') 22167850Sdougb echo '' 22267850Sdougb echo " *** ${COMPFILE} will remain for your consideration" 22367850Sdougb ;; 22467850Sdougb *) 22567850Sdougb # invalid choice, show menu again. 22667850Sdougb echo "invalid choice: ${HANDLE_COMPFILE}" 22767850Sdougb echo '' 22867850Sdougb HANDLE_COMPFILE="NOT V" 22967850Sdougb continue 23067850Sdougb ;; 23167850Sdougb esac # End of "How to handle files that are different" 23267859Sdougb done 23367850Sdougb unset NO_INSTALLED 23467850Sdougb echo '' 23567850Sdougb case "${VERBOSE}" in 23667850Sdougb '') ;; 23767850Sdougb *) 23867850Sdougb sleep 3 23967850Sdougb ;; 24067850Sdougb esac 24158910Salfred} 24258910Salfred 24397960Sdougbpress_to_continue () { 24497960Sdougb local DISCARD 24597960Sdougb echo -n ' *** Press the [Enter] or [Return] key to continue ' 24697960Sdougb read DISCARD 24797960Sdougb} 24897960Sdougb 24952400Sbillf# Set the default path for the temporary root environment 25052400Sbillf# 25152400SbillfTEMPROOT='/var/tmp/temproot' 25252400Sbillf 25373651Sdougb# Read /etc/mergemaster.rc first so the one in $HOME can override 25473651Sdougb# 25573651Sdougbif [ -r /etc/mergemaster.rc ]; then 25673651Sdougb . /etc/mergemaster.rc 25773651Sdougbfi 25873651Sdougb 25952400Sbillf# Read .mergemasterrc before command line so CLI can override 26052400Sbillf# 26167949Sdougbif [ -r "$HOME/.mergemasterrc" ]; then 26252400Sbillf . "$HOME/.mergemasterrc" 26352400Sbillffi 26452400Sbillf 26552400Sbillf# Check the command line options 26652400Sbillf# 267189992Sdougbwhile getopts ":ascrvhipCPm:t:du:w:D:A:FU" COMMAND_LINE_ARGUMENT ; do 26852400Sbillf case "${COMMAND_LINE_ARGUMENT}" in 269155309Srwatson A) 270186678Sdougb ARCHSTRING='TARGET_ARCH='${OPTARG} 271155309Srwatson ;; 272189992Sdougb F) 273189992Sdougb FREEBSD_ID=yes 274189992Sdougb ;; 275158149Sgordon U) 276158149Sgordon AUTO_UPGRADE=yes 277158149Sgordon ;; 27852400Sbillf s) 27952400Sbillf STRICT=yes 280110377Sdougb unset DIFF_OPTIONS 28152400Sbillf ;; 28252400Sbillf c) 28352400Sbillf DIFF_FLAG='-c' 28452400Sbillf ;; 28552400Sbillf r) 28652400Sbillf RERUN=yes 28752400Sbillf ;; 28852400Sbillf v) 28952400Sbillf case "${AUTO_RUN}" in 29052400Sbillf '') VERBOSE=yes ;; 29152400Sbillf esac 29252400Sbillf ;; 29352400Sbillf a) 29452400Sbillf AUTO_RUN=yes 29552400Sbillf unset VERBOSE 29652400Sbillf ;; 29752400Sbillf h) 29852400Sbillf display_usage 29952400Sbillf display_help 30052400Sbillf exit 0 30152400Sbillf ;; 30267949Sdougb i) 30367949Sdougb AUTO_INSTALL=yes 30467949Sdougb ;; 30596045Sdougb C) 30696045Sdougb COMP_CONFS=yes 30796045Sdougb ;; 308114501Sdougb P) 309114501Sdougb PRESERVE_FILES=yes 310114501Sdougb ;; 31191193Sdougb p) 31291193Sdougb PRE_WORLD=yes 31396045Sdougb unset COMP_CONFS 31496045Sdougb unset AUTO_RUN 31591193Sdougb ;; 31652400Sbillf m) 31752400Sbillf SOURCEDIR=${OPTARG} 31852400Sbillf ;; 31952400Sbillf t) 32052400Sbillf TEMPROOT=${OPTARG} 32152400Sbillf ;; 32252400Sbillf d) 32352400Sbillf TEMPROOT=${TEMPROOT}.`date +%m%d.%H.%M` 32452400Sbillf ;; 32552400Sbillf u) 32652400Sbillf NEW_UMASK=${OPTARG} 32752400Sbillf ;; 32852400Sbillf w) 32952400Sbillf SCREEN_WIDTH=${OPTARG} 33052400Sbillf ;; 33167949Sdougb D) 33267949Sdougb DESTDIR=${OPTARG} 33367949Sdougb ;; 33452400Sbillf *) 33552400Sbillf display_usage 33652400Sbillf exit 1 33752400Sbillf ;; 33852400Sbillf esac 33952400Sbillfdone 34052400Sbillf 341205145Sdougbif [ -n "$AUTO_RUN" ]; then 342205145Sdougb if [ -n "$FREEBSD_ID" -o -n "$AUTO_UPGRADE" -o -n "$AUTO_INSTALL" ]; then 343205145Sdougb echo '' 344205145Sdougb echo "*** You have included the -a option along with one or more options" 345205145Sdougb echo ' that indicate that you wish mergemaster to actually make updates' 346205145Sdougb echo ' (-F, -U, or -i), however these options are not compatible.' 347205145Sdougb echo ' Please read mergemaster(8) for more information.' 348205145Sdougb echo '' 349205145Sdougb exit 1 350205145Sdougb fi 351205145Sdougbfi 352205145Sdougb 353202817Sdougb# Assign the location of the mtree database 354202817Sdougb# 355202817SdougbMTREEDB=${MTREEDB:-${DESTDIR}/var/db} 356202817SdougbMTREEFILE="${MTREEDB}/mergemaster.mtree" 357202817Sdougb 358114501Sdougb# Don't force the user to set this in the mergemaster rc file 359114501Sdougbif [ -n "${PRESERVE_FILES}" -a -z "${PRESERVE_FILES_DIR}" ]; then 360114501Sdougb PRESERVE_FILES_DIR=/var/tmp/mergemaster/preserved-files-`date +%y%m%d-%H%M%S` 361200425Sdougb mkdir -p ${PRESERVE_FILES_DIR} 362114501Sdougbfi 363114501Sdougb 364186678Sdougb# Check for the mtree database in DESTDIR 365186678Sdougbcase "${AUTO_UPGRADE}" in 366186678Sdougb'') ;; # If the option is not set no need to run the test or warn the user 367186678Sdougb*) 368200416Sdougb if [ ! -s "${MTREEFILE}" ]; then 369186678Sdougb echo '' 370200416Sdougb echo "*** Unable to find mtree database (${MTREEFILE})." 371200416Sdougb echo " Skipping auto-upgrade on this run." 372193853Sdougb echo " It will be created for the next run when this one is complete." 373186678Sdougb echo '' 374201291Sdougb case "${AUTO_RUN}" in 375201291Sdougb '') 376201291Sdougb press_to_continue 377201291Sdougb ;; 378201291Sdougb esac 379186678Sdougb unset AUTO_UPGRADE 380186678Sdougb fi 381186678Sdougb ;; 382186678Sdougbesac 383186678Sdougb 384186689Sdougbif [ -e "${DESTDIR}/etc/fstab" ]; then 385186689Sdougb if grep -q nodev ${DESTDIR}/etc/fstab; then 386186689Sdougb echo '' 387186689Sdougb echo "*** You have the deprecated 'nodev' option in ${DESTDIR}/etc/fstab." 388186689Sdougb echo " This can prevent the filesystem from being mounted on reboot." 389186689Sdougb echo " Please update your fstab before continuing." 390186689Sdougb echo " See fstab(5) for more information." 391186689Sdougb echo '' 392186689Sdougb exit 1 393186689Sdougb fi 394158149Sgordonfi 395158149Sgordon 39652400Sbillfecho '' 39752400Sbillf 39852400Sbillf# If the user has a pager defined, make sure we can run it 39952400Sbillf# 40052400Sbillfcase "${DONT_CHECK_PAGER}" in 40152400Sbillf'') 402186695Sdougbcheck_pager () { 403186695Sdougb while ! type "${PAGER%% *}" >/dev/null; do 40452400Sbillf echo " *** Your PAGER environment variable specifies '${PAGER}', but" 40564467Sbrian echo " due to the limited PATH that I use for security reasons," 40667859Sdougb echo " I cannot execute it. So, what would you like to do?" 40752400Sbillf echo '' 40852400Sbillf echo " Use 'e' to exit mergemaster and fix your PAGER variable" 40964467Sbrian if [ -x /usr/bin/less -o -x /usr/local/bin/less ]; then 41064467Sbrian echo " Use 'l' to set PAGER to 'less' for this run" 41152400Sbillf fi 41252400Sbillf echo " Use 'm' to use plain old 'more' as your PAGER for this run" 41352400Sbillf echo '' 41452400Sbillf echo " Default is to use plain old 'more' " 41552400Sbillf echo '' 41667859Sdougb echo -n "What should I do? [Use 'more'] " 41767859Sdougb read FIXPAGER 41867859Sdougb 41952400Sbillf case "${FIXPAGER}" in 42058910Salfred [eE]) 42152400Sbillf exit 0 42252400Sbillf ;; 42358910Salfred [lL]) 42464467Sbrian if [ -x /usr/bin/less ]; then 42564467Sbrian PAGER=/usr/bin/less 42664467Sbrian elif [ -x /usr/local/bin/less ]; then 42758910Salfred PAGER=/usr/local/bin/less 42864467Sbrian else 42964467Sbrian echo '' 43064467Sbrian echo " *** Fatal Error:" 43164467Sbrian echo " You asked to use 'less' as your pager, but I can't" 43264467Sbrian echo " find it in /usr/bin or /usr/local/bin" 43364467Sbrian exit 1 43458910Salfred fi 43552400Sbillf ;; 43660420Sbsd [mM]|'') 43752400Sbillf PAGER=more 43852400Sbillf ;; 43958910Salfred *) 44058910Salfred echo '' 44158910Salfred echo "invalid choice: ${FIXPAGER}" 44252400Sbillf esac 44352400Sbillf echo '' 44458910Salfred done 445186695Sdougb} 446186695Sdougb if [ -n "${PAGER}" ]; then 447186695Sdougb check_pager 448186695Sdougb fi 44952400Sbillf ;; 45052400Sbillfesac 45152400Sbillf 45252400Sbillf# If user has a pager defined, or got assigned one above, use it. 45352400Sbillf# If not, use more. 45452400Sbillf# 45552400SbillfPAGER=${PAGER:-more} 45652400Sbillf 45752400Sbillfif [ -n "${VERBOSE}" -a ! "${PAGER}" = "more" ]; then 45852400Sbillf echo " *** You have ${PAGER} defined as your pager so we will use that" 45952400Sbillf echo '' 46052400Sbillf sleep 3 46152400Sbillffi 46252400Sbillf 46352400Sbillf# Assign the diff flag once so we will not have to keep testing it 46452400Sbillf# 46552400SbillfDIFF_FLAG=${DIFF_FLAG:--u} 46652400Sbillf 46752400Sbillf# Assign the source directory 46852400Sbillf# 469186678SdougbSOURCEDIR=${SOURCEDIR:-/usr/src} 470186678Sdougbif [ ! -f ${SOURCEDIR}/Makefile.inc1 -a \ 471186678Sdougb -f ${SOURCEDIR}/../Makefile.inc1 ]; then 472186678Sdougb echo " *** The source directory you specified (${SOURCEDIR})" 473186678Sdougb echo " will be reset to ${SOURCEDIR}/.." 474186678Sdougb echo '' 475186678Sdougb sleep 3 476186678Sdougb SOURCEDIR=${SOURCEDIR}/.. 477186678Sdougbfi 47852400Sbillf 479186678Sdougb# Setup make to use system files from SOURCEDIR 480186695SdougbMM_MAKE="make ${ARCHSTRING} -m ${SOURCEDIR}/share/mk" 481186678Sdougb 482158149Sgordon# Check DESTDIR against the mergemaster mtree database to see what 483158149Sgordon# files the user changed from the reference files. 484158149Sgordon# 485200416Sdougbif [ -n "${AUTO_UPGRADE}" -a -s "${MTREEFILE}" ]; then 486192230Sdougb CHANGED=: 487200416Sdougb for file in `mtree -eqL -f ${MTREEFILE} -p ${DESTDIR}/ \ 488158149Sgordon 2>/dev/null | awk '($2 == "changed") {print $1}'`; do 489158149Sgordon if [ -f "${DESTDIR}/$file" ]; then 490192230Sdougb CHANGED="${CHANGED}${DESTDIR}/${file}:" 491158149Sgordon fi 492158149Sgordon done 493192230Sdougb [ "$CHANGED" = ':' ] && unset CHANGED 494158149Sgordonfi 495158149Sgordon 49696045Sdougb# Check the width of the user's terminal 49796045Sdougb# 49896045Sdougbif [ -t 0 ]; then 499110377Sdougb w=`tput columns` 50096045Sdougb case "${w}" in 50196045Sdougb 0|'') ;; # No-op, since the input is not valid 50296045Sdougb *) 50396045Sdougb case "${SCREEN_WIDTH}" in 50496045Sdougb '') SCREEN_WIDTH="${w}" ;; 50596045Sdougb "${w}") ;; # No-op, since they are the same 50696045Sdougb *) 50796045Sdougb echo -n "*** You entered ${SCREEN_WIDTH} as your screen width, but stty " 50896045Sdougb echo "thinks it is ${w}." 50996045Sdougb echo '' 51096045Sdougb echo -n "What would you like to use? [${w}] " 51196045Sdougb read SCREEN_WIDTH 51297380Sdougb case "${SCREEN_WIDTH}" in 51397380Sdougb '') SCREEN_WIDTH="${w}" ;; 51497380Sdougb esac 51596045Sdougb ;; 51696045Sdougb esac 51796045Sdougb esac 51896045Sdougbfi 51996045Sdougb 52073651Sdougb# Define what CVS $Id tag to look for to aid portability. 52173651Sdougb# 52273651SdougbCVS_ID_TAG=FreeBSD 52373651Sdougb 52499152Sdougbdelete_temproot () { 525101362Sdougb rm -rf "${TEMPROOT}" 2>/dev/null 526101362Sdougb chflags -R 0 "${TEMPROOT}" 2>/dev/null 527201765Sdougb rm -rf "${TEMPROOT}" || { echo "*** Unable to delete ${TEMPROOT}"; exit 1; } 52899152Sdougb} 52999152Sdougb 53052400Sbillfcase "${RERUN}" in 53152400Sbillf'') 53252400Sbillf # Set up the loop to test for the existence of the 53352400Sbillf # temp root directory. 53452400Sbillf # 53552400Sbillf TEST_TEMP_ROOT=yes 53652400Sbillf while [ "${TEST_TEMP_ROOT}" = "yes" ]; do 53752400Sbillf if [ -d "${TEMPROOT}" ]; then 53852400Sbillf echo "*** The directory specified for the temporary root environment," 53967859Sdougb echo " ${TEMPROOT}, exists. This can be a security risk if untrusted" 54052400Sbillf echo " users have access to the system." 54152400Sbillf echo '' 54252400Sbillf case "${AUTO_RUN}" in 54352400Sbillf '') 54452400Sbillf echo " Use 'd' to delete the old ${TEMPROOT} and continue" 54552400Sbillf echo " Use 't' to select a new temporary root directory" 54652400Sbillf echo " Use 'e' to exit mergemaster" 54752400Sbillf echo '' 54852400Sbillf echo " Default is to use ${TEMPROOT} as is" 54952400Sbillf echo '' 55067859Sdougb echo -n "How should I deal with this? [Use the existing ${TEMPROOT}] " 55167859Sdougb read DELORNOT 55267859Sdougb 55367859Sdougb case "${DELORNOT}" in 55467859Sdougb [dD]) 55567859Sdougb echo '' 55667859Sdougb echo " *** Deleting the old ${TEMPROOT}" 55767859Sdougb echo '' 558201765Sdougb delete_temproot 55967859Sdougb unset TEST_TEMP_ROOT 56052400Sbillf ;; 56167859Sdougb [tT]) 56267859Sdougb echo " *** Enter new directory name for temporary root environment" 56367859Sdougb read TEMPROOT 56467859Sdougb ;; 56567859Sdougb [eE]) 56667859Sdougb exit 0 56767859Sdougb ;; 56867859Sdougb '') 56967859Sdougb echo '' 57067859Sdougb echo " *** Leaving ${TEMPROOT} intact" 57167859Sdougb echo '' 57267859Sdougb unset TEST_TEMP_ROOT 57367859Sdougb ;; 57467859Sdougb *) 57567859Sdougb echo '' 57667859Sdougb echo "invalid choice: ${DELORNOT}" 57767859Sdougb echo '' 57867859Sdougb ;; 57967859Sdougb esac 58067859Sdougb ;; 58152400Sbillf *) 58277323Sdougb # If this is an auto-run, try a hopefully safe alternative then 58377323Sdougb # re-test anyway. 58452400Sbillf TEMPROOT=/var/tmp/temproot.`date +%m%d.%H.%M.%S` 58552400Sbillf ;; 58652400Sbillf esac 58752400Sbillf else 58852400Sbillf unset TEST_TEMP_ROOT 58952400Sbillf fi 59052400Sbillf done 59152400Sbillf 59252400Sbillf echo "*** Creating the temporary root environment in ${TEMPROOT}" 59352400Sbillf 59452400Sbillf if mkdir -p "${TEMPROOT}"; then 59552400Sbillf echo " *** ${TEMPROOT} ready for use" 59652400Sbillf fi 59752400Sbillf 59852400Sbillf if [ ! -d "${TEMPROOT}" ]; then 59952400Sbillf echo '' 60052400Sbillf echo " *** FATAL ERROR: Cannot create ${TEMPROOT}" 60152400Sbillf echo '' 60252400Sbillf exit 1 60352400Sbillf fi 60452400Sbillf 60552400Sbillf echo " *** Creating and populating directory structure in ${TEMPROOT}" 60652400Sbillf echo '' 60752400Sbillf 60852400Sbillf case "${VERBOSE}" in 60952400Sbillf '') ;; 61052400Sbillf *) 61197960Sdougb press_to_continue 61252400Sbillf ;; 61352400Sbillf esac 61452400Sbillf 61591193Sdougb case "${PRE_WORLD}" in 61691193Sdougb '') 61791193Sdougb { cd ${SOURCEDIR} && 61891193Sdougb case "${DESTDIR}" in 61991193Sdougb '') ;; 62091193Sdougb *) 621208088Sdougb ${MM_MAKE} DESTDIR=${DESTDIR} distrib-dirs >/dev/null 62291193Sdougb ;; 62391193Sdougb esac 624186749Sdougb od=${TEMPROOT}/usr/obj 625208088Sdougb ${MM_MAKE} DESTDIR=${TEMPROOT} distrib-dirs >/dev/null && 626208088Sdougb MAKEOBJDIRPREFIX=$od ${MM_MAKE} _obj SUBDIR_OVERRIDE=etc >/dev/null && 627208088Sdougb MAKEOBJDIRPREFIX=$od ${MM_MAKE} everything SUBDIR_OVERRIDE=etc >/dev/null && 628208088Sdougb MAKEOBJDIRPREFIX=$od ${MM_MAKE} DESTDIR=${TEMPROOT} distribution >/dev/null;} || 62991193Sdougb { echo ''; 63091193Sdougb echo " *** FATAL ERROR: Cannot 'cd' to ${SOURCEDIR} and install files to"; 63191193Sdougb echo " the temproot environment"; 63291193Sdougb echo ''; 63391193Sdougb exit 1;} 63491193Sdougb ;; 63591193Sdougb *) 63691193Sdougb # Only set up files that are crucial to {build|install}world 63791193Sdougb { mkdir -p ${TEMPROOT}/etc && 638186678Sdougb cp -p ${SOURCEDIR}/etc/master.passwd ${TEMPROOT}/etc && 639224726Sdougb install -p -o root -g wheel -m 0644 ${SOURCEDIR}/etc/group ${TEMPROOT}/etc;} || 64091193Sdougb { echo ''; 64191193Sdougb echo ' *** FATAL ERROR: Cannot copy files to the temproot environment'; 64291193Sdougb echo ''; 64391193Sdougb exit 1;} 64491193Sdougb ;; 64591193Sdougb esac 64652400Sbillf 64777323Sdougb # Doing the inventory and removing files that we don't want to compare only 64877323Sdougb # makes sense if we are not doing a rerun, since we have no way of knowing 64977323Sdougb # what happened to the files during previous incarnations. 65067949Sdougb case "${VERBOSE}" in 65167949Sdougb '') ;; 65267949Sdougb *) 65367949Sdougb echo '' 65467949Sdougb echo ' *** The following files exist only in the installed version of' 65567949Sdougb echo " ${DESTDIR}/etc. In the vast majority of cases these files" 65667949Sdougb echo ' are necessary parts of the system and should not be deleted.' 65767949Sdougb echo ' However because these files are not updated by this process you' 65867949Sdougb echo ' might want to verify their status before rebooting your system.' 65967949Sdougb echo '' 66097960Sdougb press_to_continue 661101348Sdougb diff -qr ${DESTDIR}/etc ${TEMPROOT}/etc | grep "^Only in ${DESTDIR}/etc" | ${PAGER} 66267949Sdougb echo '' 66397960Sdougb press_to_continue 66467949Sdougb ;; 66567949Sdougb esac 66667949Sdougb 66752534Sbillf case "${IGNORE_MOTD}" in 668202340Sdougb '') ;; 669202339Sdougb *) 670186678Sdougb echo '' 671186678Sdougb echo "*** You have the IGNORE_MOTD option set in your mergemaster rc file." 672186678Sdougb echo " This option is deprecated in favor of the IGNORE_FILES option." 673186678Sdougb echo " Please update your rc file accordingly." 674186678Sdougb echo '' 675202339Sdougb exit 1 67652534Sbillf ;; 67752534Sbillf esac 67852534Sbillf 679186678Sdougb # Avoid comparing the following user specified files 680186678Sdougb for file in ${IGNORE_FILES}; do 681186688Sdougb test -e ${TEMPROOT}/${file} && unlink ${TEMPROOT}/${file} 682186678Sdougb done 68352400Sbillf 684201291Sdougb # We really don't want to have to deal with files like login.conf.db, pwd.db, 685201291Sdougb # or spwd.db. Instead, we want to compare the text versions, and run *_mkdb. 686201291Sdougb # Prompt the user to do so below, as needed. 687201291Sdougb # 688201291Sdougb rm -f ${TEMPROOT}/etc/*.db ${TEMPROOT}/etc/passwd 68977478Sdougb 690201291Sdougb # We only need to compare things like freebsd.cf once 691201291Sdougb find ${TEMPROOT}/usr/obj -type f -delete 2>/dev/null 69294196Sdougb 693201291Sdougb # Delete stuff we do not need to keep the mtree database small, 694201291Sdougb # and to make the actual comparison faster. 695201291Sdougb find ${TEMPROOT}/usr -type l -delete 2>/dev/null 696201291Sdougb find ${TEMPROOT} -type f -size 0 -delete 2>/dev/null 697201291Sdougb find -d ${TEMPROOT} -type d -empty -delete 2>/dev/null 698158149Sgordon 699201291Sdougb # Build the mtree database in a temporary location. 700201291Sdougb case "${PRE_WORLD}" in 701201323Sdougb '') MTREENEW=`mktemp -t mergemaster.mtree` 702201323Sdougb mtree -ci -p ${TEMPROOT} -k size,md5digest > ${MTREENEW} 2>/dev/null 703201291Sdougb ;; 704201291Sdougb *) # We don't want to mess with the mtree database on a pre-world run or 705201291Sdougb # when re-scanning a previously-built tree. 706201291Sdougb ;; 707201291Sdougb esac 708201291Sdougb ;; # End of the "RERUN" test 709158149Sgordonesac 710158149Sgordon 71152400Sbillf# Get ready to start comparing files 71252400Sbillf 71398084Sdougb# Check umask if not specified on the command line, 71498084Sdougb# and we are not doing an autorun 71552400Sbillf# 71698084Sdougbif [ -z "${NEW_UMASK}" -a -z "${AUTO_RUN}" ]; then 71798084Sdougb USER_UMASK=`umask` 71852400Sbillf case "${USER_UMASK}" in 71977335Sdougb 0022|022) ;; 72052400Sbillf *) 72152400Sbillf echo '' 72298084Sdougb echo " *** Your umask is currently set to ${USER_UMASK}. By default, this script" 72398084Sdougb echo " installs all files with the same user, group and modes that" 724186678Sdougb echo " they are created with by ${SOURCEDIR}/etc/Makefile, compared to" 72598084Sdougb echo " a umask of 022. This umask allows world read permission when" 72698084Sdougb echo " the file's default permissions have it." 72752400Sbillf echo '' 72898084Sdougb echo " No world permissions can sometimes cause problems. A umask of" 72998084Sdougb echo " 022 will restore the default behavior, but is not mandatory." 73098084Sdougb echo " /etc/master.passwd is a special case. Its file permissions" 73198084Sdougb echo " will be 600 (rw-------) if installed." 73297960Sdougb echo '' 73398084Sdougb echo -n "What umask should I use? [${USER_UMASK}] " 73498084Sdougb read NEW_UMASK 73598084Sdougb 73698084Sdougb NEW_UMASK="${NEW_UMASK:-$USER_UMASK}" 73752400Sbillf ;; 73852400Sbillf esac 73952400Sbillf echo '' 74098084Sdougbfi 74152400Sbillf 74298084SdougbCONFIRMED_UMASK=${NEW_UMASK:-0022} 74398084Sdougb 74452400Sbillf# 745114501Sdougb# Warn users who still have old rc files 746114501Sdougb# 747179315Sbzfor file in atm devfs diskless1 diskless2 network network6 pccard \ 748114523Sdougb serial syscons sysctl alpha amd64 i386 ia64 sparc64; do 749114501Sdougb if [ -f "${DESTDIR}/etc/rc.${file}" ]; then 750114501Sdougb OLD_RC_PRESENT=1 751114501Sdougb break 752114501Sdougb fi 753114501Sdougbdone 754114501Sdougb 755114501Sdougbcase "${OLD_RC_PRESENT}" in 756114501Sdougb1) 75752400Sbillf echo '' 758114501Sdougb echo " *** There are elements of the old rc system in ${DESTDIR}/etc/." 75967949Sdougb echo '' 760114501Sdougb echo ' While these scripts will not hurt anything, they are not' 761114501Sdougb echo ' functional on an up to date system, and can be removed.' 76267949Sdougb echo '' 763114501Sdougb 76452400Sbillf case "${AUTO_RUN}" in 76552400Sbillf '') 766114501Sdougb echo -n 'Move these files to /var/tmp/mergemaster/old_rc? [yes] ' 767114501Sdougb read MOVE_OLD_RC 76867859Sdougb 769114501Sdougb case "${MOVE_OLD_RC}" in 770114501Sdougb [nN]*) ;; 77152400Sbillf *) 772114501Sdougb mkdir -p /var/tmp/mergemaster/old_rc 773179315Sbz for file in atm devfs diskless1 diskless2 network network6 pccard \ 774114523Sdougb serial syscons sysctl alpha amd64 i386 ia64 sparc64; do 775114501Sdougb if [ -f "${DESTDIR}/etc/rc.${file}" ]; then 776114501Sdougb mv ${DESTDIR}/etc/rc.${file} /var/tmp/mergemaster/old_rc/ 777114501Sdougb fi 778114501Sdougb done 779114501Sdougb echo ' The files have been moved' 780114501Sdougb press_to_continue 78152400Sbillf ;; 78252400Sbillf esac 78352400Sbillf ;; 78452400Sbillf *) ;; 78552400Sbillf esac 786114501Sdougbesac 78752400Sbillf 78898084Sdougb# Use the umask/mode information to install the files 78952400Sbillf# Create directories as needed 79052400Sbillf# 791186678Sdougbinstall_error () { 792186678Sdougb echo "*** FATAL ERROR: Unable to install ${1} to ${2}" 793186678Sdougb echo '' 794186678Sdougb exit 1 795186678Sdougb} 796186678Sdougb 79778490Sdougbdo_install_and_rm () { 798114501Sdougb case "${PRESERVE_FILES}" in 799114501Sdougb [Yy][Ee][Ss]) 800114501Sdougb if [ -f "${3}/${2##*/}" ]; then 801114565Sdougb mkdir -p ${PRESERVE_FILES_DIR}/${2%/*} 802114565Sdougb cp ${3}/${2##*/} ${PRESERVE_FILES_DIR}/${2%/*} 803114501Sdougb fi 804114501Sdougb ;; 805114501Sdougb esac 806114501Sdougb 807186678Sdougb if [ ! -d "${3}/${2##*/}" ]; then 808186678Sdougb if install -m ${1} ${2} ${3}; then 809186678Sdougb unlink ${2} 810186678Sdougb else 811186678Sdougb install_error ${2} ${3} 812186678Sdougb fi 813186678Sdougb else 814186678Sdougb install_error ${2} ${3} 815186678Sdougb fi 81678490Sdougb} 81778490Sdougb 81898084Sdougb# 4095 = "obase=10;ibase=8;07777" | bc 81998084Sdougbfind_mode () { 82098084Sdougb local OCTAL 82198084Sdougb OCTAL=$(( ~$(echo "obase=10; ibase=8; ${CONFIRMED_UMASK}" | bc) & 4095 & 822124053Sdougb $(echo "obase=10; ibase=8; $(stat -f "%OMp%OLp" ${1})" | bc) )) 82398084Sdougb printf "%04o\n" ${OCTAL} 82498084Sdougb} 82598084Sdougb 82652400Sbillfmm_install () { 82752400Sbillf local INSTALL_DIR 82852400Sbillf INSTALL_DIR=${1#.} 82952400Sbillf INSTALL_DIR=${INSTALL_DIR%/*} 83067949Sdougb 83152400Sbillf case "${INSTALL_DIR}" in 83252400Sbillf '') 83352400Sbillf INSTALL_DIR=/ 83452400Sbillf ;; 83552400Sbillf esac 83652400Sbillf 83767949Sdougb if [ -n "${DESTDIR}${INSTALL_DIR}" -a ! -d "${DESTDIR}${INSTALL_DIR}" ]; then 83898084Sdougb DIR_MODE=`find_mode "${TEMPROOT}/${INSTALL_DIR}"` 839200425Sdougb install -d -o root -g wheel -m "${DIR_MODE}" "${DESTDIR}${INSTALL_DIR}" || 840200425Sdougb install_error $1 ${DESTDIR}${INSTALL_DIR} 84152400Sbillf fi 84252400Sbillf 84398084Sdougb FILE_MODE=`find_mode "${1}"` 84452400Sbillf 84552400Sbillf if [ ! -x "${1}" ]; then 84652400Sbillf case "${1#.}" in 84764625Sgshapiro /etc/mail/aliases) 84852400Sbillf NEED_NEWALIASES=yes 84952400Sbillf ;; 85052400Sbillf /etc/login.conf) 85152400Sbillf NEED_CAP_MKDB=yes 85252400Sbillf ;; 853207612Snork /etc/services) 854207612Snork NEED_SERVICES_MKDB=yes 855207612Snork ;; 85652400Sbillf /etc/master.passwd) 85778490Sdougb do_install_and_rm 600 "${1}" "${DESTDIR}${INSTALL_DIR}" 85852400Sbillf NEED_PWD_MKDB=yes 85952400Sbillf DONT_INSTALL=yes 86052400Sbillf ;; 86152400Sbillf /.cshrc | /.profile) 862200708Sdougb local st_nlink 863200708Sdougb 864200708Sdougb # install will unlink the file before it installs the new one, 865200708Sdougb # so we have to restore/create the link afterwards. 866200708Sdougb # 867200708Sdougb st_nlink=0 # In case the file does not yet exist 868200708Sdougb eval $(stat -s ${DESTDIR}${COMPFILE#.} 2>/dev/null) 869200708Sdougb 870200708Sdougb do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}" 871200708Sdougb 872200708Sdougb if [ -n "${AUTO_INSTALL}" -a $st_nlink -gt 1 ]; then 873200708Sdougb HANDLE_LINK=l 874200708Sdougb else 875200701Sdougb case "${LINK_EXPLAINED}" in 876200701Sdougb '') 877200701Sdougb echo " *** Historically BSD derived systems have had a" 878200701Sdougb echo " hard link from /.cshrc and /.profile to" 879200701Sdougb echo " their namesakes in /root. Please indicate" 880200701Sdougb echo " your preference below for bringing your" 881200701Sdougb echo " installed files up to date." 882200701Sdougb echo '' 883200701Sdougb LINK_EXPLAINED=yes 884200701Sdougb ;; 885200701Sdougb esac 886200701Sdougb 887200701Sdougb echo " Use 'd' to delete the temporary ${COMPFILE}" 888200708Sdougb echo " Use 'l' to delete the existing ${DESTDIR}/root/${COMPFILE##*/} and create the link" 88952400Sbillf echo '' 890200701Sdougb echo " Default is to leave the temporary file to deal with by hand" 891200701Sdougb echo '' 892200701Sdougb echo -n " How should I handle ${COMPFILE}? [Leave it to install later] " 893200701Sdougb read HANDLE_LINK 894200708Sdougb fi 89552400Sbillf 89652400Sbillf case "${HANDLE_LINK}" in 89752400Sbillf [dD]*) 89852400Sbillf rm "${COMPFILE}" 89952400Sbillf echo '' 90052400Sbillf echo " *** Deleting ${COMPFILE}" 90152400Sbillf ;; 90252400Sbillf [lL]*) 90352400Sbillf echo '' 904200708Sdougb unlink ${DESTDIR}/root/${COMPFILE##*/} 905200708Sdougb if ln ${DESTDIR}${COMPFILE#.} ${DESTDIR}/root/${COMPFILE##*/}; then 90667949Sdougb echo " *** Link from ${DESTDIR}${COMPFILE#.} to ${DESTDIR}/root/${COMPFILE##*/} installed successfully" 90752400Sbillf else 908200708Sdougb echo " *** Error linking ${DESTDIR}${COMPFILE#.} to ${DESTDIR}/root/${COMPFILE##*/}" 909200708Sdougb echo " *** ${COMPFILE} will remain for your consideration" 91052400Sbillf fi 91152400Sbillf ;; 91252400Sbillf *) 91352400Sbillf echo " *** ${COMPFILE} will remain for your consideration" 91452400Sbillf ;; 91552400Sbillf esac 916200708Sdougb return 91752400Sbillf ;; 91852400Sbillf esac 91952400Sbillf 92052400Sbillf case "${DONT_INSTALL}" in 92152400Sbillf '') 92278490Sdougb do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}" 92352400Sbillf ;; 92452400Sbillf *) 92552400Sbillf unset DONT_INSTALL 92652400Sbillf ;; 92752400Sbillf esac 92878490Sdougb else # File matched -x 92978490Sdougb do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}" 93052400Sbillf fi 93152400Sbillf return $? 93252400Sbillf} 93352400Sbillf 934174841Sdougbif [ ! -d "${TEMPROOT}" ]; then 935174841Sdougb echo "*** FATAL ERROR: The temproot directory (${TEMPROOT})" 936174841Sdougb echo ' has disappeared!' 937174841Sdougb echo '' 938174841Sdougb exit 1 939174841Sdougbfi 940174841Sdougb 94167949Sdougbecho '' 94267949Sdougbecho "*** Beginning comparison" 94367949Sdougbecho '' 94452400Sbillf 945124136Sdougb# Pre-world does not populate /etc/rc.d. 946124053Sdougb# It is very possible that a previous run would have deleted files in 947124053Sdougb# ${TEMPROOT}/etc/rc.d, thus creating a lot of false positives. 948124136Sdougbif [ -z "${PRE_WORLD}" -a -z "${RERUN}" ]; then 949124053Sdougb echo " *** Checking ${DESTDIR}/etc/rc.d for stale files" 950124053Sdougb echo '' 951124053Sdougb cd "${DESTDIR}/etc/rc.d" && 952124053Sdougb for file in *; do 953124053Sdougb if [ ! -e "${TEMPROOT}/etc/rc.d/${file}" ]; then 954124053Sdougb STALE_RC_FILES="${STALE_RC_FILES} ${file}" 955124053Sdougb fi 956124053Sdougb done 957124053Sdougb case "${STALE_RC_FILES}" in 958126718Sdougb ''|' *') 959124053Sdougb echo ' *** No stale files found' 960124053Sdougb ;; 961124053Sdougb *) 962124053Sdougb echo " *** The following files exist in ${DESTDIR}/etc/rc.d but not in" 963124053Sdougb echo " ${TEMPROOT}/etc/rc.d/:" 964124053Sdougb echo '' 965124053Sdougb echo "${STALE_RC_FILES}" 966124053Sdougb echo '' 967124053Sdougb echo ' The presence of stale files in this directory can cause the' 968124053Sdougb echo ' dreaded unpredictable results, and therefore it is highly' 969124053Sdougb echo ' recommended that you delete them.' 970124053Sdougb case "${AUTO_RUN}" in 971124053Sdougb '') 972124053Sdougb echo '' 973153604Sdougb echo -n ' *** Delete them now? [n] ' 974124053Sdougb read DELETE_STALE_RC_FILES 975124053Sdougb case "${DELETE_STALE_RC_FILES}" in 976153604Sdougb [yY]) 977124053Sdougb echo ' *** Deleting ... ' 978124053Sdougb rm ${STALE_RC_FILES} 979124053Sdougb echo ' done.' 980124053Sdougb ;; 981153604Sdougb *) 982153604Sdougb echo ' *** Files will not be deleted' 983153604Sdougb ;; 984124053Sdougb esac 985124053Sdougb sleep 2 986124053Sdougb ;; 987201291Sdougb *) 988201291Sdougb if [ -n "${DELETE_STALE_RC_FILES}" ]; then 989201291Sdougb echo ' *** Deleting ... ' 990201291Sdougb rm ${STALE_RC_FILES} 991201291Sdougb echo ' done.' 992201291Sdougb fi 993124053Sdougb esac 994124053Sdougb ;; 995124053Sdougb esac 996124053Sdougb echo '' 997124136Sdougbfi 998124053Sdougb 99967949Sdougbcd "${TEMPROOT}" 100067949Sdougb 100167949Sdougbif [ -r "${MM_PRE_COMPARE_SCRIPT}" ]; then 100267949Sdougb . "${MM_PRE_COMPARE_SCRIPT}" 100367949Sdougbfi 100467949Sdougb 1005200425Sdougb# Things that were files/directories/links in one version can sometimes 1006200425Sdougb# change to something else in a newer version. So we need to explicitly 1007200425Sdougb# test for this, and warn the user if what we find does not match. 1008200425Sdougb# 1009200700Sdougbfor COMPFILE in `find . | sort` ; do 1010200425Sdougb if [ -e "${DESTDIR}${COMPFILE#.}" ]; then 1011200425Sdougb INSTALLED_TYPE=`stat -f '%HT' ${DESTDIR}${COMPFILE#.}` 1012200425Sdougb else 1013200425Sdougb continue 1014200425Sdougb fi 1015200425Sdougb TEMPROOT_TYPE=`stat -f '%HT' $COMPFILE` 1016200425Sdougb 1017200425Sdougb if [ ! "$TEMPROOT_TYPE" = "$INSTALLED_TYPE" ]; then 1018200425Sdougb [ "$COMPFILE" = '.' ] && continue 1019200425Sdougb TEMPROOT_TYPE=`echo $TEMPROOT_TYPE | tr [:upper:] [:lower:]` 1020200425Sdougb INSTALLED_TYPE=`echo $INSTALLED_TYPE | tr [:upper:] [:lower:]` 1021200425Sdougb 1022200425Sdougb echo "*** The installed file ${DESTDIR}${COMPFILE#.} has the type \"$INSTALLED_TYPE\"" 1023200425Sdougb echo " but the new version has the type \"$TEMPROOT_TYPE\"" 1024200425Sdougb echo '' 1025200425Sdougb echo " How would you like to handle this?" 1026200425Sdougb echo '' 1027200425Sdougb echo " Use 'r' to remove ${DESTDIR}${COMPFILE#.}" 1028200425Sdougb case "$TEMPROOT_TYPE" in 1029200425Sdougb 'symbolic link') 1030200425Sdougb TARGET=`readlink $COMPFILE` 1031200425Sdougb echo " and create a link to $TARGET in its place" ;; 1032200425Sdougb *) echo " You will be able to install it as a \"$TEMPROOT_TYPE\"" ;; 1033200425Sdougb esac 1034200425Sdougb echo '' 1035200425Sdougb echo " Use 'i' to ignore this" 1036200425Sdougb echo '' 1037200425Sdougb echo -n " How to proceed? [i] " 1038200425Sdougb read ANSWER 1039200425Sdougb case "$ANSWER" in 1040200425Sdougb [rR]) case "${PRESERVE_FILES}" in 1041200425Sdougb [Yy][Ee][Ss]) 1042200425Sdougb mv ${DESTDIR}${COMPFILE#.} ${PRESERVE_FILES_DIR}/ || exit 1 ;; 1043200425Sdougb *) rm -rf ${DESTDIR}${COMPFILE#.} ;; 1044200425Sdougb esac 1045200425Sdougb case "$TEMPROOT_TYPE" in 1046200425Sdougb 'symbolic link') ln -sf $TARGET ${DESTDIR}${COMPFILE#.} ;; 1047200425Sdougb esac ;; 1048200425Sdougb *) echo '' 1049200425Sdougb echo "*** See the man page about adding ${COMPFILE#.} to the list of IGNORE_FILES" 1050200425Sdougb press_to_continue ;; 1051200425Sdougb esac 1052200425Sdougb echo '' 1053200425Sdougb fi 1054200425Sdougbdone 1055200425Sdougb 1056200700Sdougbfor COMPFILE in `find . -type f | sort`; do 105767949Sdougb 105867949Sdougb # First, check to see if the file exists in DESTDIR. If not, the 105967949Sdougb # diff_loop function knows how to handle it. 106067949Sdougb # 106167949Sdougb if [ ! -e "${DESTDIR}${COMPFILE#.}" ]; then 106277325Sdougb case "${AUTO_RUN}" in 106377325Sdougb '') 106477325Sdougb diff_loop 106577325Sdougb ;; 106677325Sdougb *) 106777325Sdougb case "${AUTO_INSTALL}" in 106877325Sdougb '') 106977325Sdougb # If this is an auto run, make it official 107077325Sdougb echo " *** ${COMPFILE} will remain for your consideration" 107177325Sdougb ;; 107277325Sdougb *) 107377325Sdougb diff_loop 107477325Sdougb ;; 107577325Sdougb esac 107677325Sdougb ;; 107777325Sdougb esac # Auto run test 107867949Sdougb continue 107967949Sdougb fi 108067949Sdougb 108152400Sbillf case "${STRICT}" in 108252400Sbillf '' | [Nn][Oo]) 108352400Sbillf # Compare CVS $Id's first so if the file hasn't been modified 108452400Sbillf # local changes will be ignored. 108552400Sbillf # If the files have the same $Id, delete the one in temproot so the 108652400Sbillf # user will have less to wade through if files are left to merge by hand. 108752400Sbillf # 108873651Sdougb CVSID1=`grep "[$]${CVS_ID_TAG}:" ${DESTDIR}${COMPFILE#.} 2>/dev/null` 108990564Sdougb CVSID2=`grep "[$]${CVS_ID_TAG}:" ${COMPFILE} 2>/dev/null` || CVSID2=none 109052400Sbillf 109167949Sdougb case "${CVSID2}" in 109273651Sdougb "${CVSID1}") 109367949Sdougb echo " *** Temp ${COMPFILE} and installed have the same CVS Id, deleting" 109467949Sdougb rm "${COMPFILE}" 109567949Sdougb ;; 109667949Sdougb esac 109752400Sbillf ;; 109852400Sbillf esac 109952400Sbillf 110052400Sbillf # If the file is still here either because the $Ids are different, the 110152400Sbillf # file doesn't have an $Id, or we're using STRICT mode; look at the diff. 110252400Sbillf # 110352400Sbillf if [ -f "${COMPFILE}" ]; then 110452400Sbillf 110552400Sbillf # Do an absolute diff first to see if the files are actually different. 110652400Sbillf # If they're not different, delete the one in temproot. 110752400Sbillf # 1108110377Sdougb if diff -q ${DIFF_OPTIONS} "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" > \ 1109110377Sdougb /dev/null 2>&1; then 111052400Sbillf echo " *** Temp ${COMPFILE} and installed are the same, deleting" 111152400Sbillf rm "${COMPFILE}" 111252400Sbillf else 111377323Sdougb # Ok, the files are different, so show the user where they differ. 111477323Sdougb # Use user's choice of diff methods; and user's pager if they have one. 111577323Sdougb # Use more if not. 111667859Sdougb # Use unified diffs by default. Context diffs give me a headache. :) 111752400Sbillf # 1118189992Sdougb # If the user chose the -F option, test for that before proceeding 1119189992Sdougb # 1120189992Sdougb if [ -n "$FREEBSD_ID" ]; then 1121201291Sdougb if diff -q -I'[$]FreeBSD.*[$]' "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" > \ 1122189992Sdougb /dev/null 2>&1; then 1123189992Sdougb if mm_install "${COMPFILE}"; then 1124189992Sdougb echo "*** Updated revision control Id for ${DESTDIR}${COMPFILE#.}" 1125189992Sdougb else 1126189992Sdougb echo "*** Problem installing ${COMPFILE}, it will remain to merge by hand later" 1127189992Sdougb fi 1128189992Sdougb continue 1129189992Sdougb fi 1130189992Sdougb fi 113152400Sbillf case "${AUTO_RUN}" in 113252400Sbillf '') 113358910Salfred # prompt user to install/delete/merge changes 113458910Salfred diff_loop 113552400Sbillf ;; 113652400Sbillf *) 113752400Sbillf # If this is an auto run, make it official 113852400Sbillf echo " *** ${COMPFILE} will remain for your consideration" 113952400Sbillf ;; 114052400Sbillf esac # Auto run test 114152400Sbillf fi # Yes, the files are different 114252400Sbillf fi # Yes, the file still remains to be checked 1143189763Sdougbdone # This is for the for way up there at the beginning of the comparison 114452400Sbillf 114552534Sbillfecho '' 114652400Sbillfecho "*** Comparison complete" 1147158149Sgordon 1148192230Sdougbif [ -s "${MTREENEW}" ]; then 1149158149Sgordon echo "*** Saving mtree database for future upgrades" 1150200416Sdougb test -e "${MTREEFILE}" && unlink ${MTREEFILE} 1151200416Sdougb mv ${MTREENEW} ${MTREEFILE} 1152158149Sgordonfi 1153158149Sgordon 115452400Sbillfecho '' 115552400Sbillf 115652400SbillfTEST_FOR_FILES=`find ${TEMPROOT} -type f -size +0 2>/dev/null` 115752400Sbillfif [ -n "${TEST_FOR_FILES}" ]; then 115852400Sbillf echo "*** Files that remain for you to merge by hand:" 1159200700Sdougb find "${TEMPROOT}" -type f -size +0 | sort 116077335Sdougb echo '' 116152400Sbillf 1162201765Sdougb case "${AUTO_RUN}" in 1163201765Sdougb '') 1164201765Sdougb echo -n "Do you wish to delete what is left of ${TEMPROOT}? [no] " 1165201765Sdougb read DEL_TEMPROOT 1166201765Sdougb case "${DEL_TEMPROOT}" in 1167201765Sdougb [yY]*) 1168201765Sdougb delete_temproot 1169201765Sdougb ;; 1170201765Sdougb *) 1171201765Sdougb echo " *** ${TEMPROOT} will remain" 1172201765Sdougb ;; 1173201765Sdougb esac 117452400Sbillf ;; 1175201765Sdougb *) ;; 117652400Sbillf esac 1177201765Sdougbelse 1178201765Sdougb echo "*** ${TEMPROOT} is empty, deleting" 1179201765Sdougb delete_temproot 1180201765Sdougbfi 118152400Sbillf 118268153Sdougbcase "${AUTO_INSTALLED_FILES}" in 118368153Sdougb'') ;; 118468153Sdougb*) 118573651Sdougb case "${AUTO_RUN}" in 118673651Sdougb '') 118773651Sdougb ( 118873651Sdougb echo '' 118977323Sdougb echo '*** You chose the automatic install option for files that did not' 119077323Sdougb echo ' exist on your system. The following were installed for you:' 119173651Sdougb echo "${AUTO_INSTALLED_FILES}" 119273651Sdougb ) | ${PAGER} 119373651Sdougb ;; 119473651Sdougb *) 119568153Sdougb echo '' 119677323Sdougb echo '*** You chose the automatic install option for files that did not' 119777323Sdougb echo ' exist on your system. The following were installed for you:' 119868153Sdougb echo "${AUTO_INSTALLED_FILES}" 119973651Sdougb ;; 120073651Sdougb esac 120168153Sdougb ;; 120268153Sdougbesac 120368153Sdougb 1204158149Sgordoncase "${AUTO_UPGRADED_FILES}" in 1205158149Sgordon'') ;; 1206158149Sgordon*) 1207158149Sgordon case "${AUTO_RUN}" in 1208158149Sgordon '') 1209158149Sgordon ( 1210158149Sgordon echo '' 1211158149Sgordon echo '*** You chose the automatic upgrade option for files that you did' 1212158149Sgordon echo ' not alter on your system. The following were upgraded for you:' 1213158149Sgordon echo "${AUTO_UPGRADED_FILES}" 1214158149Sgordon ) | ${PAGER} 1215158149Sgordon ;; 1216158149Sgordon *) 1217158149Sgordon echo '' 1218158149Sgordon echo '*** You chose the automatic upgrade option for files that you did' 1219158149Sgordon echo ' not alter on your system. The following were upgraded for you:' 1220158149Sgordon echo "${AUTO_UPGRADED_FILES}" 1221158149Sgordon ;; 1222158149Sgordon esac 1223158149Sgordon ;; 1224158149Sgordonesac 1225158149Sgordon 122673651Sdougbrun_it_now () { 122773651Sdougb case "${AUTO_RUN}" in 122873651Sdougb '') 122973651Sdougb unset YES_OR_NO 123073651Sdougb echo '' 123177335Sdougb echo -n ' Would you like to run it now? y or n [n] ' 123273651Sdougb read YES_OR_NO 123373651Sdougb 123473651Sdougb case "${YES_OR_NO}" in 123573651Sdougb y) 123677335Sdougb echo " Running ${1}" 123777335Sdougb echo '' 123873651Sdougb eval "${1}" 123973651Sdougb ;; 124077335Sdougb ''|n) 124177335Sdougb echo '' 124277335Sdougb echo " *** Cancelled" 124377335Sdougb echo '' 124477335Sdougb echo " Make sure to run ${1} yourself" 124577335Sdougb ;; 124673651Sdougb *) 124777335Sdougb echo '' 124877335Sdougb echo " *** Sorry, I do not understand your answer (${YES_OR_NO})" 124977335Sdougb echo '' 125077335Sdougb echo " Make sure to run ${1} yourself" 125173651Sdougb esac 125273651Sdougb ;; 125373651Sdougb *) ;; 125473651Sdougb esac 125573651Sdougb} 125673651Sdougb 125752400Sbillfcase "${NEED_NEWALIASES}" in 125852400Sbillf'') ;; 125952400Sbillf*) 126052400Sbillf echo '' 126177335Sdougb if [ -n "${DESTDIR}" ]; then 126277335Sdougb echo "*** You installed a new aliases file into ${DESTDIR}/etc/mail, but" 126377335Sdougb echo " the newaliases command is limited to the directories configured" 126477335Sdougb echo " in sendmail.cf. Make sure to create your aliases database by" 126577335Sdougb echo " hand when your sendmail configuration is done." 126677335Sdougb else 126777335Sdougb echo "*** You installed a new aliases file, so make sure that you run" 126877335Sdougb echo " '/usr/bin/newaliases' to rebuild your aliases database" 126977335Sdougb run_it_now '/usr/bin/newaliases' 127077335Sdougb fi 127152400Sbillf ;; 127252400Sbillfesac 127352400Sbillf 127452400Sbillfcase "${NEED_CAP_MKDB}" in 127552400Sbillf'') ;; 127652400Sbillf*) 127752400Sbillf echo '' 127852400Sbillf echo "*** You installed a login.conf file, so make sure that you run" 127977335Sdougb echo " '/usr/bin/cap_mkdb ${DESTDIR}/etc/login.conf'" 128077335Sdougb echo " to rebuild your login.conf database" 128177335Sdougb run_it_now "/usr/bin/cap_mkdb ${DESTDIR}/etc/login.conf" 128252400Sbillf ;; 128352400Sbillfesac 128452400Sbillf 1285207612Snorkcase "${NEED_SERVICES_MKDB}" in 1286207612Snork'') ;; 1287207612Snork*) 1288207612Snork echo '' 1289207612Snork echo "*** You installed a services file, so make sure that you run" 1290207612Snork echo " '/usr/sbin/services_mkdb -q -o ${DESTDIR}/var/db/services.db ${DESTDIR}/etc/services'" 1291207612Snork echo " to rebuild your services database" 1292207612Snork run_it_now "/usr/sbin/services_mkdb -q -o ${DESTDIR}/var/db/services.db ${DESTDIR}/etc/services" 1293207612Snork ;; 1294207612Snorkesac 1295207612Snork 129652400Sbillfcase "${NEED_PWD_MKDB}" in 129752400Sbillf'') ;; 129852400Sbillf*) 129952400Sbillf echo '' 130052400Sbillf echo "*** You installed a new master.passwd file, so make sure that you run" 130177335Sdougb if [ -n "${DESTDIR}" ]; then 130277335Sdougb echo " '/usr/sbin/pwd_mkdb -d ${DESTDIR}/etc -p ${DESTDIR}/etc/master.passwd'" 130377335Sdougb echo " to rebuild your password files" 130477335Sdougb run_it_now "/usr/sbin/pwd_mkdb -d ${DESTDIR}/etc -p ${DESTDIR}/etc/master.passwd" 130577335Sdougb else 130677335Sdougb echo " '/usr/sbin/pwd_mkdb -p /etc/master.passwd'" 130777335Sdougb echo " to rebuild your password files" 130877335Sdougb run_it_now '/usr/sbin/pwd_mkdb -p /etc/master.passwd' 130977335Sdougb fi 131052400Sbillf ;; 131152400Sbillfesac 131252400Sbillf 131352400Sbillfecho '' 131452400Sbillf 131567949Sdougbif [ -r "${MM_EXIT_SCRIPT}" ]; then 131667949Sdougb . "${MM_EXIT_SCRIPT}" 131767949Sdougbfi 131867949Sdougb 131991193Sdougbcase "${COMP_CONFS}" in 132091193Sdougb'') ;; 132191193Sdougb*) 132291193Sdougb . ${DESTDIR}/etc/defaults/rc.conf 132391193Sdougb 132491193Sdougb (echo '' 132591193Sdougb echo "*** Comparing conf files: ${rc_conf_files}" 132691193Sdougb 132791193Sdougb for CONF_FILE in ${rc_conf_files}; do 132891193Sdougb if [ -r "${DESTDIR}${CONF_FILE}" ]; then 132991193Sdougb echo '' 133091193Sdougb echo "*** From ${DESTDIR}${CONF_FILE}" 133191193Sdougb echo "*** From ${DESTDIR}/etc/defaults/rc.conf" 133291193Sdougb 133391193Sdougb for RC_CONF_VAR in `grep -i ^[a-z] ${DESTDIR}${CONF_FILE} | 133491193Sdougb cut -d '=' -f 1`; do 133591193Sdougb echo '' 133691223Sdougb grep -w ^${RC_CONF_VAR} ${DESTDIR}${CONF_FILE} 133791223Sdougb grep -w ^${RC_CONF_VAR} ${DESTDIR}/etc/defaults/rc.conf || 133891193Sdougb echo ' * No default variable with this name' 133991193Sdougb done 134091193Sdougb fi 134191193Sdougb done) | ${PAGER} 134291193Sdougb echo '' 134391193Sdougb ;; 134491193Sdougbesac 134591193Sdougb 134691193Sdougbcase "${PRE_WORLD}" in 134791193Sdougb'') ;; 134891193Sdougb*) 1349186678Sdougb MAKE_CONF="${SOURCEDIR}/share/examples/etc/make.conf" 135091193Sdougb 135191193Sdougb (echo '' 135291193Sdougb echo '*** Comparing make variables' 135391193Sdougb echo '' 135491193Sdougb echo "*** From ${DESTDIR}/etc/make.conf" 135591193Sdougb echo "*** From ${MAKE_CONF}" 135691193Sdougb 1357101348Sdougb for MAKE_VAR in `grep -i ^[a-z] ${DESTDIR}/etc/make.conf | cut -d '=' -f 1`; do 135891193Sdougb echo '' 135991223Sdougb grep -w ^${MAKE_VAR} ${DESTDIR}/etc/make.conf 136091223Sdougb grep -w ^#${MAKE_VAR} ${MAKE_CONF} || 136191193Sdougb echo ' * No example variable with this name' 136291193Sdougb done) | ${PAGER} 136391193Sdougb ;; 136491193Sdougbesac 136591193Sdougb 1366200425Sdougbif [ -n "${PRESERVE_FILES}" ]; then 1367200425Sdougb find -d $PRESERVE_FILES_DIR -type d -empty -delete 2>/dev/null 1368200425Sdougb rmdir $PRESERVE_FILES_DIR 2>/dev/null 1369200425Sdougbfi 1370200425Sdougb 137152400Sbillfexit 0 1372