mergemaster.sh revision 189763
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 8186678Sdougb# Copyright 1998-2009 Douglas Barton 973651Sdougb# DougB@FreeBSD.org 1052400Sbillf 1152495Sbillf# $FreeBSD: head/usr.sbin/mergemaster/mergemaster.sh 189763 2009-03-13 08:48:33Z 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}" 18189763Sdougb echo 'Usage: mergemaster [-scrvahipCPU]' 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' 2991193Sdougb echo ' -C Compare local rc.conf variables to the defaults' 30114501Sdougb echo ' -P Preserve files that are overwritten' 31189763Sdougb echo " -U Attempt to auto upgrade files that have not been user modified" 32189763Sdougb echo '' 3352400Sbillf echo " -m /path/directory Specify location of source to do the make in" 3452400Sbillf echo " -t /path/directory Specify temp root directory" 3552400Sbillf echo " -d Add date and time to directory name (e.g., /var/tmp/temproot.`date +%m%d.%H.%M`)" 3652400Sbillf echo " -u N Specify a numeric umask" 3752400Sbillf echo " -w N Specify a screen width in columns to sdiff" 38155309Srwatson echo " -A architecture Alternative architecture name to pass to make" 3967949Sdougb echo ' -D /path/directory Specify the destination directory to install files to' 4052400Sbillf echo '' 4152400Sbillf} 4252400Sbillf 4352400Sbillfdisplay_help () { 4452400Sbillf echo "* To specify a directory other than /var/tmp/temproot for the" 4552400Sbillf echo " temporary root environment, use -t /path/to/temp/root" 4652400Sbillf echo "* The -w option takes a number as an argument for the column width" 4767859Sdougb echo " of the screen. The default is 80." 4867949Sdougb echo '* The -a option causes mergemaster to run without prompting.' 4952400Sbillf} 5052400Sbillf 5158910Salfred# Loop allowing the user to use sdiff to merge files and display the merged 5258910Salfred# file. 5358910Salfredmerge_loop () { 5467850Sdougb case "${VERBOSE}" in 5567850Sdougb '') ;; 5667850Sdougb *) 5767850Sdougb echo " *** Type h at the sdiff prompt (%) to get usage help" 5867850Sdougb ;; 5967850Sdougb esac 6067850Sdougb echo '' 6167850Sdougb MERGE_AGAIN=yes 6267850Sdougb while [ "${MERGE_AGAIN}" = "yes" ]; do 6367850Sdougb # Prime file.merged so we don't blat the owner/group id's 6467850Sdougb cp -p "${COMPFILE}" "${COMPFILE}.merged" 6567850Sdougb sdiff -o "${COMPFILE}.merged" --text --suppress-common-lines \ 6667949Sdougb --width=${SCREEN_WIDTH:-80} "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" 6767850Sdougb INSTALL_MERGED=V 6867850Sdougb while [ "${INSTALL_MERGED}" = "v" -o "${INSTALL_MERGED}" = "V" ]; do 6967850Sdougb echo '' 7067850Sdougb echo " Use 'i' to install merged file" 7167850Sdougb echo " Use 'r' to re-do the merge" 7267850Sdougb echo " Use 'v' to view the merged file" 7367850Sdougb echo " Default is to leave the temporary file to deal with by hand" 7467850Sdougb echo '' 7567859Sdougb echo -n " *** How should I deal with the merged file? [Leave it for later] " 7667859Sdougb read INSTALL_MERGED 7758910Salfred 7867850Sdougb case "${INSTALL_MERGED}" in 7967850Sdougb [iI]) 8067850Sdougb mv "${COMPFILE}.merged" "${COMPFILE}" 8167850Sdougb echo '' 8267850Sdougb if mm_install "${COMPFILE}"; then 8367850Sdougb echo " *** Merged version of ${COMPFILE} installed successfully" 8467859Sdougb else 8567850Sdougb echo " *** Problem installing ${COMPFILE}, it will remain to merge by hand later" 8667859Sdougb fi 8767850Sdougb unset MERGE_AGAIN 8867850Sdougb ;; 8967850Sdougb [rR]) 9067850Sdougb rm "${COMPFILE}.merged" 9167859Sdougb ;; 9267850Sdougb [vV]) 9367850Sdougb ${PAGER} "${COMPFILE}.merged" 9467850Sdougb ;; 9567850Sdougb '') 9667850Sdougb echo " *** ${COMPFILE} will remain for your consideration" 9767850Sdougb unset MERGE_AGAIN 9867850Sdougb ;; 9967850Sdougb *) 10067850Sdougb echo "invalid choice: ${INSTALL_MERGED}" 10167850Sdougb INSTALL_MERGED=V 10267850Sdougb ;; 10367850Sdougb esac 10467850Sdougb done 10567850Sdougb done 10658910Salfred} 10758910Salfred 10858910Salfred# Loop showing user differences between files, allow merge, skip or install 10958910Salfred# options 11058910Salfreddiff_loop () { 11158910Salfred 11267850Sdougb HANDLE_COMPFILE=v 11358910Salfred 11477323Sdougb while [ "${HANDLE_COMPFILE}" = "v" -o "${HANDLE_COMPFILE}" = "V" -o \ 11577323Sdougb "${HANDLE_COMPFILE}" = "NOT V" ]; do 11667949Sdougb if [ -f "${DESTDIR}${COMPFILE#.}" -a -f "${COMPFILE}" ]; then 117158149Sgordon if [ -n "${AUTO_UPGRADE}" ]; then 118158149Sgordon if echo "${CHANGED}" | grep -qsv ${DESTDIR}${COMPFILE#.}; then 119158149Sgordon echo '' 120158149Sgordon echo " *** ${COMPFILE} has not been user modified." 121158149Sgordon echo '' 122158149Sgordon 123158149Sgordon if mm_install "${COMPFILE}"; then 124158149Sgordon echo " *** ${COMPFILE} upgraded successfully" 125158149Sgordon echo '' 126158149Sgordon # Make the list print one file per line 127158149Sgordon AUTO_UPGRADED_FILES="${AUTO_UPGRADED_FILES} ${DESTDIR}${COMPFILE#.} 128158149Sgordon" 129158149Sgordon else 130158149Sgordon echo " *** Problem upgrading ${COMPFILE}, it will remain to merge by hand" 131158149Sgordon fi 132158149Sgordon return 133158149Sgordon fi 134158149Sgordon fi 13567850Sdougb if [ "${HANDLE_COMPFILE}" = "v" -o "${HANDLE_COMPFILE}" = "V" ]; then 13690564Sdougb echo '' 137109993Sdillon echo ' ====================================================================== ' 138109993Sdillon echo '' 139109993Sdillon ( 140109993Sdillon echo " *** Displaying differences between ${COMPFILE} and installed version:" 141109993Sdillon echo '' 142110377Sdougb diff ${DIFF_FLAG} ${DIFF_OPTIONS} "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" 143109993Sdillon ) | ${PAGER} 144109993Sdillon echo '' 14567850Sdougb fi 14667850Sdougb else 147109993Sdillon echo '' 14867850Sdougb echo " *** There is no installed version of ${COMPFILE}" 14991193Sdougb echo '' 15067949Sdougb case "${AUTO_INSTALL}" in 15167949Sdougb [Yy][Ee][Ss]) 15267949Sdougb echo '' 15367949Sdougb if mm_install "${COMPFILE}"; then 15467949Sdougb echo " *** ${COMPFILE} installed successfully" 15568507Sdougb echo '' 15667949Sdougb # Make the list print one file per line 15767949Sdougb AUTO_INSTALLED_FILES="${AUTO_INSTALLED_FILES} ${DESTDIR}${COMPFILE#.} 15867949Sdougb" 15967949Sdougb else 16067949Sdougb echo " *** Problem installing ${COMPFILE}, it will remain to merge by hand" 16167949Sdougb fi 16267949Sdougb return 16367949Sdougb ;; 16467949Sdougb *) 16567949Sdougb NO_INSTALLED=yes 16667949Sdougb ;; 16767949Sdougb esac 16867850Sdougb fi 16967859Sdougb 17067850Sdougb echo " Use 'd' to delete the temporary ${COMPFILE}" 17167850Sdougb echo " Use 'i' to install the temporary ${COMPFILE}" 17267850Sdougb case "${NO_INSTALLED}" in 17367850Sdougb '') 17477326Sdougb echo " Use 'm' to merge the temporary and installed versions" 175109993Sdillon echo " Use 'v' to view the diff results again" 17667850Sdougb ;; 17767850Sdougb esac 17867850Sdougb echo '' 17967850Sdougb echo " Default is to leave the temporary file to deal with by hand" 18067850Sdougb echo '' 18167859Sdougb echo -n "How should I deal with this? [Leave it for later] " 18267859Sdougb read HANDLE_COMPFILE 18367859Sdougb 18467850Sdougb case "${HANDLE_COMPFILE}" in 18567850Sdougb [dD]) 18667850Sdougb rm "${COMPFILE}" 18767850Sdougb echo '' 18867850Sdougb echo " *** Deleting ${COMPFILE}" 18967850Sdougb ;; 19067850Sdougb [iI]) 19167850Sdougb echo '' 19267850Sdougb if mm_install "${COMPFILE}"; then 19367850Sdougb echo " *** ${COMPFILE} installed successfully" 19467850Sdougb else 19567850Sdougb echo " *** Problem installing ${COMPFILE}, it will remain to merge by hand" 19667850Sdougb fi 19767850Sdougb ;; 19867850Sdougb [mM]) 19967850Sdougb case "${NO_INSTALLED}" in 20067850Sdougb '') 20167850Sdougb # interact with user to merge files 20267850Sdougb merge_loop 20367850Sdougb ;; 20467850Sdougb *) 20567850Sdougb echo '' 20667850Sdougb echo " *** There is no installed version of ${COMPFILE}" 20767850Sdougb echo '' 20867850Sdougb HANDLE_COMPFILE="NOT V" 20967850Sdougb ;; 21067850Sdougb esac # End of "No installed version of file but user selected merge" test 21167850Sdougb ;; 21267850Sdougb [vV]) 21367850Sdougb continue 21467850Sdougb ;; 21567850Sdougb '') 21667850Sdougb echo '' 21767850Sdougb echo " *** ${COMPFILE} will remain for your consideration" 21867850Sdougb ;; 21967850Sdougb *) 22067850Sdougb # invalid choice, show menu again. 22167850Sdougb echo "invalid choice: ${HANDLE_COMPFILE}" 22267850Sdougb echo '' 22367850Sdougb HANDLE_COMPFILE="NOT V" 22467850Sdougb continue 22567850Sdougb ;; 22667850Sdougb esac # End of "How to handle files that are different" 22767859Sdougb done 22867850Sdougb unset NO_INSTALLED 22967850Sdougb echo '' 23067850Sdougb case "${VERBOSE}" in 23167850Sdougb '') ;; 23267850Sdougb *) 23367850Sdougb sleep 3 23467850Sdougb ;; 23567850Sdougb esac 23658910Salfred} 23758910Salfred 23897960Sdougbpress_to_continue () { 23997960Sdougb local DISCARD 24097960Sdougb echo -n ' *** Press the [Enter] or [Return] key to continue ' 24197960Sdougb read DISCARD 24297960Sdougb} 24397960Sdougb 24452400Sbillf# Set the default path for the temporary root environment 24552400Sbillf# 24652400SbillfTEMPROOT='/var/tmp/temproot' 24752400Sbillf 24873651Sdougb# Read /etc/mergemaster.rc first so the one in $HOME can override 24973651Sdougb# 25073651Sdougbif [ -r /etc/mergemaster.rc ]; then 25173651Sdougb . /etc/mergemaster.rc 25273651Sdougbfi 25373651Sdougb 25452400Sbillf# Read .mergemasterrc before command line so CLI can override 25552400Sbillf# 25667949Sdougbif [ -r "$HOME/.mergemasterrc" ]; then 25752400Sbillf . "$HOME/.mergemasterrc" 25852400Sbillffi 25952400Sbillf 260186678Sdougb# Assign the location of the mtree database 261186678Sdougb# 262186678SdougbMTREEDB=${MTREEDB:-/var/db} 263186678SdougbMTREEFILE="${MTREEDB}/mergemaster.mtree" 264186678Sdougb 26552400Sbillf# Check the command line options 26652400Sbillf# 267158149Sgordonwhile getopts ":ascrvhipCPm:t:du:w:D:A:U" COMMAND_LINE_ARGUMENT ; do 26852400Sbillf case "${COMMAND_LINE_ARGUMENT}" in 269155309Srwatson A) 270186678Sdougb ARCHSTRING='TARGET_ARCH='${OPTARG} 271155309Srwatson ;; 272158149Sgordon U) 273158149Sgordon AUTO_UPGRADE=yes 274158149Sgordon ;; 27552400Sbillf s) 27652400Sbillf STRICT=yes 277110377Sdougb unset DIFF_OPTIONS 27852400Sbillf ;; 27952400Sbillf c) 28052400Sbillf DIFF_FLAG='-c' 28152400Sbillf ;; 28252400Sbillf r) 28352400Sbillf RERUN=yes 28452400Sbillf ;; 28552400Sbillf v) 28652400Sbillf case "${AUTO_RUN}" in 28752400Sbillf '') VERBOSE=yes ;; 28852400Sbillf esac 28952400Sbillf ;; 29052400Sbillf a) 29152400Sbillf AUTO_RUN=yes 29252400Sbillf unset VERBOSE 29352400Sbillf ;; 29452400Sbillf h) 29552400Sbillf display_usage 29652400Sbillf display_help 29752400Sbillf exit 0 29852400Sbillf ;; 29967949Sdougb i) 30067949Sdougb AUTO_INSTALL=yes 30167949Sdougb ;; 30296045Sdougb C) 30396045Sdougb COMP_CONFS=yes 30496045Sdougb ;; 305114501Sdougb P) 306114501Sdougb PRESERVE_FILES=yes 307114501Sdougb ;; 30891193Sdougb p) 30991193Sdougb PRE_WORLD=yes 31096045Sdougb unset COMP_CONFS 31196045Sdougb unset AUTO_RUN 31291193Sdougb ;; 31352400Sbillf m) 31452400Sbillf SOURCEDIR=${OPTARG} 31552400Sbillf ;; 31652400Sbillf t) 31752400Sbillf TEMPROOT=${OPTARG} 31852400Sbillf ;; 31952400Sbillf d) 32052400Sbillf TEMPROOT=${TEMPROOT}.`date +%m%d.%H.%M` 32152400Sbillf ;; 32252400Sbillf u) 32352400Sbillf NEW_UMASK=${OPTARG} 32452400Sbillf ;; 32552400Sbillf w) 32652400Sbillf SCREEN_WIDTH=${OPTARG} 32752400Sbillf ;; 32867949Sdougb D) 32967949Sdougb DESTDIR=${OPTARG} 33067949Sdougb ;; 33152400Sbillf *) 33252400Sbillf display_usage 33352400Sbillf exit 1 33452400Sbillf ;; 33552400Sbillf esac 33652400Sbillfdone 33752400Sbillf 338114501Sdougb# Don't force the user to set this in the mergemaster rc file 339114501Sdougbif [ -n "${PRESERVE_FILES}" -a -z "${PRESERVE_FILES_DIR}" ]; then 340114501Sdougb PRESERVE_FILES_DIR=/var/tmp/mergemaster/preserved-files-`date +%y%m%d-%H%M%S` 341114501Sdougbfi 342114501Sdougb 343186678Sdougb# Check for the mtree database in DESTDIR 344186678Sdougbcase "${AUTO_UPGRADE}" in 345186678Sdougb'') ;; # If the option is not set no need to run the test or warn the user 346186678Sdougb*) 347186678Sdougb if [ ! -f "${DESTDIR}${MTREEFILE}" ]; then 348186678Sdougb echo '' 349186678Sdougb echo "*** Unable to find mtree database. Skipping auto-upgrade." 350186678Sdougb echo '' 351186678Sdougb press_to_continue 352186678Sdougb unset AUTO_UPGRADE 353186678Sdougb fi 354186678Sdougb ;; 355186678Sdougbesac 356186678Sdougb 357186689Sdougbif [ -e "${DESTDIR}/etc/fstab" ]; then 358186689Sdougb if grep -q nodev ${DESTDIR}/etc/fstab; then 359186689Sdougb echo '' 360186689Sdougb echo "*** You have the deprecated 'nodev' option in ${DESTDIR}/etc/fstab." 361186689Sdougb echo " This can prevent the filesystem from being mounted on reboot." 362186689Sdougb echo " Please update your fstab before continuing." 363186689Sdougb echo " See fstab(5) for more information." 364186689Sdougb echo '' 365186689Sdougb exit 1 366186689Sdougb fi 367158149Sgordonfi 368158149Sgordon 36952400Sbillfecho '' 37052400Sbillf 37152400Sbillf# If the user has a pager defined, make sure we can run it 37252400Sbillf# 37352400Sbillfcase "${DONT_CHECK_PAGER}" in 37452400Sbillf'') 375186695Sdougbcheck_pager () { 376186695Sdougb while ! type "${PAGER%% *}" >/dev/null; do 37752400Sbillf echo " *** Your PAGER environment variable specifies '${PAGER}', but" 37864467Sbrian echo " due to the limited PATH that I use for security reasons," 37967859Sdougb echo " I cannot execute it. So, what would you like to do?" 38052400Sbillf echo '' 38152400Sbillf echo " Use 'e' to exit mergemaster and fix your PAGER variable" 38264467Sbrian if [ -x /usr/bin/less -o -x /usr/local/bin/less ]; then 38364467Sbrian echo " Use 'l' to set PAGER to 'less' for this run" 38452400Sbillf fi 38552400Sbillf echo " Use 'm' to use plain old 'more' as your PAGER for this run" 38652400Sbillf echo '' 38752400Sbillf echo " Default is to use plain old 'more' " 38852400Sbillf echo '' 38967859Sdougb echo -n "What should I do? [Use 'more'] " 39067859Sdougb read FIXPAGER 39167859Sdougb 39252400Sbillf case "${FIXPAGER}" in 39358910Salfred [eE]) 39452400Sbillf exit 0 39552400Sbillf ;; 39658910Salfred [lL]) 39764467Sbrian if [ -x /usr/bin/less ]; then 39864467Sbrian PAGER=/usr/bin/less 39964467Sbrian elif [ -x /usr/local/bin/less ]; then 40058910Salfred PAGER=/usr/local/bin/less 40164467Sbrian else 40264467Sbrian echo '' 40364467Sbrian echo " *** Fatal Error:" 40464467Sbrian echo " You asked to use 'less' as your pager, but I can't" 40564467Sbrian echo " find it in /usr/bin or /usr/local/bin" 40664467Sbrian exit 1 40758910Salfred fi 40852400Sbillf ;; 40960420Sbsd [mM]|'') 41052400Sbillf PAGER=more 41152400Sbillf ;; 41258910Salfred *) 41358910Salfred echo '' 41458910Salfred echo "invalid choice: ${FIXPAGER}" 41552400Sbillf esac 41652400Sbillf echo '' 41758910Salfred done 418186695Sdougb} 419186695Sdougb if [ -n "${PAGER}" ]; then 420186695Sdougb check_pager 421186695Sdougb fi 42252400Sbillf ;; 42352400Sbillfesac 42452400Sbillf 42552400Sbillf# If user has a pager defined, or got assigned one above, use it. 42652400Sbillf# If not, use more. 42752400Sbillf# 42852400SbillfPAGER=${PAGER:-more} 42952400Sbillf 43052400Sbillfif [ -n "${VERBOSE}" -a ! "${PAGER}" = "more" ]; then 43152400Sbillf echo " *** You have ${PAGER} defined as your pager so we will use that" 43252400Sbillf echo '' 43352400Sbillf sleep 3 43452400Sbillffi 43552400Sbillf 43652400Sbillf# Assign the diff flag once so we will not have to keep testing it 43752400Sbillf# 43852400SbillfDIFF_FLAG=${DIFF_FLAG:--u} 43952400Sbillf 44052400Sbillf# Assign the source directory 44152400Sbillf# 442186678SdougbSOURCEDIR=${SOURCEDIR:-/usr/src} 443186678Sdougbif [ ! -f ${SOURCEDIR}/Makefile.inc1 -a \ 444186678Sdougb -f ${SOURCEDIR}/../Makefile.inc1 ]; then 445186678Sdougb echo " *** The source directory you specified (${SOURCEDIR})" 446186678Sdougb echo " will be reset to ${SOURCEDIR}/.." 447186678Sdougb echo '' 448186678Sdougb sleep 3 449186678Sdougb SOURCEDIR=${SOURCEDIR}/.. 450186678Sdougbfi 45152400Sbillf 452186678Sdougb# Setup make to use system files from SOURCEDIR 453186695SdougbMM_MAKE="make ${ARCHSTRING} -m ${SOURCEDIR}/share/mk" 454186678Sdougb 455158149Sgordon# Check DESTDIR against the mergemaster mtree database to see what 456158149Sgordon# files the user changed from the reference files. 457158149Sgordon# 458158149SgordonCHANGED= 459186678Sdougbif [ -n "${AUTO_UPGRADE}" -a -f "${DESTDIR}${MTREEFILE}" ]; then 460186678Sdougb for file in `mtree -eq -f ${DESTDIR}${MTREEFILE} -p ${DESTDIR}/ \ 461158149Sgordon 2>/dev/null | awk '($2 == "changed") {print $1}'`; do 462158149Sgordon if [ -f "${DESTDIR}/$file" ]; then 463158149Sgordon CHANGED="${CHANGED} ${DESTDIR}/$file" 464158149Sgordon fi 465158149Sgordon done 466158149Sgordonfi 467158149Sgordon 46896045Sdougb# Check the width of the user's terminal 46996045Sdougb# 47096045Sdougbif [ -t 0 ]; then 471110377Sdougb w=`tput columns` 47296045Sdougb case "${w}" in 47396045Sdougb 0|'') ;; # No-op, since the input is not valid 47496045Sdougb *) 47596045Sdougb case "${SCREEN_WIDTH}" in 47696045Sdougb '') SCREEN_WIDTH="${w}" ;; 47796045Sdougb "${w}") ;; # No-op, since they are the same 47896045Sdougb *) 47996045Sdougb echo -n "*** You entered ${SCREEN_WIDTH} as your screen width, but stty " 48096045Sdougb echo "thinks it is ${w}." 48196045Sdougb echo '' 48296045Sdougb echo -n "What would you like to use? [${w}] " 48396045Sdougb read SCREEN_WIDTH 48497380Sdougb case "${SCREEN_WIDTH}" in 48597380Sdougb '') SCREEN_WIDTH="${w}" ;; 48697380Sdougb esac 48796045Sdougb ;; 48896045Sdougb esac 48996045Sdougb esac 49096045Sdougbfi 49196045Sdougb 49273651Sdougb# Define what CVS $Id tag to look for to aid portability. 49373651Sdougb# 49473651SdougbCVS_ID_TAG=FreeBSD 49573651Sdougb 49699152Sdougbdelete_temproot () { 497101362Sdougb rm -rf "${TEMPROOT}" 2>/dev/null 498101362Sdougb chflags -R 0 "${TEMPROOT}" 2>/dev/null 499101362Sdougb rm -rf "${TEMPROOT}" || exit 1 50099152Sdougb} 50199152Sdougb 50252400Sbillfcase "${RERUN}" in 50352400Sbillf'') 50452400Sbillf # Set up the loop to test for the existence of the 50552400Sbillf # temp root directory. 50652400Sbillf # 50752400Sbillf TEST_TEMP_ROOT=yes 50852400Sbillf while [ "${TEST_TEMP_ROOT}" = "yes" ]; do 50952400Sbillf if [ -d "${TEMPROOT}" ]; then 51052400Sbillf echo "*** The directory specified for the temporary root environment," 51167859Sdougb echo " ${TEMPROOT}, exists. This can be a security risk if untrusted" 51252400Sbillf echo " users have access to the system." 51352400Sbillf echo '' 51452400Sbillf case "${AUTO_RUN}" in 51552400Sbillf '') 51652400Sbillf echo " Use 'd' to delete the old ${TEMPROOT} and continue" 51752400Sbillf echo " Use 't' to select a new temporary root directory" 51852400Sbillf echo " Use 'e' to exit mergemaster" 51952400Sbillf echo '' 52052400Sbillf echo " Default is to use ${TEMPROOT} as is" 52152400Sbillf echo '' 52267859Sdougb echo -n "How should I deal with this? [Use the existing ${TEMPROOT}] " 52367859Sdougb read DELORNOT 52467859Sdougb 52567859Sdougb case "${DELORNOT}" in 52667859Sdougb [dD]) 52767859Sdougb echo '' 52867859Sdougb echo " *** Deleting the old ${TEMPROOT}" 52967859Sdougb echo '' 53099152Sdougb delete_temproot || exit 1 53167859Sdougb unset TEST_TEMP_ROOT 53252400Sbillf ;; 53367859Sdougb [tT]) 53467859Sdougb echo " *** Enter new directory name for temporary root environment" 53567859Sdougb read TEMPROOT 53667859Sdougb ;; 53767859Sdougb [eE]) 53867859Sdougb exit 0 53967859Sdougb ;; 54067859Sdougb '') 54167859Sdougb echo '' 54267859Sdougb echo " *** Leaving ${TEMPROOT} intact" 54367859Sdougb echo '' 54467859Sdougb unset TEST_TEMP_ROOT 54567859Sdougb ;; 54667859Sdougb *) 54767859Sdougb echo '' 54867859Sdougb echo "invalid choice: ${DELORNOT}" 54967859Sdougb echo '' 55067859Sdougb ;; 55167859Sdougb esac 55267859Sdougb ;; 55352400Sbillf *) 55477323Sdougb # If this is an auto-run, try a hopefully safe alternative then 55577323Sdougb # re-test anyway. 55652400Sbillf TEMPROOT=/var/tmp/temproot.`date +%m%d.%H.%M.%S` 55752400Sbillf ;; 55852400Sbillf esac 55952400Sbillf else 56052400Sbillf unset TEST_TEMP_ROOT 56152400Sbillf fi 56252400Sbillf done 56352400Sbillf 56452400Sbillf echo "*** Creating the temporary root environment in ${TEMPROOT}" 56552400Sbillf 56652400Sbillf if mkdir -p "${TEMPROOT}"; then 56752400Sbillf echo " *** ${TEMPROOT} ready for use" 56852400Sbillf fi 56952400Sbillf 57052400Sbillf if [ ! -d "${TEMPROOT}" ]; then 57152400Sbillf echo '' 57252400Sbillf echo " *** FATAL ERROR: Cannot create ${TEMPROOT}" 57352400Sbillf echo '' 57452400Sbillf exit 1 57552400Sbillf fi 57652400Sbillf 57752400Sbillf echo " *** Creating and populating directory structure in ${TEMPROOT}" 57852400Sbillf echo '' 57952400Sbillf 58052400Sbillf case "${VERBOSE}" in 58152400Sbillf '') ;; 58252400Sbillf *) 58397960Sdougb press_to_continue 58452400Sbillf ;; 58552400Sbillf esac 58652400Sbillf 58791193Sdougb case "${PRE_WORLD}" in 58891193Sdougb '') 58991193Sdougb { cd ${SOURCEDIR} && 59091193Sdougb case "${DESTDIR}" in 59191193Sdougb '') ;; 59291193Sdougb *) 593186695Sdougb ${MM_MAKE} DESTDIR=${DESTDIR} distrib-dirs 59491193Sdougb ;; 59591193Sdougb esac 596186749Sdougb od=${TEMPROOT}/usr/obj 597186695Sdougb ${MM_MAKE} DESTDIR=${TEMPROOT} distrib-dirs && 598186749Sdougb MAKEOBJDIRPREFIX=$od ${MM_MAKE} _obj SUBDIR_OVERRIDE=etc && 599186749Sdougb MAKEOBJDIRPREFIX=$od ${MM_MAKE} everything SUBDIR_OVERRIDE=etc && 600186749Sdougb MAKEOBJDIRPREFIX=$od ${MM_MAKE} DESTDIR=${TEMPROOT} distribution;} || 60191193Sdougb { echo ''; 60291193Sdougb echo " *** FATAL ERROR: Cannot 'cd' to ${SOURCEDIR} and install files to"; 60391193Sdougb echo " the temproot environment"; 60491193Sdougb echo ''; 60591193Sdougb exit 1;} 60691193Sdougb ;; 60791193Sdougb *) 60891193Sdougb # Only set up files that are crucial to {build|install}world 60991193Sdougb { mkdir -p ${TEMPROOT}/etc && 610186678Sdougb cp -p ${SOURCEDIR}/etc/master.passwd ${TEMPROOT}/etc && 611186678Sdougb cp -p ${SOURCEDIR}/etc/group ${TEMPROOT}/etc;} || 61291193Sdougb { echo ''; 61391193Sdougb echo ' *** FATAL ERROR: Cannot copy files to the temproot environment'; 61491193Sdougb echo ''; 61591193Sdougb exit 1;} 61691193Sdougb ;; 61791193Sdougb esac 61852400Sbillf 61977323Sdougb # Doing the inventory and removing files that we don't want to compare only 62077323Sdougb # makes sense if we are not doing a rerun, since we have no way of knowing 62177323Sdougb # what happened to the files during previous incarnations. 62267949Sdougb case "${VERBOSE}" in 62367949Sdougb '') ;; 62467949Sdougb *) 62567949Sdougb echo '' 62667949Sdougb echo ' *** The following files exist only in the installed version of' 62767949Sdougb echo " ${DESTDIR}/etc. In the vast majority of cases these files" 62867949Sdougb echo ' are necessary parts of the system and should not be deleted.' 62967949Sdougb echo ' However because these files are not updated by this process you' 63067949Sdougb echo ' might want to verify their status before rebooting your system.' 63167949Sdougb echo '' 63297960Sdougb press_to_continue 633101348Sdougb diff -qr ${DESTDIR}/etc ${TEMPROOT}/etc | grep "^Only in ${DESTDIR}/etc" | ${PAGER} 63467949Sdougb echo '' 63597960Sdougb press_to_continue 63667949Sdougb ;; 63767949Sdougb esac 63867949Sdougb 63952534Sbillf # Avoid comparing the motd if the user specifies it in .mergemasterrc 640186678Sdougb # Compatibility shim to be removed in FreeBSD 9.x 64152534Sbillf case "${IGNORE_MOTD}" in 64252534Sbillf '') ;; 643186678Sdougb *) IGNORE_FILES="${IGNORE_FILES} /etc/motd" 644186678Sdougb echo '' 645186678Sdougb echo "*** You have the IGNORE_MOTD option set in your mergemaster rc file." 646186678Sdougb echo " This option is deprecated in favor of the IGNORE_FILES option." 647186678Sdougb echo " Please update your rc file accordingly." 648186678Sdougb echo '' 649186678Sdougb press_to_continue 65052534Sbillf ;; 65152534Sbillf esac 65252534Sbillf 653186678Sdougb # Avoid comparing the following user specified files 654186678Sdougb for file in ${IGNORE_FILES}; do 655186688Sdougb test -e ${TEMPROOT}/${file} && unlink ${TEMPROOT}/${file} 656186678Sdougb done 65752400Sbillf ;; # End of the "RERUN" test 65852400Sbillfesac 65952400Sbillf 660111901Sdougb# We really don't want to have to deal with files like login.conf.db, pwd.db, 661111901Sdougb# or spwd.db. Instead, we want to compare the text versions, and run *_mkdb. 662111901Sdougb# Prompt the user to do so below, as needed. 66377478Sdougb# 664111905Sdougbrm -f ${TEMPROOT}/etc/*.db ${TEMPROOT}/etc/passwd 66577478Sdougb 66694196Sdougb# We only need to compare things like freebsd.cf once 66796045Sdougbfind ${TEMPROOT}/usr/obj -type f -delete 2>/dev/null 66894196Sdougb 669158149Sgordon# Delete 0 length files to make the mtree database as small as possible. 670158149Sgordonfind ${TEMPROOT} -type f -size 0 -delete 2>/dev/null 671158149Sgordon 672158149Sgordon# Build the mtree database in a temporary location. 673186678SdougbMTREENEW=`mktemp -t mergemaster.mtree` 674158149Sgordoncase "${PRE_WORLD}" in 675189761Sdougb'') mtree -ci -p ${TEMPROOT} -k size,md5digest > ${MTREENEW} 2>/dev/null 676158149Sgordon ;; 677158149Sgordon*) # We don't want to mess with the mtree database on a pre-world run. 678158149Sgordon ;; 679158149Sgordonesac 680158149Sgordon 68152400Sbillf# Get ready to start comparing files 68252400Sbillf 68398084Sdougb# Check umask if not specified on the command line, 68498084Sdougb# and we are not doing an autorun 68552400Sbillf# 68698084Sdougbif [ -z "${NEW_UMASK}" -a -z "${AUTO_RUN}" ]; then 68798084Sdougb USER_UMASK=`umask` 68852400Sbillf case "${USER_UMASK}" in 68977335Sdougb 0022|022) ;; 69052400Sbillf *) 69152400Sbillf echo '' 69298084Sdougb echo " *** Your umask is currently set to ${USER_UMASK}. By default, this script" 69398084Sdougb echo " installs all files with the same user, group and modes that" 694186678Sdougb echo " they are created with by ${SOURCEDIR}/etc/Makefile, compared to" 69598084Sdougb echo " a umask of 022. This umask allows world read permission when" 69698084Sdougb echo " the file's default permissions have it." 69752400Sbillf echo '' 69898084Sdougb echo " No world permissions can sometimes cause problems. A umask of" 69998084Sdougb echo " 022 will restore the default behavior, but is not mandatory." 70098084Sdougb echo " /etc/master.passwd is a special case. Its file permissions" 70198084Sdougb echo " will be 600 (rw-------) if installed." 70297960Sdougb echo '' 70398084Sdougb echo -n "What umask should I use? [${USER_UMASK}] " 70498084Sdougb read NEW_UMASK 70598084Sdougb 70698084Sdougb NEW_UMASK="${NEW_UMASK:-$USER_UMASK}" 70752400Sbillf ;; 70852400Sbillf esac 70952400Sbillf echo '' 71098084Sdougbfi 71152400Sbillf 71298084SdougbCONFIRMED_UMASK=${NEW_UMASK:-0022} 71398084Sdougb 71452400Sbillf# 715114501Sdougb# Warn users who still have old rc files 716114501Sdougb# 717179315Sbzfor file in atm devfs diskless1 diskless2 network network6 pccard \ 718114523Sdougb serial syscons sysctl alpha amd64 i386 ia64 sparc64; do 719114501Sdougb if [ -f "${DESTDIR}/etc/rc.${file}" ]; then 720114501Sdougb OLD_RC_PRESENT=1 721114501Sdougb break 722114501Sdougb fi 723114501Sdougbdone 724114501Sdougb 725114501Sdougbcase "${OLD_RC_PRESENT}" in 726114501Sdougb1) 72752400Sbillf echo '' 728114501Sdougb echo " *** There are elements of the old rc system in ${DESTDIR}/etc/." 72967949Sdougb echo '' 730114501Sdougb echo ' While these scripts will not hurt anything, they are not' 731114501Sdougb echo ' functional on an up to date system, and can be removed.' 73267949Sdougb echo '' 733114501Sdougb 73452400Sbillf case "${AUTO_RUN}" in 73552400Sbillf '') 736114501Sdougb echo -n 'Move these files to /var/tmp/mergemaster/old_rc? [yes] ' 737114501Sdougb read MOVE_OLD_RC 73867859Sdougb 739114501Sdougb case "${MOVE_OLD_RC}" in 740114501Sdougb [nN]*) ;; 74152400Sbillf *) 742114501Sdougb mkdir -p /var/tmp/mergemaster/old_rc 743179315Sbz for file in atm devfs diskless1 diskless2 network network6 pccard \ 744114523Sdougb serial syscons sysctl alpha amd64 i386 ia64 sparc64; do 745114501Sdougb if [ -f "${DESTDIR}/etc/rc.${file}" ]; then 746114501Sdougb mv ${DESTDIR}/etc/rc.${file} /var/tmp/mergemaster/old_rc/ 747114501Sdougb fi 748114501Sdougb done 749114501Sdougb echo ' The files have been moved' 750114501Sdougb press_to_continue 75152400Sbillf ;; 75252400Sbillf esac 75352400Sbillf ;; 75452400Sbillf *) ;; 75552400Sbillf esac 756114501Sdougbesac 75752400Sbillf 75898084Sdougb# Use the umask/mode information to install the files 75952400Sbillf# Create directories as needed 76052400Sbillf# 761186678Sdougbinstall_error () { 762186678Sdougb echo "*** FATAL ERROR: Unable to install ${1} to ${2}" 763186678Sdougb echo '' 764186678Sdougb exit 1 765186678Sdougb} 766186678Sdougb 76778490Sdougbdo_install_and_rm () { 768114501Sdougb case "${PRESERVE_FILES}" in 769114501Sdougb [Yy][Ee][Ss]) 770114501Sdougb if [ -f "${3}/${2##*/}" ]; then 771114565Sdougb mkdir -p ${PRESERVE_FILES_DIR}/${2%/*} 772114565Sdougb cp ${3}/${2##*/} ${PRESERVE_FILES_DIR}/${2%/*} 773114501Sdougb fi 774114501Sdougb ;; 775114501Sdougb esac 776114501Sdougb 777186678Sdougb if [ ! -d "${3}/${2##*/}" ]; then 778186678Sdougb if install -m ${1} ${2} ${3}; then 779186678Sdougb unlink ${2} 780186678Sdougb else 781186678Sdougb install_error ${2} ${3} 782186678Sdougb fi 783186678Sdougb else 784186678Sdougb install_error ${2} ${3} 785186678Sdougb fi 78678490Sdougb} 78778490Sdougb 78898084Sdougb# 4095 = "obase=10;ibase=8;07777" | bc 78998084Sdougbfind_mode () { 79098084Sdougb local OCTAL 79198084Sdougb OCTAL=$(( ~$(echo "obase=10; ibase=8; ${CONFIRMED_UMASK}" | bc) & 4095 & 792124053Sdougb $(echo "obase=10; ibase=8; $(stat -f "%OMp%OLp" ${1})" | bc) )) 79398084Sdougb printf "%04o\n" ${OCTAL} 79498084Sdougb} 79598084Sdougb 79652400Sbillfmm_install () { 79752400Sbillf local INSTALL_DIR 79852400Sbillf INSTALL_DIR=${1#.} 79952400Sbillf INSTALL_DIR=${INSTALL_DIR%/*} 80067949Sdougb 80152400Sbillf case "${INSTALL_DIR}" in 80252400Sbillf '') 80352400Sbillf INSTALL_DIR=/ 80452400Sbillf ;; 80552400Sbillf esac 80652400Sbillf 80767949Sdougb if [ -n "${DESTDIR}${INSTALL_DIR}" -a ! -d "${DESTDIR}${INSTALL_DIR}" ]; then 80898084Sdougb DIR_MODE=`find_mode "${TEMPROOT}/${INSTALL_DIR}"` 80967949Sdougb install -d -o root -g wheel -m "${DIR_MODE}" "${DESTDIR}${INSTALL_DIR}" 81052400Sbillf fi 81152400Sbillf 81298084Sdougb FILE_MODE=`find_mode "${1}"` 81352400Sbillf 81452400Sbillf if [ ! -x "${1}" ]; then 81552400Sbillf case "${1#.}" in 81664625Sgshapiro /etc/mail/aliases) 81752400Sbillf NEED_NEWALIASES=yes 81852400Sbillf ;; 81952400Sbillf /etc/login.conf) 82052400Sbillf NEED_CAP_MKDB=yes 82152400Sbillf ;; 82252400Sbillf /etc/master.passwd) 82378490Sdougb do_install_and_rm 600 "${1}" "${DESTDIR}${INSTALL_DIR}" 82452400Sbillf NEED_PWD_MKDB=yes 82552400Sbillf DONT_INSTALL=yes 82652400Sbillf ;; 82752400Sbillf /.cshrc | /.profile) 82877335Sdougb case "${AUTO_INSTALL}" in 82977335Sdougb '') 83052400Sbillf case "${LINK_EXPLAINED}" in 83152400Sbillf '') 83267859Sdougb echo " *** Historically BSD derived systems have had a" 83367859Sdougb echo " hard link from /.cshrc and /.profile to" 83467859Sdougb echo " their namesakes in /root. Please indicate" 83567859Sdougb echo " your preference below for bringing your" 83667859Sdougb echo " installed files up to date." 83752400Sbillf echo '' 83852400Sbillf LINK_EXPLAINED=yes 83952400Sbillf ;; 84052400Sbillf esac 84152400Sbillf 84252400Sbillf echo " Use 'd' to delete the temporary ${COMPFILE}" 84367949Sdougb echo " Use 'l' to delete the existing ${DESTDIR}${COMPFILE#.} and create the link" 84452400Sbillf echo '' 84552400Sbillf echo " Default is to leave the temporary file to deal with by hand" 84652400Sbillf echo '' 84767859Sdougb echo -n " How should I handle ${COMPFILE}? [Leave it to install later] " 84867859Sdougb read HANDLE_LINK 84977335Sdougb ;; 85077335Sdougb *) # Part of AUTO_INSTALL 85177335Sdougb HANDLE_LINK=l 85277335Sdougb ;; 85377335Sdougb esac 85467859Sdougb 85552400Sbillf case "${HANDLE_LINK}" in 85652400Sbillf [dD]*) 85752400Sbillf rm "${COMPFILE}" 85852400Sbillf echo '' 85952400Sbillf echo " *** Deleting ${COMPFILE}" 86052400Sbillf ;; 86152400Sbillf [lL]*) 86252400Sbillf echo '' 86367949Sdougb rm -f "${DESTDIR}${COMPFILE#.}" 86467949Sdougb if ln "${DESTDIR}/root/${COMPFILE##*/}" "${DESTDIR}${COMPFILE#.}"; then 86567949Sdougb echo " *** Link from ${DESTDIR}${COMPFILE#.} to ${DESTDIR}/root/${COMPFILE##*/} installed successfully" 86652400Sbillf rm "${COMPFILE}" 86752400Sbillf else 86867949Sdougb echo " *** Error linking ${DESTDIR}${COMPFILE#.} to ${DESTDIR}/root/${COMPFILE##*/}, ${COMPFILE} will remain to install by hand" 86952400Sbillf fi 87052400Sbillf ;; 87152400Sbillf *) 87252400Sbillf echo " *** ${COMPFILE} will remain for your consideration" 87352400Sbillf ;; 87452400Sbillf esac 87552400Sbillf DONT_INSTALL=yes 87652400Sbillf ;; 87752400Sbillf esac 87852400Sbillf 87952400Sbillf case "${DONT_INSTALL}" in 88052400Sbillf '') 88178490Sdougb do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}" 88252400Sbillf ;; 88352400Sbillf *) 88452400Sbillf unset DONT_INSTALL 88552400Sbillf ;; 88652400Sbillf esac 88778490Sdougb else # File matched -x 88878490Sdougb do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}" 88952400Sbillf fi 89052400Sbillf return $? 89152400Sbillf} 89252400Sbillf 893174841Sdougbif [ ! -d "${TEMPROOT}" ]; then 894174841Sdougb echo "*** FATAL ERROR: The temproot directory (${TEMPROOT})" 895174841Sdougb echo ' has disappeared!' 896174841Sdougb echo '' 897174841Sdougb exit 1 898174841Sdougbfi 899174841Sdougb 90067949Sdougbecho '' 90167949Sdougbecho "*** Beginning comparison" 90267949Sdougbecho '' 90352400Sbillf 904124136Sdougb# Pre-world does not populate /etc/rc.d. 905124053Sdougb# It is very possible that a previous run would have deleted files in 906124053Sdougb# ${TEMPROOT}/etc/rc.d, thus creating a lot of false positives. 907124136Sdougbif [ -z "${PRE_WORLD}" -a -z "${RERUN}" ]; then 908124053Sdougb echo " *** Checking ${DESTDIR}/etc/rc.d for stale files" 909124053Sdougb echo '' 910124053Sdougb cd "${DESTDIR}/etc/rc.d" && 911124053Sdougb for file in *; do 912124053Sdougb if [ ! -e "${TEMPROOT}/etc/rc.d/${file}" ]; then 913124053Sdougb STALE_RC_FILES="${STALE_RC_FILES} ${file}" 914124053Sdougb fi 915124053Sdougb done 916124053Sdougb case "${STALE_RC_FILES}" in 917126718Sdougb ''|' *') 918124053Sdougb echo ' *** No stale files found' 919124053Sdougb ;; 920124053Sdougb *) 921124053Sdougb echo " *** The following files exist in ${DESTDIR}/etc/rc.d but not in" 922124053Sdougb echo " ${TEMPROOT}/etc/rc.d/:" 923124053Sdougb echo '' 924124053Sdougb echo "${STALE_RC_FILES}" 925124053Sdougb echo '' 926124053Sdougb echo ' The presence of stale files in this directory can cause the' 927124053Sdougb echo ' dreaded unpredictable results, and therefore it is highly' 928124053Sdougb echo ' recommended that you delete them.' 929124053Sdougb case "${AUTO_RUN}" in 930124053Sdougb '') 931124053Sdougb echo '' 932153604Sdougb echo -n ' *** Delete them now? [n] ' 933124053Sdougb read DELETE_STALE_RC_FILES 934124053Sdougb case "${DELETE_STALE_RC_FILES}" in 935153604Sdougb [yY]) 936124053Sdougb echo ' *** Deleting ... ' 937124053Sdougb rm ${STALE_RC_FILES} 938124053Sdougb echo ' done.' 939124053Sdougb ;; 940153604Sdougb *) 941153604Sdougb echo ' *** Files will not be deleted' 942153604Sdougb ;; 943124053Sdougb esac 944124053Sdougb sleep 2 945124053Sdougb ;; 946124053Sdougb esac 947124053Sdougb ;; 948124053Sdougb esac 949124053Sdougb echo '' 950124136Sdougbfi 951124053Sdougb 95267949Sdougbcd "${TEMPROOT}" 95367949Sdougb 95467949Sdougbif [ -r "${MM_PRE_COMPARE_SCRIPT}" ]; then 95567949Sdougb . "${MM_PRE_COMPARE_SCRIPT}" 95667949Sdougbfi 95767949Sdougb 95852400Sbillf# Using -size +0 avoids uselessly checking the empty log files created 959186678Sdougb# by ${SOURCEDIR}/etc/Makefile and the device entries in ./dev, but does 96067949Sdougb# check the scripts in ./dev, as we'd like (assuming no devfs of course). 96152400Sbillf# 96252400Sbillffor COMPFILE in `find . -type f -size +0`; do 96367949Sdougb 96467949Sdougb # First, check to see if the file exists in DESTDIR. If not, the 96567949Sdougb # diff_loop function knows how to handle it. 96667949Sdougb # 96767949Sdougb if [ ! -e "${DESTDIR}${COMPFILE#.}" ]; then 96877325Sdougb case "${AUTO_RUN}" in 96977325Sdougb '') 97077325Sdougb diff_loop 97177325Sdougb ;; 97277325Sdougb *) 97377325Sdougb case "${AUTO_INSTALL}" in 97477325Sdougb '') 97577325Sdougb # If this is an auto run, make it official 97677325Sdougb echo " *** ${COMPFILE} will remain for your consideration" 97777325Sdougb ;; 97877325Sdougb *) 97977325Sdougb diff_loop 98077325Sdougb ;; 98177325Sdougb esac 98277325Sdougb ;; 98377325Sdougb esac # Auto run test 98467949Sdougb continue 98567949Sdougb fi 98667949Sdougb 98752400Sbillf case "${STRICT}" in 98852400Sbillf '' | [Nn][Oo]) 98952400Sbillf # Compare CVS $Id's first so if the file hasn't been modified 99052400Sbillf # local changes will be ignored. 99152400Sbillf # If the files have the same $Id, delete the one in temproot so the 99252400Sbillf # user will have less to wade through if files are left to merge by hand. 99352400Sbillf # 99473651Sdougb CVSID1=`grep "[$]${CVS_ID_TAG}:" ${DESTDIR}${COMPFILE#.} 2>/dev/null` 99590564Sdougb CVSID2=`grep "[$]${CVS_ID_TAG}:" ${COMPFILE} 2>/dev/null` || CVSID2=none 99652400Sbillf 99767949Sdougb case "${CVSID2}" in 99873651Sdougb "${CVSID1}") 99967949Sdougb echo " *** Temp ${COMPFILE} and installed have the same CVS Id, deleting" 100067949Sdougb rm "${COMPFILE}" 100167949Sdougb ;; 100267949Sdougb esac 100352400Sbillf ;; 100452400Sbillf esac 100552400Sbillf 100652400Sbillf # If the file is still here either because the $Ids are different, the 100752400Sbillf # file doesn't have an $Id, or we're using STRICT mode; look at the diff. 100852400Sbillf # 100952400Sbillf if [ -f "${COMPFILE}" ]; then 101052400Sbillf 101152400Sbillf # Do an absolute diff first to see if the files are actually different. 101252400Sbillf # If they're not different, delete the one in temproot. 101352400Sbillf # 1014110377Sdougb if diff -q ${DIFF_OPTIONS} "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" > \ 1015110377Sdougb /dev/null 2>&1; then 101652400Sbillf echo " *** Temp ${COMPFILE} and installed are the same, deleting" 101752400Sbillf rm "${COMPFILE}" 101852400Sbillf else 101977323Sdougb # Ok, the files are different, so show the user where they differ. 102077323Sdougb # Use user's choice of diff methods; and user's pager if they have one. 102177323Sdougb # Use more if not. 102267859Sdougb # Use unified diffs by default. Context diffs give me a headache. :) 102352400Sbillf # 102452400Sbillf case "${AUTO_RUN}" in 102552400Sbillf '') 102658910Salfred # prompt user to install/delete/merge changes 102758910Salfred diff_loop 102852400Sbillf ;; 102952400Sbillf *) 103052400Sbillf # If this is an auto run, make it official 103152400Sbillf echo " *** ${COMPFILE} will remain for your consideration" 103252400Sbillf ;; 103352400Sbillf esac # Auto run test 103452400Sbillf fi # Yes, the files are different 103552400Sbillf fi # Yes, the file still remains to be checked 1036189763Sdougbdone # This is for the for way up there at the beginning of the comparison 103752400Sbillf 103852534Sbillfecho '' 103952400Sbillfecho "*** Comparison complete" 1040158149Sgordon 1041189761Sdougbif [ -f "${MTREENEW}" ]; then 1042158149Sgordon echo "*** Saving mtree database for future upgrades" 1043189761Sdougb test -e "${DESTDIR}${MTREEFILE}" && unlink ${DESTDIR}${MTREEFILE} 1044189761Sdougb mv ${MTREENEW} ${DESTDIR}${MTREEFILE} 1045158149Sgordonfi 1046158149Sgordon 104752400Sbillfecho '' 104852400Sbillf 104952400SbillfTEST_FOR_FILES=`find ${TEMPROOT} -type f -size +0 2>/dev/null` 105052400Sbillfif [ -n "${TEST_FOR_FILES}" ]; then 105152400Sbillf echo "*** Files that remain for you to merge by hand:" 105252400Sbillf find "${TEMPROOT}" -type f -size +0 105377335Sdougb echo '' 105452400Sbillffi 105552400Sbillf 105652400Sbillfcase "${AUTO_RUN}" in 105752400Sbillf'') 105867859Sdougb echo -n "Do you wish to delete what is left of ${TEMPROOT}? [no] " 105967859Sdougb read DEL_TEMPROOT 106067859Sdougb 106152400Sbillf case "${DEL_TEMPROOT}" in 106252400Sbillf [yY]*) 106399152Sdougb if delete_temproot; then 106452400Sbillf echo " *** ${TEMPROOT} has been deleted" 106552400Sbillf else 106652400Sbillf echo " *** Unable to delete ${TEMPROOT}" 106752400Sbillf fi 106852400Sbillf ;; 106952400Sbillf *) 107052400Sbillf echo " *** ${TEMPROOT} will remain" 107152400Sbillf ;; 107252400Sbillf esac 107352400Sbillf ;; 107452400Sbillf*) ;; 107552400Sbillfesac 107652400Sbillf 107768153Sdougbcase "${AUTO_INSTALLED_FILES}" in 107868153Sdougb'') ;; 107968153Sdougb*) 108073651Sdougb case "${AUTO_RUN}" in 108173651Sdougb '') 108273651Sdougb ( 108373651Sdougb echo '' 108477323Sdougb echo '*** You chose the automatic install option for files that did not' 108577323Sdougb echo ' exist on your system. The following were installed for you:' 108673651Sdougb echo "${AUTO_INSTALLED_FILES}" 108773651Sdougb ) | ${PAGER} 108873651Sdougb ;; 108973651Sdougb *) 109068153Sdougb echo '' 109177323Sdougb echo '*** You chose the automatic install option for files that did not' 109277323Sdougb echo ' exist on your system. The following were installed for you:' 109368153Sdougb echo "${AUTO_INSTALLED_FILES}" 109473651Sdougb ;; 109573651Sdougb esac 109668153Sdougb ;; 109768153Sdougbesac 109868153Sdougb 1099158149Sgordoncase "${AUTO_UPGRADED_FILES}" in 1100158149Sgordon'') ;; 1101158149Sgordon*) 1102158149Sgordon case "${AUTO_RUN}" in 1103158149Sgordon '') 1104158149Sgordon ( 1105158149Sgordon echo '' 1106158149Sgordon echo '*** You chose the automatic upgrade option for files that you did' 1107158149Sgordon echo ' not alter on your system. The following were upgraded for you:' 1108158149Sgordon echo "${AUTO_UPGRADED_FILES}" 1109158149Sgordon ) | ${PAGER} 1110158149Sgordon ;; 1111158149Sgordon *) 1112158149Sgordon echo '' 1113158149Sgordon echo '*** You chose the automatic upgrade option for files that you did' 1114158149Sgordon echo ' not alter on your system. The following were upgraded for you:' 1115158149Sgordon echo "${AUTO_UPGRADED_FILES}" 1116158149Sgordon ;; 1117158149Sgordon esac 1118158149Sgordon ;; 1119158149Sgordonesac 1120158149Sgordon 112173651Sdougbrun_it_now () { 112273651Sdougb case "${AUTO_RUN}" in 112373651Sdougb '') 112473651Sdougb unset YES_OR_NO 112573651Sdougb echo '' 112677335Sdougb echo -n ' Would you like to run it now? y or n [n] ' 112773651Sdougb read YES_OR_NO 112873651Sdougb 112973651Sdougb case "${YES_OR_NO}" in 113073651Sdougb y) 113177335Sdougb echo " Running ${1}" 113277335Sdougb echo '' 113373651Sdougb eval "${1}" 113473651Sdougb ;; 113577335Sdougb ''|n) 113677335Sdougb echo '' 113777335Sdougb echo " *** Cancelled" 113877335Sdougb echo '' 113977335Sdougb echo " Make sure to run ${1} yourself" 114077335Sdougb ;; 114173651Sdougb *) 114277335Sdougb echo '' 114377335Sdougb echo " *** Sorry, I do not understand your answer (${YES_OR_NO})" 114477335Sdougb echo '' 114577335Sdougb echo " Make sure to run ${1} yourself" 114673651Sdougb esac 114773651Sdougb ;; 114873651Sdougb *) ;; 114973651Sdougb esac 115073651Sdougb} 115173651Sdougb 115252400Sbillfcase "${NEED_NEWALIASES}" in 115352400Sbillf'') ;; 115452400Sbillf*) 115552400Sbillf echo '' 115677335Sdougb if [ -n "${DESTDIR}" ]; then 115777335Sdougb echo "*** You installed a new aliases file into ${DESTDIR}/etc/mail, but" 115877335Sdougb echo " the newaliases command is limited to the directories configured" 115977335Sdougb echo " in sendmail.cf. Make sure to create your aliases database by" 116077335Sdougb echo " hand when your sendmail configuration is done." 116177335Sdougb else 116277335Sdougb echo "*** You installed a new aliases file, so make sure that you run" 116377335Sdougb echo " '/usr/bin/newaliases' to rebuild your aliases database" 116477335Sdougb run_it_now '/usr/bin/newaliases' 116577335Sdougb fi 116652400Sbillf ;; 116752400Sbillfesac 116852400Sbillf 116952400Sbillfcase "${NEED_CAP_MKDB}" in 117052400Sbillf'') ;; 117152400Sbillf*) 117252400Sbillf echo '' 117352400Sbillf echo "*** You installed a login.conf file, so make sure that you run" 117477335Sdougb echo " '/usr/bin/cap_mkdb ${DESTDIR}/etc/login.conf'" 117577335Sdougb echo " to rebuild your login.conf database" 117677335Sdougb run_it_now "/usr/bin/cap_mkdb ${DESTDIR}/etc/login.conf" 117752400Sbillf ;; 117852400Sbillfesac 117952400Sbillf 118052400Sbillfcase "${NEED_PWD_MKDB}" in 118152400Sbillf'') ;; 118252400Sbillf*) 118352400Sbillf echo '' 118452400Sbillf echo "*** You installed a new master.passwd file, so make sure that you run" 118577335Sdougb if [ -n "${DESTDIR}" ]; then 118677335Sdougb echo " '/usr/sbin/pwd_mkdb -d ${DESTDIR}/etc -p ${DESTDIR}/etc/master.passwd'" 118777335Sdougb echo " to rebuild your password files" 118877335Sdougb run_it_now "/usr/sbin/pwd_mkdb -d ${DESTDIR}/etc -p ${DESTDIR}/etc/master.passwd" 118977335Sdougb else 119077335Sdougb echo " '/usr/sbin/pwd_mkdb -p /etc/master.passwd'" 119177335Sdougb echo " to rebuild your password files" 119277335Sdougb run_it_now '/usr/sbin/pwd_mkdb -p /etc/master.passwd' 119377335Sdougb fi 119452400Sbillf ;; 119552400Sbillfesac 119652400Sbillf 119752400Sbillfecho '' 119852400Sbillf 119967949Sdougbif [ -r "${MM_EXIT_SCRIPT}" ]; then 120067949Sdougb . "${MM_EXIT_SCRIPT}" 120167949Sdougbfi 120267949Sdougb 120391193Sdougbcase "${COMP_CONFS}" in 120491193Sdougb'') ;; 120591193Sdougb*) 120691193Sdougb . ${DESTDIR}/etc/defaults/rc.conf 120791193Sdougb 120891193Sdougb (echo '' 120991193Sdougb echo "*** Comparing conf files: ${rc_conf_files}" 121091193Sdougb 121191193Sdougb for CONF_FILE in ${rc_conf_files}; do 121291193Sdougb if [ -r "${DESTDIR}${CONF_FILE}" ]; then 121391193Sdougb echo '' 121491193Sdougb echo "*** From ${DESTDIR}${CONF_FILE}" 121591193Sdougb echo "*** From ${DESTDIR}/etc/defaults/rc.conf" 121691193Sdougb 121791193Sdougb for RC_CONF_VAR in `grep -i ^[a-z] ${DESTDIR}${CONF_FILE} | 121891193Sdougb cut -d '=' -f 1`; do 121991193Sdougb echo '' 122091223Sdougb grep -w ^${RC_CONF_VAR} ${DESTDIR}${CONF_FILE} 122191223Sdougb grep -w ^${RC_CONF_VAR} ${DESTDIR}/etc/defaults/rc.conf || 122291193Sdougb echo ' * No default variable with this name' 122391193Sdougb done 122491193Sdougb fi 122591193Sdougb done) | ${PAGER} 122691193Sdougb echo '' 122791193Sdougb ;; 122891193Sdougbesac 122991193Sdougb 123091193Sdougbcase "${PRE_WORLD}" in 123191193Sdougb'') ;; 123291193Sdougb*) 1233186678Sdougb MAKE_CONF="${SOURCEDIR}/share/examples/etc/make.conf" 123491193Sdougb 123591193Sdougb (echo '' 123691193Sdougb echo '*** Comparing make variables' 123791193Sdougb echo '' 123891193Sdougb echo "*** From ${DESTDIR}/etc/make.conf" 123991193Sdougb echo "*** From ${MAKE_CONF}" 124091193Sdougb 1241101348Sdougb for MAKE_VAR in `grep -i ^[a-z] ${DESTDIR}/etc/make.conf | cut -d '=' -f 1`; do 124291193Sdougb echo '' 124391223Sdougb grep -w ^${MAKE_VAR} ${DESTDIR}/etc/make.conf 124491223Sdougb grep -w ^#${MAKE_VAR} ${MAKE_CONF} || 124591193Sdougb echo ' * No example variable with this name' 124691193Sdougb done) | ${PAGER} 124791193Sdougb ;; 124891193Sdougbesac 124991193Sdougb 125052400Sbillfexit 0 125167850Sdougb 1252