mergemaster.sh revision 205145
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 8201765Sdougb# Copyright 1998-2010 Douglas Barton 973651Sdougb# DougB@FreeBSD.org 1052400Sbillf 1152495Sbillf# $FreeBSD: head/usr.sbin/mergemaster/mergemaster.sh 205145 2010-03-14 05:22:46Z 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" 33189763Sdougb echo '' 3452400Sbillf echo " -m /path/directory Specify location of source to do the make in" 3552400Sbillf echo " -t /path/directory Specify temp root directory" 3652400Sbillf echo " -d Add date and time to directory name (e.g., /var/tmp/temproot.`date +%m%d.%H.%M`)" 3752400Sbillf echo " -u N Specify a numeric umask" 3852400Sbillf echo " -w N Specify a screen width in columns to sdiff" 39155309Srwatson echo " -A architecture Alternative architecture name to pass to make" 4067949Sdougb echo ' -D /path/directory Specify the destination directory to install files to' 4152400Sbillf echo '' 4252400Sbillf} 4352400Sbillf 4452400Sbillfdisplay_help () { 4552400Sbillf echo "* To specify a directory other than /var/tmp/temproot for the" 4652400Sbillf echo " temporary root environment, use -t /path/to/temp/root" 4752400Sbillf echo "* The -w option takes a number as an argument for the column width" 4867859Sdougb echo " of the screen. The default is 80." 4967949Sdougb echo '* The -a option causes mergemaster to run without prompting.' 5052400Sbillf} 5152400Sbillf 5258910Salfred# Loop allowing the user to use sdiff to merge files and display the merged 5358910Salfred# file. 5458910Salfredmerge_loop () { 5567850Sdougb case "${VERBOSE}" in 5667850Sdougb '') ;; 5767850Sdougb *) 5867850Sdougb echo " *** Type h at the sdiff prompt (%) to get usage help" 5967850Sdougb ;; 6067850Sdougb esac 6167850Sdougb echo '' 6267850Sdougb MERGE_AGAIN=yes 6367850Sdougb while [ "${MERGE_AGAIN}" = "yes" ]; do 6467850Sdougb # Prime file.merged so we don't blat the owner/group id's 6567850Sdougb cp -p "${COMPFILE}" "${COMPFILE}.merged" 6667850Sdougb sdiff -o "${COMPFILE}.merged" --text --suppress-common-lines \ 6767949Sdougb --width=${SCREEN_WIDTH:-80} "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" 6867850Sdougb INSTALL_MERGED=V 6967850Sdougb while [ "${INSTALL_MERGED}" = "v" -o "${INSTALL_MERGED}" = "V" ]; do 7067850Sdougb echo '' 7167850Sdougb echo " Use 'i' to install merged file" 7267850Sdougb echo " Use 'r' to re-do the merge" 7367850Sdougb echo " Use 'v' to view the merged file" 7467850Sdougb echo " Default is to leave the temporary file to deal with by hand" 7567850Sdougb echo '' 7667859Sdougb echo -n " *** How should I deal with the merged file? [Leave it for later] " 7767859Sdougb read INSTALL_MERGED 7858910Salfred 7967850Sdougb case "${INSTALL_MERGED}" in 8067850Sdougb [iI]) 8167850Sdougb mv "${COMPFILE}.merged" "${COMPFILE}" 8267850Sdougb echo '' 8367850Sdougb if mm_install "${COMPFILE}"; then 8467850Sdougb echo " *** Merged version of ${COMPFILE} installed successfully" 8567859Sdougb else 8667850Sdougb echo " *** Problem installing ${COMPFILE}, it will remain to merge by hand later" 8767859Sdougb fi 8867850Sdougb unset MERGE_AGAIN 8967850Sdougb ;; 9067850Sdougb [rR]) 9167850Sdougb rm "${COMPFILE}.merged" 9267859Sdougb ;; 9367850Sdougb [vV]) 9467850Sdougb ${PAGER} "${COMPFILE}.merged" 9567850Sdougb ;; 9667850Sdougb '') 9767850Sdougb echo " *** ${COMPFILE} will remain for your consideration" 9867850Sdougb unset MERGE_AGAIN 9967850Sdougb ;; 10067850Sdougb *) 10167850Sdougb echo "invalid choice: ${INSTALL_MERGED}" 10267850Sdougb INSTALL_MERGED=V 10367850Sdougb ;; 10467850Sdougb esac 10567850Sdougb done 10667850Sdougb done 10758910Salfred} 10858910Salfred 10958910Salfred# Loop showing user differences between files, allow merge, skip or install 11058910Salfred# options 11158910Salfreddiff_loop () { 11258910Salfred 11367850Sdougb HANDLE_COMPFILE=v 11458910Salfred 11577323Sdougb while [ "${HANDLE_COMPFILE}" = "v" -o "${HANDLE_COMPFILE}" = "V" -o \ 11677323Sdougb "${HANDLE_COMPFILE}" = "NOT V" ]; do 11767949Sdougb if [ -f "${DESTDIR}${COMPFILE#.}" -a -f "${COMPFILE}" ]; then 118192230Sdougb if [ -n "${AUTO_UPGRADE}" -a -n "${CHANGED}" ]; then 119192230Sdougb case "${CHANGED}" in 120192230Sdougb *:${DESTDIR}${COMPFILE#.}:*) ;; # File has been modified 121192230Sdougb *) 122158149Sgordon echo '' 123158149Sgordon echo " *** ${COMPFILE} has not been user modified." 124158149Sgordon echo '' 125158149Sgordon 126158149Sgordon if mm_install "${COMPFILE}"; then 127158149Sgordon echo " *** ${COMPFILE} upgraded successfully" 128158149Sgordon echo '' 129158149Sgordon # Make the list print one file per line 130158149Sgordon AUTO_UPGRADED_FILES="${AUTO_UPGRADED_FILES} ${DESTDIR}${COMPFILE#.} 131158149Sgordon" 132158149Sgordon else 133192230Sdougb echo " *** Problem upgrading ${COMPFILE}, it will remain to merge by hand" 134158149Sgordon fi 135158149Sgordon return 136192230Sdougb ;; 137192230Sdougb esac 138158149Sgordon fi 13967850Sdougb if [ "${HANDLE_COMPFILE}" = "v" -o "${HANDLE_COMPFILE}" = "V" ]; then 14090564Sdougb echo '' 141109993Sdillon echo ' ====================================================================== ' 142109993Sdillon echo '' 143109993Sdillon ( 144109993Sdillon echo " *** Displaying differences between ${COMPFILE} and installed version:" 145109993Sdillon echo '' 146110377Sdougb diff ${DIFF_FLAG} ${DIFF_OPTIONS} "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" 147109993Sdillon ) | ${PAGER} 148109993Sdillon echo '' 14967850Sdougb fi 15067850Sdougb else 151109993Sdillon echo '' 15267850Sdougb echo " *** There is no installed version of ${COMPFILE}" 15391193Sdougb echo '' 15467949Sdougb case "${AUTO_INSTALL}" in 15567949Sdougb [Yy][Ee][Ss]) 15667949Sdougb echo '' 15767949Sdougb if mm_install "${COMPFILE}"; then 15867949Sdougb echo " *** ${COMPFILE} installed successfully" 15968507Sdougb echo '' 16067949Sdougb # Make the list print one file per line 16167949Sdougb AUTO_INSTALLED_FILES="${AUTO_INSTALLED_FILES} ${DESTDIR}${COMPFILE#.} 16267949Sdougb" 16367949Sdougb else 16467949Sdougb echo " *** Problem installing ${COMPFILE}, it will remain to merge by hand" 16567949Sdougb fi 16667949Sdougb return 16767949Sdougb ;; 16867949Sdougb *) 16967949Sdougb NO_INSTALLED=yes 17067949Sdougb ;; 17167949Sdougb esac 17267850Sdougb fi 17367859Sdougb 17467850Sdougb echo " Use 'd' to delete the temporary ${COMPFILE}" 17567850Sdougb echo " Use 'i' to install the temporary ${COMPFILE}" 17667850Sdougb case "${NO_INSTALLED}" in 17767850Sdougb '') 17877326Sdougb echo " Use 'm' to merge the temporary and installed versions" 179109993Sdillon echo " Use 'v' to view the diff results again" 18067850Sdougb ;; 18167850Sdougb esac 18267850Sdougb echo '' 18367850Sdougb echo " Default is to leave the temporary file to deal with by hand" 18467850Sdougb echo '' 18567859Sdougb echo -n "How should I deal with this? [Leave it for later] " 18667859Sdougb read HANDLE_COMPFILE 18767859Sdougb 18867850Sdougb case "${HANDLE_COMPFILE}" in 18967850Sdougb [dD]) 19067850Sdougb rm "${COMPFILE}" 19167850Sdougb echo '' 19267850Sdougb echo " *** Deleting ${COMPFILE}" 19367850Sdougb ;; 19467850Sdougb [iI]) 19567850Sdougb echo '' 19667850Sdougb if mm_install "${COMPFILE}"; then 19767850Sdougb echo " *** ${COMPFILE} installed successfully" 19867850Sdougb else 19967850Sdougb echo " *** Problem installing ${COMPFILE}, it will remain to merge by hand" 20067850Sdougb fi 20167850Sdougb ;; 20267850Sdougb [mM]) 20367850Sdougb case "${NO_INSTALLED}" in 20467850Sdougb '') 20567850Sdougb # interact with user to merge files 20667850Sdougb merge_loop 20767850Sdougb ;; 20867850Sdougb *) 20967850Sdougb echo '' 21067850Sdougb echo " *** There is no installed version of ${COMPFILE}" 21167850Sdougb echo '' 21267850Sdougb HANDLE_COMPFILE="NOT V" 21367850Sdougb ;; 21467850Sdougb esac # End of "No installed version of file but user selected merge" test 21567850Sdougb ;; 21667850Sdougb [vV]) 21767850Sdougb continue 21867850Sdougb ;; 21967850Sdougb '') 22067850Sdougb echo '' 22167850Sdougb echo " *** ${COMPFILE} will remain for your consideration" 22267850Sdougb ;; 22367850Sdougb *) 22467850Sdougb # invalid choice, show menu again. 22567850Sdougb echo "invalid choice: ${HANDLE_COMPFILE}" 22667850Sdougb echo '' 22767850Sdougb HANDLE_COMPFILE="NOT V" 22867850Sdougb continue 22967850Sdougb ;; 23067850Sdougb esac # End of "How to handle files that are different" 23167859Sdougb done 23267850Sdougb unset NO_INSTALLED 23367850Sdougb echo '' 23467850Sdougb case "${VERBOSE}" in 23567850Sdougb '') ;; 23667850Sdougb *) 23767850Sdougb sleep 3 23867850Sdougb ;; 23967850Sdougb esac 24058910Salfred} 24158910Salfred 24297960Sdougbpress_to_continue () { 24397960Sdougb local DISCARD 24497960Sdougb echo -n ' *** Press the [Enter] or [Return] key to continue ' 24597960Sdougb read DISCARD 24697960Sdougb} 24797960Sdougb 24852400Sbillf# Set the default path for the temporary root environment 24952400Sbillf# 25052400SbillfTEMPROOT='/var/tmp/temproot' 25152400Sbillf 25273651Sdougb# Read /etc/mergemaster.rc first so the one in $HOME can override 25373651Sdougb# 25473651Sdougbif [ -r /etc/mergemaster.rc ]; then 25573651Sdougb . /etc/mergemaster.rc 25673651Sdougbfi 25773651Sdougb 25852400Sbillf# Read .mergemasterrc before command line so CLI can override 25952400Sbillf# 26067949Sdougbif [ -r "$HOME/.mergemasterrc" ]; then 26152400Sbillf . "$HOME/.mergemasterrc" 26252400Sbillffi 26352400Sbillf 26452400Sbillf# Check the command line options 26552400Sbillf# 266189992Sdougbwhile getopts ":ascrvhipCPm:t:du:w:D:A:FU" COMMAND_LINE_ARGUMENT ; do 26752400Sbillf case "${COMMAND_LINE_ARGUMENT}" in 268155309Srwatson A) 269186678Sdougb ARCHSTRING='TARGET_ARCH='${OPTARG} 270155309Srwatson ;; 271189992Sdougb F) 272189992Sdougb FREEBSD_ID=yes 273189992Sdougb ;; 274158149Sgordon U) 275158149Sgordon AUTO_UPGRADE=yes 276158149Sgordon ;; 27752400Sbillf s) 27852400Sbillf STRICT=yes 279110377Sdougb unset DIFF_OPTIONS 28052400Sbillf ;; 28152400Sbillf c) 28252400Sbillf DIFF_FLAG='-c' 28352400Sbillf ;; 28452400Sbillf r) 28552400Sbillf RERUN=yes 28652400Sbillf ;; 28752400Sbillf v) 28852400Sbillf case "${AUTO_RUN}" in 28952400Sbillf '') VERBOSE=yes ;; 29052400Sbillf esac 29152400Sbillf ;; 29252400Sbillf a) 29352400Sbillf AUTO_RUN=yes 29452400Sbillf unset VERBOSE 29552400Sbillf ;; 29652400Sbillf h) 29752400Sbillf display_usage 29852400Sbillf display_help 29952400Sbillf exit 0 30052400Sbillf ;; 30167949Sdougb i) 30267949Sdougb AUTO_INSTALL=yes 30367949Sdougb ;; 30496045Sdougb C) 30596045Sdougb COMP_CONFS=yes 30696045Sdougb ;; 307114501Sdougb P) 308114501Sdougb PRESERVE_FILES=yes 309114501Sdougb ;; 31091193Sdougb p) 31191193Sdougb PRE_WORLD=yes 31296045Sdougb unset COMP_CONFS 31396045Sdougb unset AUTO_RUN 31491193Sdougb ;; 31552400Sbillf m) 31652400Sbillf SOURCEDIR=${OPTARG} 31752400Sbillf ;; 31852400Sbillf t) 31952400Sbillf TEMPROOT=${OPTARG} 32052400Sbillf ;; 32152400Sbillf d) 32252400Sbillf TEMPROOT=${TEMPROOT}.`date +%m%d.%H.%M` 32352400Sbillf ;; 32452400Sbillf u) 32552400Sbillf NEW_UMASK=${OPTARG} 32652400Sbillf ;; 32752400Sbillf w) 32852400Sbillf SCREEN_WIDTH=${OPTARG} 32952400Sbillf ;; 33067949Sdougb D) 33167949Sdougb DESTDIR=${OPTARG} 33267949Sdougb ;; 33352400Sbillf *) 33452400Sbillf display_usage 33552400Sbillf exit 1 33652400Sbillf ;; 33752400Sbillf esac 33852400Sbillfdone 33952400Sbillf 340205145Sdougbif [ -n "$AUTO_RUN" ]; then 341205145Sdougb if [ -n "$FREEBSD_ID" -o -n "$AUTO_UPGRADE" -o -n "$AUTO_INSTALL" ]; then 342205145Sdougb echo '' 343205145Sdougb echo "*** You have included the -a option along with one or more options" 344205145Sdougb echo ' that indicate that you wish mergemaster to actually make updates' 345205145Sdougb echo ' (-F, -U, or -i), however these options are not compatible.' 346205145Sdougb echo ' Please read mergemaster(8) for more information.' 347205145Sdougb echo '' 348205145Sdougb exit 1 349205145Sdougb fi 350205145Sdougbfi 351205145Sdougb 352202817Sdougb# Assign the location of the mtree database 353202817Sdougb# 354202817SdougbMTREEDB=${MTREEDB:-${DESTDIR}/var/db} 355202817SdougbMTREEFILE="${MTREEDB}/mergemaster.mtree" 356202817Sdougb 357114501Sdougb# Don't force the user to set this in the mergemaster rc file 358114501Sdougbif [ -n "${PRESERVE_FILES}" -a -z "${PRESERVE_FILES_DIR}" ]; then 359114501Sdougb PRESERVE_FILES_DIR=/var/tmp/mergemaster/preserved-files-`date +%y%m%d-%H%M%S` 360200425Sdougb mkdir -p ${PRESERVE_FILES_DIR} 361114501Sdougbfi 362114501Sdougb 363186678Sdougb# Check for the mtree database in DESTDIR 364186678Sdougbcase "${AUTO_UPGRADE}" in 365186678Sdougb'') ;; # If the option is not set no need to run the test or warn the user 366186678Sdougb*) 367200416Sdougb if [ ! -s "${MTREEFILE}" ]; then 368186678Sdougb echo '' 369200416Sdougb echo "*** Unable to find mtree database (${MTREEFILE})." 370200416Sdougb echo " Skipping auto-upgrade on this run." 371193853Sdougb echo " It will be created for the next run when this one is complete." 372186678Sdougb echo '' 373201291Sdougb case "${AUTO_RUN}" in 374201291Sdougb '') 375201291Sdougb press_to_continue 376201291Sdougb ;; 377201291Sdougb esac 378186678Sdougb unset AUTO_UPGRADE 379186678Sdougb fi 380186678Sdougb ;; 381186678Sdougbesac 382186678Sdougb 383186689Sdougbif [ -e "${DESTDIR}/etc/fstab" ]; then 384186689Sdougb if grep -q nodev ${DESTDIR}/etc/fstab; then 385186689Sdougb echo '' 386186689Sdougb echo "*** You have the deprecated 'nodev' option in ${DESTDIR}/etc/fstab." 387186689Sdougb echo " This can prevent the filesystem from being mounted on reboot." 388186689Sdougb echo " Please update your fstab before continuing." 389186689Sdougb echo " See fstab(5) for more information." 390186689Sdougb echo '' 391186689Sdougb exit 1 392186689Sdougb fi 393158149Sgordonfi 394158149Sgordon 39552400Sbillfecho '' 39652400Sbillf 39752400Sbillf# If the user has a pager defined, make sure we can run it 39852400Sbillf# 39952400Sbillfcase "${DONT_CHECK_PAGER}" in 40052400Sbillf'') 401186695Sdougbcheck_pager () { 402186695Sdougb while ! type "${PAGER%% *}" >/dev/null; do 40352400Sbillf echo " *** Your PAGER environment variable specifies '${PAGER}', but" 40464467Sbrian echo " due to the limited PATH that I use for security reasons," 40567859Sdougb echo " I cannot execute it. So, what would you like to do?" 40652400Sbillf echo '' 40752400Sbillf echo " Use 'e' to exit mergemaster and fix your PAGER variable" 40864467Sbrian if [ -x /usr/bin/less -o -x /usr/local/bin/less ]; then 40964467Sbrian echo " Use 'l' to set PAGER to 'less' for this run" 41052400Sbillf fi 41152400Sbillf echo " Use 'm' to use plain old 'more' as your PAGER for this run" 41252400Sbillf echo '' 41352400Sbillf echo " Default is to use plain old 'more' " 41452400Sbillf echo '' 41567859Sdougb echo -n "What should I do? [Use 'more'] " 41667859Sdougb read FIXPAGER 41767859Sdougb 41852400Sbillf case "${FIXPAGER}" in 41958910Salfred [eE]) 42052400Sbillf exit 0 42152400Sbillf ;; 42258910Salfred [lL]) 42364467Sbrian if [ -x /usr/bin/less ]; then 42464467Sbrian PAGER=/usr/bin/less 42564467Sbrian elif [ -x /usr/local/bin/less ]; then 42658910Salfred PAGER=/usr/local/bin/less 42764467Sbrian else 42864467Sbrian echo '' 42964467Sbrian echo " *** Fatal Error:" 43064467Sbrian echo " You asked to use 'less' as your pager, but I can't" 43164467Sbrian echo " find it in /usr/bin or /usr/local/bin" 43264467Sbrian exit 1 43358910Salfred fi 43452400Sbillf ;; 43560420Sbsd [mM]|'') 43652400Sbillf PAGER=more 43752400Sbillf ;; 43858910Salfred *) 43958910Salfred echo '' 44058910Salfred echo "invalid choice: ${FIXPAGER}" 44152400Sbillf esac 44252400Sbillf echo '' 44358910Salfred done 444186695Sdougb} 445186695Sdougb if [ -n "${PAGER}" ]; then 446186695Sdougb check_pager 447186695Sdougb fi 44852400Sbillf ;; 44952400Sbillfesac 45052400Sbillf 45152400Sbillf# If user has a pager defined, or got assigned one above, use it. 45252400Sbillf# If not, use more. 45352400Sbillf# 45452400SbillfPAGER=${PAGER:-more} 45552400Sbillf 45652400Sbillfif [ -n "${VERBOSE}" -a ! "${PAGER}" = "more" ]; then 45752400Sbillf echo " *** You have ${PAGER} defined as your pager so we will use that" 45852400Sbillf echo '' 45952400Sbillf sleep 3 46052400Sbillffi 46152400Sbillf 46252400Sbillf# Assign the diff flag once so we will not have to keep testing it 46352400Sbillf# 46452400SbillfDIFF_FLAG=${DIFF_FLAG:--u} 46552400Sbillf 46652400Sbillf# Assign the source directory 46752400Sbillf# 468186678SdougbSOURCEDIR=${SOURCEDIR:-/usr/src} 469186678Sdougbif [ ! -f ${SOURCEDIR}/Makefile.inc1 -a \ 470186678Sdougb -f ${SOURCEDIR}/../Makefile.inc1 ]; then 471186678Sdougb echo " *** The source directory you specified (${SOURCEDIR})" 472186678Sdougb echo " will be reset to ${SOURCEDIR}/.." 473186678Sdougb echo '' 474186678Sdougb sleep 3 475186678Sdougb SOURCEDIR=${SOURCEDIR}/.. 476186678Sdougbfi 47752400Sbillf 478186678Sdougb# Setup make to use system files from SOURCEDIR 479186695SdougbMM_MAKE="make ${ARCHSTRING} -m ${SOURCEDIR}/share/mk" 480186678Sdougb 481158149Sgordon# Check DESTDIR against the mergemaster mtree database to see what 482158149Sgordon# files the user changed from the reference files. 483158149Sgordon# 484200416Sdougbif [ -n "${AUTO_UPGRADE}" -a -s "${MTREEFILE}" ]; then 485192230Sdougb CHANGED=: 486200416Sdougb for file in `mtree -eqL -f ${MTREEFILE} -p ${DESTDIR}/ \ 487158149Sgordon 2>/dev/null | awk '($2 == "changed") {print $1}'`; do 488158149Sgordon if [ -f "${DESTDIR}/$file" ]; then 489192230Sdougb CHANGED="${CHANGED}${DESTDIR}/${file}:" 490158149Sgordon fi 491158149Sgordon done 492192230Sdougb [ "$CHANGED" = ':' ] && unset CHANGED 493158149Sgordonfi 494158149Sgordon 49596045Sdougb# Check the width of the user's terminal 49696045Sdougb# 49796045Sdougbif [ -t 0 ]; then 498110377Sdougb w=`tput columns` 49996045Sdougb case "${w}" in 50096045Sdougb 0|'') ;; # No-op, since the input is not valid 50196045Sdougb *) 50296045Sdougb case "${SCREEN_WIDTH}" in 50396045Sdougb '') SCREEN_WIDTH="${w}" ;; 50496045Sdougb "${w}") ;; # No-op, since they are the same 50596045Sdougb *) 50696045Sdougb echo -n "*** You entered ${SCREEN_WIDTH} as your screen width, but stty " 50796045Sdougb echo "thinks it is ${w}." 50896045Sdougb echo '' 50996045Sdougb echo -n "What would you like to use? [${w}] " 51096045Sdougb read SCREEN_WIDTH 51197380Sdougb case "${SCREEN_WIDTH}" in 51297380Sdougb '') SCREEN_WIDTH="${w}" ;; 51397380Sdougb esac 51496045Sdougb ;; 51596045Sdougb esac 51696045Sdougb esac 51796045Sdougbfi 51896045Sdougb 51973651Sdougb# Define what CVS $Id tag to look for to aid portability. 52073651Sdougb# 52173651SdougbCVS_ID_TAG=FreeBSD 52273651Sdougb 52399152Sdougbdelete_temproot () { 524101362Sdougb rm -rf "${TEMPROOT}" 2>/dev/null 525101362Sdougb chflags -R 0 "${TEMPROOT}" 2>/dev/null 526201765Sdougb rm -rf "${TEMPROOT}" || { echo "*** Unable to delete ${TEMPROOT}"; exit 1; } 52799152Sdougb} 52899152Sdougb 52952400Sbillfcase "${RERUN}" in 53052400Sbillf'') 53152400Sbillf # Set up the loop to test for the existence of the 53252400Sbillf # temp root directory. 53352400Sbillf # 53452400Sbillf TEST_TEMP_ROOT=yes 53552400Sbillf while [ "${TEST_TEMP_ROOT}" = "yes" ]; do 53652400Sbillf if [ -d "${TEMPROOT}" ]; then 53752400Sbillf echo "*** The directory specified for the temporary root environment," 53867859Sdougb echo " ${TEMPROOT}, exists. This can be a security risk if untrusted" 53952400Sbillf echo " users have access to the system." 54052400Sbillf echo '' 54152400Sbillf case "${AUTO_RUN}" in 54252400Sbillf '') 54352400Sbillf echo " Use 'd' to delete the old ${TEMPROOT} and continue" 54452400Sbillf echo " Use 't' to select a new temporary root directory" 54552400Sbillf echo " Use 'e' to exit mergemaster" 54652400Sbillf echo '' 54752400Sbillf echo " Default is to use ${TEMPROOT} as is" 54852400Sbillf echo '' 54967859Sdougb echo -n "How should I deal with this? [Use the existing ${TEMPROOT}] " 55067859Sdougb read DELORNOT 55167859Sdougb 55267859Sdougb case "${DELORNOT}" in 55367859Sdougb [dD]) 55467859Sdougb echo '' 55567859Sdougb echo " *** Deleting the old ${TEMPROOT}" 55667859Sdougb echo '' 557201765Sdougb delete_temproot 55867859Sdougb unset TEST_TEMP_ROOT 55952400Sbillf ;; 56067859Sdougb [tT]) 56167859Sdougb echo " *** Enter new directory name for temporary root environment" 56267859Sdougb read TEMPROOT 56367859Sdougb ;; 56467859Sdougb [eE]) 56567859Sdougb exit 0 56667859Sdougb ;; 56767859Sdougb '') 56867859Sdougb echo '' 56967859Sdougb echo " *** Leaving ${TEMPROOT} intact" 57067859Sdougb echo '' 57167859Sdougb unset TEST_TEMP_ROOT 57267859Sdougb ;; 57367859Sdougb *) 57467859Sdougb echo '' 57567859Sdougb echo "invalid choice: ${DELORNOT}" 57667859Sdougb echo '' 57767859Sdougb ;; 57867859Sdougb esac 57967859Sdougb ;; 58052400Sbillf *) 58177323Sdougb # If this is an auto-run, try a hopefully safe alternative then 58277323Sdougb # re-test anyway. 58352400Sbillf TEMPROOT=/var/tmp/temproot.`date +%m%d.%H.%M.%S` 58452400Sbillf ;; 58552400Sbillf esac 58652400Sbillf else 58752400Sbillf unset TEST_TEMP_ROOT 58852400Sbillf fi 58952400Sbillf done 59052400Sbillf 59152400Sbillf echo "*** Creating the temporary root environment in ${TEMPROOT}" 59252400Sbillf 59352400Sbillf if mkdir -p "${TEMPROOT}"; then 59452400Sbillf echo " *** ${TEMPROOT} ready for use" 59552400Sbillf fi 59652400Sbillf 59752400Sbillf if [ ! -d "${TEMPROOT}" ]; then 59852400Sbillf echo '' 59952400Sbillf echo " *** FATAL ERROR: Cannot create ${TEMPROOT}" 60052400Sbillf echo '' 60152400Sbillf exit 1 60252400Sbillf fi 60352400Sbillf 60452400Sbillf echo " *** Creating and populating directory structure in ${TEMPROOT}" 60552400Sbillf echo '' 60652400Sbillf 60752400Sbillf case "${VERBOSE}" in 60852400Sbillf '') ;; 60952400Sbillf *) 61097960Sdougb press_to_continue 61152400Sbillf ;; 61252400Sbillf esac 61352400Sbillf 61491193Sdougb case "${PRE_WORLD}" in 61591193Sdougb '') 61691193Sdougb { cd ${SOURCEDIR} && 61791193Sdougb case "${DESTDIR}" in 61891193Sdougb '') ;; 61991193Sdougb *) 620186695Sdougb ${MM_MAKE} DESTDIR=${DESTDIR} distrib-dirs 62191193Sdougb ;; 62291193Sdougb esac 623186749Sdougb od=${TEMPROOT}/usr/obj 624186695Sdougb ${MM_MAKE} DESTDIR=${TEMPROOT} distrib-dirs && 625186749Sdougb MAKEOBJDIRPREFIX=$od ${MM_MAKE} _obj SUBDIR_OVERRIDE=etc && 626186749Sdougb MAKEOBJDIRPREFIX=$od ${MM_MAKE} everything SUBDIR_OVERRIDE=etc && 627186749Sdougb MAKEOBJDIRPREFIX=$od ${MM_MAKE} DESTDIR=${TEMPROOT} distribution;} || 62891193Sdougb { echo ''; 62991193Sdougb echo " *** FATAL ERROR: Cannot 'cd' to ${SOURCEDIR} and install files to"; 63091193Sdougb echo " the temproot environment"; 63191193Sdougb echo ''; 63291193Sdougb exit 1;} 63391193Sdougb ;; 63491193Sdougb *) 63591193Sdougb # Only set up files that are crucial to {build|install}world 63691193Sdougb { mkdir -p ${TEMPROOT}/etc && 637186678Sdougb cp -p ${SOURCEDIR}/etc/master.passwd ${TEMPROOT}/etc && 638186678Sdougb cp -p ${SOURCEDIR}/etc/group ${TEMPROOT}/etc;} || 63991193Sdougb { echo ''; 64091193Sdougb echo ' *** FATAL ERROR: Cannot copy files to the temproot environment'; 64191193Sdougb echo ''; 64291193Sdougb exit 1;} 64391193Sdougb ;; 64491193Sdougb esac 64552400Sbillf 64677323Sdougb # Doing the inventory and removing files that we don't want to compare only 64777323Sdougb # makes sense if we are not doing a rerun, since we have no way of knowing 64877323Sdougb # what happened to the files during previous incarnations. 64967949Sdougb case "${VERBOSE}" in 65067949Sdougb '') ;; 65167949Sdougb *) 65267949Sdougb echo '' 65367949Sdougb echo ' *** The following files exist only in the installed version of' 65467949Sdougb echo " ${DESTDIR}/etc. In the vast majority of cases these files" 65567949Sdougb echo ' are necessary parts of the system and should not be deleted.' 65667949Sdougb echo ' However because these files are not updated by this process you' 65767949Sdougb echo ' might want to verify their status before rebooting your system.' 65867949Sdougb echo '' 65997960Sdougb press_to_continue 660101348Sdougb diff -qr ${DESTDIR}/etc ${TEMPROOT}/etc | grep "^Only in ${DESTDIR}/etc" | ${PAGER} 66167949Sdougb echo '' 66297960Sdougb press_to_continue 66367949Sdougb ;; 66467949Sdougb esac 66567949Sdougb 66652534Sbillf case "${IGNORE_MOTD}" in 667202340Sdougb '') ;; 668202339Sdougb *) 669186678Sdougb echo '' 670186678Sdougb echo "*** You have the IGNORE_MOTD option set in your mergemaster rc file." 671186678Sdougb echo " This option is deprecated in favor of the IGNORE_FILES option." 672186678Sdougb echo " Please update your rc file accordingly." 673186678Sdougb echo '' 674202339Sdougb exit 1 67552534Sbillf ;; 67652534Sbillf esac 67752534Sbillf 678186678Sdougb # Avoid comparing the following user specified files 679186678Sdougb for file in ${IGNORE_FILES}; do 680186688Sdougb test -e ${TEMPROOT}/${file} && unlink ${TEMPROOT}/${file} 681186678Sdougb done 68252400Sbillf 683201291Sdougb # We really don't want to have to deal with files like login.conf.db, pwd.db, 684201291Sdougb # or spwd.db. Instead, we want to compare the text versions, and run *_mkdb. 685201291Sdougb # Prompt the user to do so below, as needed. 686201291Sdougb # 687201291Sdougb rm -f ${TEMPROOT}/etc/*.db ${TEMPROOT}/etc/passwd 68877478Sdougb 689201291Sdougb # We only need to compare things like freebsd.cf once 690201291Sdougb find ${TEMPROOT}/usr/obj -type f -delete 2>/dev/null 69194196Sdougb 692201291Sdougb # Delete stuff we do not need to keep the mtree database small, 693201291Sdougb # and to make the actual comparison faster. 694201291Sdougb find ${TEMPROOT}/usr -type l -delete 2>/dev/null 695201291Sdougb find ${TEMPROOT} -type f -size 0 -delete 2>/dev/null 696201291Sdougb find -d ${TEMPROOT} -type d -empty -delete 2>/dev/null 697158149Sgordon 698201291Sdougb # Build the mtree database in a temporary location. 699201291Sdougb case "${PRE_WORLD}" in 700201323Sdougb '') MTREENEW=`mktemp -t mergemaster.mtree` 701201323Sdougb mtree -ci -p ${TEMPROOT} -k size,md5digest > ${MTREENEW} 2>/dev/null 702201291Sdougb ;; 703201291Sdougb *) # We don't want to mess with the mtree database on a pre-world run or 704201291Sdougb # when re-scanning a previously-built tree. 705201291Sdougb ;; 706201291Sdougb esac 707201291Sdougb ;; # End of the "RERUN" test 708158149Sgordonesac 709158149Sgordon 71052400Sbillf# Get ready to start comparing files 71152400Sbillf 71298084Sdougb# Check umask if not specified on the command line, 71398084Sdougb# and we are not doing an autorun 71452400Sbillf# 71598084Sdougbif [ -z "${NEW_UMASK}" -a -z "${AUTO_RUN}" ]; then 71698084Sdougb USER_UMASK=`umask` 71752400Sbillf case "${USER_UMASK}" in 71877335Sdougb 0022|022) ;; 71952400Sbillf *) 72052400Sbillf echo '' 72198084Sdougb echo " *** Your umask is currently set to ${USER_UMASK}. By default, this script" 72298084Sdougb echo " installs all files with the same user, group and modes that" 723186678Sdougb echo " they are created with by ${SOURCEDIR}/etc/Makefile, compared to" 72498084Sdougb echo " a umask of 022. This umask allows world read permission when" 72598084Sdougb echo " the file's default permissions have it." 72652400Sbillf echo '' 72798084Sdougb echo " No world permissions can sometimes cause problems. A umask of" 72898084Sdougb echo " 022 will restore the default behavior, but is not mandatory." 72998084Sdougb echo " /etc/master.passwd is a special case. Its file permissions" 73098084Sdougb echo " will be 600 (rw-------) if installed." 73197960Sdougb echo '' 73298084Sdougb echo -n "What umask should I use? [${USER_UMASK}] " 73398084Sdougb read NEW_UMASK 73498084Sdougb 73598084Sdougb NEW_UMASK="${NEW_UMASK:-$USER_UMASK}" 73652400Sbillf ;; 73752400Sbillf esac 73852400Sbillf echo '' 73998084Sdougbfi 74052400Sbillf 74198084SdougbCONFIRMED_UMASK=${NEW_UMASK:-0022} 74298084Sdougb 74352400Sbillf# 744114501Sdougb# Warn users who still have old rc files 745114501Sdougb# 746179315Sbzfor file in atm devfs diskless1 diskless2 network network6 pccard \ 747114523Sdougb serial syscons sysctl alpha amd64 i386 ia64 sparc64; do 748114501Sdougb if [ -f "${DESTDIR}/etc/rc.${file}" ]; then 749114501Sdougb OLD_RC_PRESENT=1 750114501Sdougb break 751114501Sdougb fi 752114501Sdougbdone 753114501Sdougb 754114501Sdougbcase "${OLD_RC_PRESENT}" in 755114501Sdougb1) 75652400Sbillf echo '' 757114501Sdougb echo " *** There are elements of the old rc system in ${DESTDIR}/etc/." 75867949Sdougb echo '' 759114501Sdougb echo ' While these scripts will not hurt anything, they are not' 760114501Sdougb echo ' functional on an up to date system, and can be removed.' 76167949Sdougb echo '' 762114501Sdougb 76352400Sbillf case "${AUTO_RUN}" in 76452400Sbillf '') 765114501Sdougb echo -n 'Move these files to /var/tmp/mergemaster/old_rc? [yes] ' 766114501Sdougb read MOVE_OLD_RC 76767859Sdougb 768114501Sdougb case "${MOVE_OLD_RC}" in 769114501Sdougb [nN]*) ;; 77052400Sbillf *) 771114501Sdougb mkdir -p /var/tmp/mergemaster/old_rc 772179315Sbz for file in atm devfs diskless1 diskless2 network network6 pccard \ 773114523Sdougb serial syscons sysctl alpha amd64 i386 ia64 sparc64; do 774114501Sdougb if [ -f "${DESTDIR}/etc/rc.${file}" ]; then 775114501Sdougb mv ${DESTDIR}/etc/rc.${file} /var/tmp/mergemaster/old_rc/ 776114501Sdougb fi 777114501Sdougb done 778114501Sdougb echo ' The files have been moved' 779114501Sdougb press_to_continue 78052400Sbillf ;; 78152400Sbillf esac 78252400Sbillf ;; 78352400Sbillf *) ;; 78452400Sbillf esac 785114501Sdougbesac 78652400Sbillf 78798084Sdougb# Use the umask/mode information to install the files 78852400Sbillf# Create directories as needed 78952400Sbillf# 790186678Sdougbinstall_error () { 791186678Sdougb echo "*** FATAL ERROR: Unable to install ${1} to ${2}" 792186678Sdougb echo '' 793186678Sdougb exit 1 794186678Sdougb} 795186678Sdougb 79678490Sdougbdo_install_and_rm () { 797114501Sdougb case "${PRESERVE_FILES}" in 798114501Sdougb [Yy][Ee][Ss]) 799114501Sdougb if [ -f "${3}/${2##*/}" ]; then 800114565Sdougb mkdir -p ${PRESERVE_FILES_DIR}/${2%/*} 801114565Sdougb cp ${3}/${2##*/} ${PRESERVE_FILES_DIR}/${2%/*} 802114501Sdougb fi 803114501Sdougb ;; 804114501Sdougb esac 805114501Sdougb 806186678Sdougb if [ ! -d "${3}/${2##*/}" ]; then 807186678Sdougb if install -m ${1} ${2} ${3}; then 808186678Sdougb unlink ${2} 809186678Sdougb else 810186678Sdougb install_error ${2} ${3} 811186678Sdougb fi 812186678Sdougb else 813186678Sdougb install_error ${2} ${3} 814186678Sdougb fi 81578490Sdougb} 81678490Sdougb 81798084Sdougb# 4095 = "obase=10;ibase=8;07777" | bc 81898084Sdougbfind_mode () { 81998084Sdougb local OCTAL 82098084Sdougb OCTAL=$(( ~$(echo "obase=10; ibase=8; ${CONFIRMED_UMASK}" | bc) & 4095 & 821124053Sdougb $(echo "obase=10; ibase=8; $(stat -f "%OMp%OLp" ${1})" | bc) )) 82298084Sdougb printf "%04o\n" ${OCTAL} 82398084Sdougb} 82498084Sdougb 82552400Sbillfmm_install () { 82652400Sbillf local INSTALL_DIR 82752400Sbillf INSTALL_DIR=${1#.} 82852400Sbillf INSTALL_DIR=${INSTALL_DIR%/*} 82967949Sdougb 83052400Sbillf case "${INSTALL_DIR}" in 83152400Sbillf '') 83252400Sbillf INSTALL_DIR=/ 83352400Sbillf ;; 83452400Sbillf esac 83552400Sbillf 83667949Sdougb if [ -n "${DESTDIR}${INSTALL_DIR}" -a ! -d "${DESTDIR}${INSTALL_DIR}" ]; then 83798084Sdougb DIR_MODE=`find_mode "${TEMPROOT}/${INSTALL_DIR}"` 838200425Sdougb install -d -o root -g wheel -m "${DIR_MODE}" "${DESTDIR}${INSTALL_DIR}" || 839200425Sdougb install_error $1 ${DESTDIR}${INSTALL_DIR} 84052400Sbillf fi 84152400Sbillf 84298084Sdougb FILE_MODE=`find_mode "${1}"` 84352400Sbillf 84452400Sbillf if [ ! -x "${1}" ]; then 84552400Sbillf case "${1#.}" in 84664625Sgshapiro /etc/mail/aliases) 84752400Sbillf NEED_NEWALIASES=yes 84852400Sbillf ;; 84952400Sbillf /etc/login.conf) 85052400Sbillf NEED_CAP_MKDB=yes 85152400Sbillf ;; 85252400Sbillf /etc/master.passwd) 85378490Sdougb do_install_and_rm 600 "${1}" "${DESTDIR}${INSTALL_DIR}" 85452400Sbillf NEED_PWD_MKDB=yes 85552400Sbillf DONT_INSTALL=yes 85652400Sbillf ;; 85752400Sbillf /.cshrc | /.profile) 858200708Sdougb local st_nlink 859200708Sdougb 860200708Sdougb # install will unlink the file before it installs the new one, 861200708Sdougb # so we have to restore/create the link afterwards. 862200708Sdougb # 863200708Sdougb st_nlink=0 # In case the file does not yet exist 864200708Sdougb eval $(stat -s ${DESTDIR}${COMPFILE#.} 2>/dev/null) 865200708Sdougb 866200708Sdougb do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}" 867200708Sdougb 868200708Sdougb if [ -n "${AUTO_INSTALL}" -a $st_nlink -gt 1 ]; then 869200708Sdougb HANDLE_LINK=l 870200708Sdougb else 871200701Sdougb case "${LINK_EXPLAINED}" in 872200701Sdougb '') 873200701Sdougb echo " *** Historically BSD derived systems have had a" 874200701Sdougb echo " hard link from /.cshrc and /.profile to" 875200701Sdougb echo " their namesakes in /root. Please indicate" 876200701Sdougb echo " your preference below for bringing your" 877200701Sdougb echo " installed files up to date." 878200701Sdougb echo '' 879200701Sdougb LINK_EXPLAINED=yes 880200701Sdougb ;; 881200701Sdougb esac 882200701Sdougb 883200701Sdougb echo " Use 'd' to delete the temporary ${COMPFILE}" 884200708Sdougb echo " Use 'l' to delete the existing ${DESTDIR}/root/${COMPFILE##*/} and create the link" 88552400Sbillf echo '' 886200701Sdougb echo " Default is to leave the temporary file to deal with by hand" 887200701Sdougb echo '' 888200701Sdougb echo -n " How should I handle ${COMPFILE}? [Leave it to install later] " 889200701Sdougb read HANDLE_LINK 890200708Sdougb fi 89152400Sbillf 89252400Sbillf case "${HANDLE_LINK}" in 89352400Sbillf [dD]*) 89452400Sbillf rm "${COMPFILE}" 89552400Sbillf echo '' 89652400Sbillf echo " *** Deleting ${COMPFILE}" 89752400Sbillf ;; 89852400Sbillf [lL]*) 89952400Sbillf echo '' 900200708Sdougb unlink ${DESTDIR}/root/${COMPFILE##*/} 901200708Sdougb if ln ${DESTDIR}${COMPFILE#.} ${DESTDIR}/root/${COMPFILE##*/}; then 90267949Sdougb echo " *** Link from ${DESTDIR}${COMPFILE#.} to ${DESTDIR}/root/${COMPFILE##*/} installed successfully" 90352400Sbillf else 904200708Sdougb echo " *** Error linking ${DESTDIR}${COMPFILE#.} to ${DESTDIR}/root/${COMPFILE##*/}" 905200708Sdougb echo " *** ${COMPFILE} will remain for your consideration" 90652400Sbillf fi 90752400Sbillf ;; 90852400Sbillf *) 90952400Sbillf echo " *** ${COMPFILE} will remain for your consideration" 91052400Sbillf ;; 91152400Sbillf esac 912200708Sdougb return 91352400Sbillf ;; 91452400Sbillf esac 91552400Sbillf 91652400Sbillf case "${DONT_INSTALL}" in 91752400Sbillf '') 91878490Sdougb do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}" 91952400Sbillf ;; 92052400Sbillf *) 92152400Sbillf unset DONT_INSTALL 92252400Sbillf ;; 92352400Sbillf esac 92478490Sdougb else # File matched -x 92578490Sdougb do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}" 92652400Sbillf fi 92752400Sbillf return $? 92852400Sbillf} 92952400Sbillf 930174841Sdougbif [ ! -d "${TEMPROOT}" ]; then 931174841Sdougb echo "*** FATAL ERROR: The temproot directory (${TEMPROOT})" 932174841Sdougb echo ' has disappeared!' 933174841Sdougb echo '' 934174841Sdougb exit 1 935174841Sdougbfi 936174841Sdougb 93767949Sdougbecho '' 93867949Sdougbecho "*** Beginning comparison" 93967949Sdougbecho '' 94052400Sbillf 941124136Sdougb# Pre-world does not populate /etc/rc.d. 942124053Sdougb# It is very possible that a previous run would have deleted files in 943124053Sdougb# ${TEMPROOT}/etc/rc.d, thus creating a lot of false positives. 944124136Sdougbif [ -z "${PRE_WORLD}" -a -z "${RERUN}" ]; then 945124053Sdougb echo " *** Checking ${DESTDIR}/etc/rc.d for stale files" 946124053Sdougb echo '' 947124053Sdougb cd "${DESTDIR}/etc/rc.d" && 948124053Sdougb for file in *; do 949124053Sdougb if [ ! -e "${TEMPROOT}/etc/rc.d/${file}" ]; then 950124053Sdougb STALE_RC_FILES="${STALE_RC_FILES} ${file}" 951124053Sdougb fi 952124053Sdougb done 953124053Sdougb case "${STALE_RC_FILES}" in 954126718Sdougb ''|' *') 955124053Sdougb echo ' *** No stale files found' 956124053Sdougb ;; 957124053Sdougb *) 958124053Sdougb echo " *** The following files exist in ${DESTDIR}/etc/rc.d but not in" 959124053Sdougb echo " ${TEMPROOT}/etc/rc.d/:" 960124053Sdougb echo '' 961124053Sdougb echo "${STALE_RC_FILES}" 962124053Sdougb echo '' 963124053Sdougb echo ' The presence of stale files in this directory can cause the' 964124053Sdougb echo ' dreaded unpredictable results, and therefore it is highly' 965124053Sdougb echo ' recommended that you delete them.' 966124053Sdougb case "${AUTO_RUN}" in 967124053Sdougb '') 968124053Sdougb echo '' 969153604Sdougb echo -n ' *** Delete them now? [n] ' 970124053Sdougb read DELETE_STALE_RC_FILES 971124053Sdougb case "${DELETE_STALE_RC_FILES}" in 972153604Sdougb [yY]) 973124053Sdougb echo ' *** Deleting ... ' 974124053Sdougb rm ${STALE_RC_FILES} 975124053Sdougb echo ' done.' 976124053Sdougb ;; 977153604Sdougb *) 978153604Sdougb echo ' *** Files will not be deleted' 979153604Sdougb ;; 980124053Sdougb esac 981124053Sdougb sleep 2 982124053Sdougb ;; 983201291Sdougb *) 984201291Sdougb if [ -n "${DELETE_STALE_RC_FILES}" ]; then 985201291Sdougb echo ' *** Deleting ... ' 986201291Sdougb rm ${STALE_RC_FILES} 987201291Sdougb echo ' done.' 988201291Sdougb fi 989124053Sdougb esac 990124053Sdougb ;; 991124053Sdougb esac 992124053Sdougb echo '' 993124136Sdougbfi 994124053Sdougb 99567949Sdougbcd "${TEMPROOT}" 99667949Sdougb 99767949Sdougbif [ -r "${MM_PRE_COMPARE_SCRIPT}" ]; then 99867949Sdougb . "${MM_PRE_COMPARE_SCRIPT}" 99967949Sdougbfi 100067949Sdougb 1001200425Sdougb# Things that were files/directories/links in one version can sometimes 1002200425Sdougb# change to something else in a newer version. So we need to explicitly 1003200425Sdougb# test for this, and warn the user if what we find does not match. 1004200425Sdougb# 1005200700Sdougbfor COMPFILE in `find . | sort` ; do 1006200425Sdougb if [ -e "${DESTDIR}${COMPFILE#.}" ]; then 1007200425Sdougb INSTALLED_TYPE=`stat -f '%HT' ${DESTDIR}${COMPFILE#.}` 1008200425Sdougb else 1009200425Sdougb continue 1010200425Sdougb fi 1011200425Sdougb TEMPROOT_TYPE=`stat -f '%HT' $COMPFILE` 1012200425Sdougb 1013200425Sdougb if [ ! "$TEMPROOT_TYPE" = "$INSTALLED_TYPE" ]; then 1014200425Sdougb [ "$COMPFILE" = '.' ] && continue 1015200425Sdougb TEMPROOT_TYPE=`echo $TEMPROOT_TYPE | tr [:upper:] [:lower:]` 1016200425Sdougb INSTALLED_TYPE=`echo $INSTALLED_TYPE | tr [:upper:] [:lower:]` 1017200425Sdougb 1018200425Sdougb echo "*** The installed file ${DESTDIR}${COMPFILE#.} has the type \"$INSTALLED_TYPE\"" 1019200425Sdougb echo " but the new version has the type \"$TEMPROOT_TYPE\"" 1020200425Sdougb echo '' 1021200425Sdougb echo " How would you like to handle this?" 1022200425Sdougb echo '' 1023200425Sdougb echo " Use 'r' to remove ${DESTDIR}${COMPFILE#.}" 1024200425Sdougb case "$TEMPROOT_TYPE" in 1025200425Sdougb 'symbolic link') 1026200425Sdougb TARGET=`readlink $COMPFILE` 1027200425Sdougb echo " and create a link to $TARGET in its place" ;; 1028200425Sdougb *) echo " You will be able to install it as a \"$TEMPROOT_TYPE\"" ;; 1029200425Sdougb esac 1030200425Sdougb echo '' 1031200425Sdougb echo " Use 'i' to ignore this" 1032200425Sdougb echo '' 1033200425Sdougb echo -n " How to proceed? [i] " 1034200425Sdougb read ANSWER 1035200425Sdougb case "$ANSWER" in 1036200425Sdougb [rR]) case "${PRESERVE_FILES}" in 1037200425Sdougb [Yy][Ee][Ss]) 1038200425Sdougb mv ${DESTDIR}${COMPFILE#.} ${PRESERVE_FILES_DIR}/ || exit 1 ;; 1039200425Sdougb *) rm -rf ${DESTDIR}${COMPFILE#.} ;; 1040200425Sdougb esac 1041200425Sdougb case "$TEMPROOT_TYPE" in 1042200425Sdougb 'symbolic link') ln -sf $TARGET ${DESTDIR}${COMPFILE#.} ;; 1043200425Sdougb esac ;; 1044200425Sdougb *) echo '' 1045200425Sdougb echo "*** See the man page about adding ${COMPFILE#.} to the list of IGNORE_FILES" 1046200425Sdougb press_to_continue ;; 1047200425Sdougb esac 1048200425Sdougb echo '' 1049200425Sdougb fi 1050200425Sdougbdone 1051200425Sdougb 1052200700Sdougbfor COMPFILE in `find . -type f | sort`; do 105367949Sdougb 105467949Sdougb # First, check to see if the file exists in DESTDIR. If not, the 105567949Sdougb # diff_loop function knows how to handle it. 105667949Sdougb # 105767949Sdougb if [ ! -e "${DESTDIR}${COMPFILE#.}" ]; then 105877325Sdougb case "${AUTO_RUN}" in 105977325Sdougb '') 106077325Sdougb diff_loop 106177325Sdougb ;; 106277325Sdougb *) 106377325Sdougb case "${AUTO_INSTALL}" in 106477325Sdougb '') 106577325Sdougb # If this is an auto run, make it official 106677325Sdougb echo " *** ${COMPFILE} will remain for your consideration" 106777325Sdougb ;; 106877325Sdougb *) 106977325Sdougb diff_loop 107077325Sdougb ;; 107177325Sdougb esac 107277325Sdougb ;; 107377325Sdougb esac # Auto run test 107467949Sdougb continue 107567949Sdougb fi 107667949Sdougb 107752400Sbillf case "${STRICT}" in 107852400Sbillf '' | [Nn][Oo]) 107952400Sbillf # Compare CVS $Id's first so if the file hasn't been modified 108052400Sbillf # local changes will be ignored. 108152400Sbillf # If the files have the same $Id, delete the one in temproot so the 108252400Sbillf # user will have less to wade through if files are left to merge by hand. 108352400Sbillf # 108473651Sdougb CVSID1=`grep "[$]${CVS_ID_TAG}:" ${DESTDIR}${COMPFILE#.} 2>/dev/null` 108590564Sdougb CVSID2=`grep "[$]${CVS_ID_TAG}:" ${COMPFILE} 2>/dev/null` || CVSID2=none 108652400Sbillf 108767949Sdougb case "${CVSID2}" in 108873651Sdougb "${CVSID1}") 108967949Sdougb echo " *** Temp ${COMPFILE} and installed have the same CVS Id, deleting" 109067949Sdougb rm "${COMPFILE}" 109167949Sdougb ;; 109267949Sdougb esac 109352400Sbillf ;; 109452400Sbillf esac 109552400Sbillf 109652400Sbillf # If the file is still here either because the $Ids are different, the 109752400Sbillf # file doesn't have an $Id, or we're using STRICT mode; look at the diff. 109852400Sbillf # 109952400Sbillf if [ -f "${COMPFILE}" ]; then 110052400Sbillf 110152400Sbillf # Do an absolute diff first to see if the files are actually different. 110252400Sbillf # If they're not different, delete the one in temproot. 110352400Sbillf # 1104110377Sdougb if diff -q ${DIFF_OPTIONS} "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" > \ 1105110377Sdougb /dev/null 2>&1; then 110652400Sbillf echo " *** Temp ${COMPFILE} and installed are the same, deleting" 110752400Sbillf rm "${COMPFILE}" 110852400Sbillf else 110977323Sdougb # Ok, the files are different, so show the user where they differ. 111077323Sdougb # Use user's choice of diff methods; and user's pager if they have one. 111177323Sdougb # Use more if not. 111267859Sdougb # Use unified diffs by default. Context diffs give me a headache. :) 111352400Sbillf # 1114189992Sdougb # If the user chose the -F option, test for that before proceeding 1115189992Sdougb # 1116189992Sdougb if [ -n "$FREEBSD_ID" ]; then 1117201291Sdougb if diff -q -I'[$]FreeBSD.*[$]' "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" > \ 1118189992Sdougb /dev/null 2>&1; then 1119189992Sdougb if mm_install "${COMPFILE}"; then 1120189992Sdougb echo "*** Updated revision control Id for ${DESTDIR}${COMPFILE#.}" 1121189992Sdougb else 1122189992Sdougb echo "*** Problem installing ${COMPFILE}, it will remain to merge by hand later" 1123189992Sdougb fi 1124189992Sdougb continue 1125189992Sdougb fi 1126189992Sdougb fi 112752400Sbillf case "${AUTO_RUN}" in 112852400Sbillf '') 112958910Salfred # prompt user to install/delete/merge changes 113058910Salfred diff_loop 113152400Sbillf ;; 113252400Sbillf *) 113352400Sbillf # If this is an auto run, make it official 113452400Sbillf echo " *** ${COMPFILE} will remain for your consideration" 113552400Sbillf ;; 113652400Sbillf esac # Auto run test 113752400Sbillf fi # Yes, the files are different 113852400Sbillf fi # Yes, the file still remains to be checked 1139189763Sdougbdone # This is for the for way up there at the beginning of the comparison 114052400Sbillf 114152534Sbillfecho '' 114252400Sbillfecho "*** Comparison complete" 1143158149Sgordon 1144192230Sdougbif [ -s "${MTREENEW}" ]; then 1145158149Sgordon echo "*** Saving mtree database for future upgrades" 1146200416Sdougb test -e "${MTREEFILE}" && unlink ${MTREEFILE} 1147200416Sdougb mv ${MTREENEW} ${MTREEFILE} 1148158149Sgordonfi 1149158149Sgordon 115052400Sbillfecho '' 115152400Sbillf 115252400SbillfTEST_FOR_FILES=`find ${TEMPROOT} -type f -size +0 2>/dev/null` 115352400Sbillfif [ -n "${TEST_FOR_FILES}" ]; then 115452400Sbillf echo "*** Files that remain for you to merge by hand:" 1155200700Sdougb find "${TEMPROOT}" -type f -size +0 | sort 115677335Sdougb echo '' 115752400Sbillf 1158201765Sdougb case "${AUTO_RUN}" in 1159201765Sdougb '') 1160201765Sdougb echo -n "Do you wish to delete what is left of ${TEMPROOT}? [no] " 1161201765Sdougb read DEL_TEMPROOT 1162201765Sdougb case "${DEL_TEMPROOT}" in 1163201765Sdougb [yY]*) 1164201765Sdougb delete_temproot 1165201765Sdougb ;; 1166201765Sdougb *) 1167201765Sdougb echo " *** ${TEMPROOT} will remain" 1168201765Sdougb ;; 1169201765Sdougb esac 117052400Sbillf ;; 1171201765Sdougb *) ;; 117252400Sbillf esac 1173201765Sdougbelse 1174201765Sdougb echo "*** ${TEMPROOT} is empty, deleting" 1175201765Sdougb delete_temproot 1176201765Sdougbfi 117752400Sbillf 117868153Sdougbcase "${AUTO_INSTALLED_FILES}" in 117968153Sdougb'') ;; 118068153Sdougb*) 118173651Sdougb case "${AUTO_RUN}" in 118273651Sdougb '') 118373651Sdougb ( 118473651Sdougb echo '' 118577323Sdougb echo '*** You chose the automatic install option for files that did not' 118677323Sdougb echo ' exist on your system. The following were installed for you:' 118773651Sdougb echo "${AUTO_INSTALLED_FILES}" 118873651Sdougb ) | ${PAGER} 118973651Sdougb ;; 119073651Sdougb *) 119168153Sdougb echo '' 119277323Sdougb echo '*** You chose the automatic install option for files that did not' 119377323Sdougb echo ' exist on your system. The following were installed for you:' 119468153Sdougb echo "${AUTO_INSTALLED_FILES}" 119573651Sdougb ;; 119673651Sdougb esac 119768153Sdougb ;; 119868153Sdougbesac 119968153Sdougb 1200158149Sgordoncase "${AUTO_UPGRADED_FILES}" in 1201158149Sgordon'') ;; 1202158149Sgordon*) 1203158149Sgordon case "${AUTO_RUN}" in 1204158149Sgordon '') 1205158149Sgordon ( 1206158149Sgordon echo '' 1207158149Sgordon echo '*** You chose the automatic upgrade option for files that you did' 1208158149Sgordon echo ' not alter on your system. The following were upgraded for you:' 1209158149Sgordon echo "${AUTO_UPGRADED_FILES}" 1210158149Sgordon ) | ${PAGER} 1211158149Sgordon ;; 1212158149Sgordon *) 1213158149Sgordon echo '' 1214158149Sgordon echo '*** You chose the automatic upgrade option for files that you did' 1215158149Sgordon echo ' not alter on your system. The following were upgraded for you:' 1216158149Sgordon echo "${AUTO_UPGRADED_FILES}" 1217158149Sgordon ;; 1218158149Sgordon esac 1219158149Sgordon ;; 1220158149Sgordonesac 1221158149Sgordon 122273651Sdougbrun_it_now () { 122373651Sdougb case "${AUTO_RUN}" in 122473651Sdougb '') 122573651Sdougb unset YES_OR_NO 122673651Sdougb echo '' 122777335Sdougb echo -n ' Would you like to run it now? y or n [n] ' 122873651Sdougb read YES_OR_NO 122973651Sdougb 123073651Sdougb case "${YES_OR_NO}" in 123173651Sdougb y) 123277335Sdougb echo " Running ${1}" 123377335Sdougb echo '' 123473651Sdougb eval "${1}" 123573651Sdougb ;; 123677335Sdougb ''|n) 123777335Sdougb echo '' 123877335Sdougb echo " *** Cancelled" 123977335Sdougb echo '' 124077335Sdougb echo " Make sure to run ${1} yourself" 124177335Sdougb ;; 124273651Sdougb *) 124377335Sdougb echo '' 124477335Sdougb echo " *** Sorry, I do not understand your answer (${YES_OR_NO})" 124577335Sdougb echo '' 124677335Sdougb echo " Make sure to run ${1} yourself" 124773651Sdougb esac 124873651Sdougb ;; 124973651Sdougb *) ;; 125073651Sdougb esac 125173651Sdougb} 125273651Sdougb 125352400Sbillfcase "${NEED_NEWALIASES}" in 125452400Sbillf'') ;; 125552400Sbillf*) 125652400Sbillf echo '' 125777335Sdougb if [ -n "${DESTDIR}" ]; then 125877335Sdougb echo "*** You installed a new aliases file into ${DESTDIR}/etc/mail, but" 125977335Sdougb echo " the newaliases command is limited to the directories configured" 126077335Sdougb echo " in sendmail.cf. Make sure to create your aliases database by" 126177335Sdougb echo " hand when your sendmail configuration is done." 126277335Sdougb else 126377335Sdougb echo "*** You installed a new aliases file, so make sure that you run" 126477335Sdougb echo " '/usr/bin/newaliases' to rebuild your aliases database" 126577335Sdougb run_it_now '/usr/bin/newaliases' 126677335Sdougb fi 126752400Sbillf ;; 126852400Sbillfesac 126952400Sbillf 127052400Sbillfcase "${NEED_CAP_MKDB}" in 127152400Sbillf'') ;; 127252400Sbillf*) 127352400Sbillf echo '' 127452400Sbillf echo "*** You installed a login.conf file, so make sure that you run" 127577335Sdougb echo " '/usr/bin/cap_mkdb ${DESTDIR}/etc/login.conf'" 127677335Sdougb echo " to rebuild your login.conf database" 127777335Sdougb run_it_now "/usr/bin/cap_mkdb ${DESTDIR}/etc/login.conf" 127852400Sbillf ;; 127952400Sbillfesac 128052400Sbillf 128152400Sbillfcase "${NEED_PWD_MKDB}" in 128252400Sbillf'') ;; 128352400Sbillf*) 128452400Sbillf echo '' 128552400Sbillf echo "*** You installed a new master.passwd file, so make sure that you run" 128677335Sdougb if [ -n "${DESTDIR}" ]; then 128777335Sdougb echo " '/usr/sbin/pwd_mkdb -d ${DESTDIR}/etc -p ${DESTDIR}/etc/master.passwd'" 128877335Sdougb echo " to rebuild your password files" 128977335Sdougb run_it_now "/usr/sbin/pwd_mkdb -d ${DESTDIR}/etc -p ${DESTDIR}/etc/master.passwd" 129077335Sdougb else 129177335Sdougb echo " '/usr/sbin/pwd_mkdb -p /etc/master.passwd'" 129277335Sdougb echo " to rebuild your password files" 129377335Sdougb run_it_now '/usr/sbin/pwd_mkdb -p /etc/master.passwd' 129477335Sdougb fi 129552400Sbillf ;; 129652400Sbillfesac 129752400Sbillf 129852400Sbillfecho '' 129952400Sbillf 130067949Sdougbif [ -r "${MM_EXIT_SCRIPT}" ]; then 130167949Sdougb . "${MM_EXIT_SCRIPT}" 130267949Sdougbfi 130367949Sdougb 130491193Sdougbcase "${COMP_CONFS}" in 130591193Sdougb'') ;; 130691193Sdougb*) 130791193Sdougb . ${DESTDIR}/etc/defaults/rc.conf 130891193Sdougb 130991193Sdougb (echo '' 131091193Sdougb echo "*** Comparing conf files: ${rc_conf_files}" 131191193Sdougb 131291193Sdougb for CONF_FILE in ${rc_conf_files}; do 131391193Sdougb if [ -r "${DESTDIR}${CONF_FILE}" ]; then 131491193Sdougb echo '' 131591193Sdougb echo "*** From ${DESTDIR}${CONF_FILE}" 131691193Sdougb echo "*** From ${DESTDIR}/etc/defaults/rc.conf" 131791193Sdougb 131891193Sdougb for RC_CONF_VAR in `grep -i ^[a-z] ${DESTDIR}${CONF_FILE} | 131991193Sdougb cut -d '=' -f 1`; do 132091193Sdougb echo '' 132191223Sdougb grep -w ^${RC_CONF_VAR} ${DESTDIR}${CONF_FILE} 132291223Sdougb grep -w ^${RC_CONF_VAR} ${DESTDIR}/etc/defaults/rc.conf || 132391193Sdougb echo ' * No default variable with this name' 132491193Sdougb done 132591193Sdougb fi 132691193Sdougb done) | ${PAGER} 132791193Sdougb echo '' 132891193Sdougb ;; 132991193Sdougbesac 133091193Sdougb 133191193Sdougbcase "${PRE_WORLD}" in 133291193Sdougb'') ;; 133391193Sdougb*) 1334186678Sdougb MAKE_CONF="${SOURCEDIR}/share/examples/etc/make.conf" 133591193Sdougb 133691193Sdougb (echo '' 133791193Sdougb echo '*** Comparing make variables' 133891193Sdougb echo '' 133991193Sdougb echo "*** From ${DESTDIR}/etc/make.conf" 134091193Sdougb echo "*** From ${MAKE_CONF}" 134191193Sdougb 1342101348Sdougb for MAKE_VAR in `grep -i ^[a-z] ${DESTDIR}/etc/make.conf | cut -d '=' -f 1`; do 134391193Sdougb echo '' 134491223Sdougb grep -w ^${MAKE_VAR} ${DESTDIR}/etc/make.conf 134591223Sdougb grep -w ^#${MAKE_VAR} ${MAKE_CONF} || 134691193Sdougb echo ' * No example variable with this name' 134791193Sdougb done) | ${PAGER} 134891193Sdougb ;; 134991193Sdougbesac 135091193Sdougb 1351200425Sdougbif [ -n "${PRESERVE_FILES}" ]; then 1352200425Sdougb find -d $PRESERVE_FILES_DIR -type d -empty -delete 2>/dev/null 1353200425Sdougb rmdir $PRESERVE_FILES_DIR 2>/dev/null 1354200425Sdougbfi 1355200425Sdougb 135652400Sbillfexit 0 1357