mergemaster.sh revision 189992
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 189992 2009-03-18 21:51:11Z 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}" 18189992Sdougb echo 'Usage: mergemaster [-scrvahipFCPU]' 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' 29189992Sdougb echo ' -F Install files that differ only by revision control Id ($FreeBSD: head/usr.sbin/mergemaster/mergemaster.sh 189992 2009-03-18 21:51:11Z dougb $)' 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 118158149Sgordon if [ -n "${AUTO_UPGRADE}" ]; then 119158149Sgordon if echo "${CHANGED}" | grep -qsv ${DESTDIR}${COMPFILE#.}; then 120158149Sgordon echo '' 121158149Sgordon echo " *** ${COMPFILE} has not been user modified." 122158149Sgordon echo '' 123158149Sgordon 124158149Sgordon if mm_install "${COMPFILE}"; then 125158149Sgordon echo " *** ${COMPFILE} upgraded successfully" 126158149Sgordon echo '' 127158149Sgordon # Make the list print one file per line 128158149Sgordon AUTO_UPGRADED_FILES="${AUTO_UPGRADED_FILES} ${DESTDIR}${COMPFILE#.} 129158149Sgordon" 130158149Sgordon else 131158149Sgordon echo " *** Problem upgrading ${COMPFILE}, it will remain to merge by hand" 132158149Sgordon fi 133158149Sgordon return 134158149Sgordon fi 135158149Sgordon fi 13667850Sdougb if [ "${HANDLE_COMPFILE}" = "v" -o "${HANDLE_COMPFILE}" = "V" ]; then 13790564Sdougb echo '' 138109993Sdillon echo ' ====================================================================== ' 139109993Sdillon echo '' 140109993Sdillon ( 141109993Sdillon echo " *** Displaying differences between ${COMPFILE} and installed version:" 142109993Sdillon echo '' 143110377Sdougb diff ${DIFF_FLAG} ${DIFF_OPTIONS} "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" 144109993Sdillon ) | ${PAGER} 145109993Sdillon echo '' 14667850Sdougb fi 14767850Sdougb else 148109993Sdillon echo '' 14967850Sdougb echo " *** There is no installed version of ${COMPFILE}" 15091193Sdougb echo '' 15167949Sdougb case "${AUTO_INSTALL}" in 15267949Sdougb [Yy][Ee][Ss]) 15367949Sdougb echo '' 15467949Sdougb if mm_install "${COMPFILE}"; then 15567949Sdougb echo " *** ${COMPFILE} installed successfully" 15668507Sdougb echo '' 15767949Sdougb # Make the list print one file per line 15867949Sdougb AUTO_INSTALLED_FILES="${AUTO_INSTALLED_FILES} ${DESTDIR}${COMPFILE#.} 15967949Sdougb" 16067949Sdougb else 16167949Sdougb echo " *** Problem installing ${COMPFILE}, it will remain to merge by hand" 16267949Sdougb fi 16367949Sdougb return 16467949Sdougb ;; 16567949Sdougb *) 16667949Sdougb NO_INSTALLED=yes 16767949Sdougb ;; 16867949Sdougb esac 16967850Sdougb fi 17067859Sdougb 17167850Sdougb echo " Use 'd' to delete the temporary ${COMPFILE}" 17267850Sdougb echo " Use 'i' to install the temporary ${COMPFILE}" 17367850Sdougb case "${NO_INSTALLED}" in 17467850Sdougb '') 17577326Sdougb echo " Use 'm' to merge the temporary and installed versions" 176109993Sdillon echo " Use 'v' to view the diff results again" 17767850Sdougb ;; 17867850Sdougb esac 17967850Sdougb echo '' 18067850Sdougb echo " Default is to leave the temporary file to deal with by hand" 18167850Sdougb echo '' 18267859Sdougb echo -n "How should I deal with this? [Leave it for later] " 18367859Sdougb read HANDLE_COMPFILE 18467859Sdougb 18567850Sdougb case "${HANDLE_COMPFILE}" in 18667850Sdougb [dD]) 18767850Sdougb rm "${COMPFILE}" 18867850Sdougb echo '' 18967850Sdougb echo " *** Deleting ${COMPFILE}" 19067850Sdougb ;; 19167850Sdougb [iI]) 19267850Sdougb echo '' 19367850Sdougb if mm_install "${COMPFILE}"; then 19467850Sdougb echo " *** ${COMPFILE} installed successfully" 19567850Sdougb else 19667850Sdougb echo " *** Problem installing ${COMPFILE}, it will remain to merge by hand" 19767850Sdougb fi 19867850Sdougb ;; 19967850Sdougb [mM]) 20067850Sdougb case "${NO_INSTALLED}" in 20167850Sdougb '') 20267850Sdougb # interact with user to merge files 20367850Sdougb merge_loop 20467850Sdougb ;; 20567850Sdougb *) 20667850Sdougb echo '' 20767850Sdougb echo " *** There is no installed version of ${COMPFILE}" 20867850Sdougb echo '' 20967850Sdougb HANDLE_COMPFILE="NOT V" 21067850Sdougb ;; 21167850Sdougb esac # End of "No installed version of file but user selected merge" test 21267850Sdougb ;; 21367850Sdougb [vV]) 21467850Sdougb continue 21567850Sdougb ;; 21667850Sdougb '') 21767850Sdougb echo '' 21867850Sdougb echo " *** ${COMPFILE} will remain for your consideration" 21967850Sdougb ;; 22067850Sdougb *) 22167850Sdougb # invalid choice, show menu again. 22267850Sdougb echo "invalid choice: ${HANDLE_COMPFILE}" 22367850Sdougb echo '' 22467850Sdougb HANDLE_COMPFILE="NOT V" 22567850Sdougb continue 22667850Sdougb ;; 22767850Sdougb esac # End of "How to handle files that are different" 22867859Sdougb done 22967850Sdougb unset NO_INSTALLED 23067850Sdougb echo '' 23167850Sdougb case "${VERBOSE}" in 23267850Sdougb '') ;; 23367850Sdougb *) 23467850Sdougb sleep 3 23567850Sdougb ;; 23667850Sdougb esac 23758910Salfred} 23858910Salfred 23997960Sdougbpress_to_continue () { 24097960Sdougb local DISCARD 24197960Sdougb echo -n ' *** Press the [Enter] or [Return] key to continue ' 24297960Sdougb read DISCARD 24397960Sdougb} 24497960Sdougb 24552400Sbillf# Set the default path for the temporary root environment 24652400Sbillf# 24752400SbillfTEMPROOT='/var/tmp/temproot' 24852400Sbillf 24973651Sdougb# Read /etc/mergemaster.rc first so the one in $HOME can override 25073651Sdougb# 25173651Sdougbif [ -r /etc/mergemaster.rc ]; then 25273651Sdougb . /etc/mergemaster.rc 25373651Sdougbfi 25473651Sdougb 25552400Sbillf# Read .mergemasterrc before command line so CLI can override 25652400Sbillf# 25767949Sdougbif [ -r "$HOME/.mergemasterrc" ]; then 25852400Sbillf . "$HOME/.mergemasterrc" 25952400Sbillffi 26052400Sbillf 261186678Sdougb# Assign the location of the mtree database 262186678Sdougb# 263186678SdougbMTREEDB=${MTREEDB:-/var/db} 264186678SdougbMTREEFILE="${MTREEDB}/mergemaster.mtree" 265186678Sdougb 26652400Sbillf# Check the command line options 26752400Sbillf# 268189992Sdougbwhile getopts ":ascrvhipCPm:t:du:w:D:A:FU" COMMAND_LINE_ARGUMENT ; do 26952400Sbillf case "${COMMAND_LINE_ARGUMENT}" in 270155309Srwatson A) 271186678Sdougb ARCHSTRING='TARGET_ARCH='${OPTARG} 272155309Srwatson ;; 273189992Sdougb F) 274189992Sdougb FREEBSD_ID=yes 275189992Sdougb ;; 276158149Sgordon U) 277158149Sgordon AUTO_UPGRADE=yes 278158149Sgordon ;; 27952400Sbillf s) 28052400Sbillf STRICT=yes 281110377Sdougb unset DIFF_OPTIONS 28252400Sbillf ;; 28352400Sbillf c) 28452400Sbillf DIFF_FLAG='-c' 28552400Sbillf ;; 28652400Sbillf r) 28752400Sbillf RERUN=yes 28852400Sbillf ;; 28952400Sbillf v) 29052400Sbillf case "${AUTO_RUN}" in 29152400Sbillf '') VERBOSE=yes ;; 29252400Sbillf esac 29352400Sbillf ;; 29452400Sbillf a) 29552400Sbillf AUTO_RUN=yes 29652400Sbillf unset VERBOSE 29752400Sbillf ;; 29852400Sbillf h) 29952400Sbillf display_usage 30052400Sbillf display_help 30152400Sbillf exit 0 30252400Sbillf ;; 30367949Sdougb i) 30467949Sdougb AUTO_INSTALL=yes 30567949Sdougb ;; 30696045Sdougb C) 30796045Sdougb COMP_CONFS=yes 30896045Sdougb ;; 309114501Sdougb P) 310114501Sdougb PRESERVE_FILES=yes 311114501Sdougb ;; 31291193Sdougb p) 31391193Sdougb PRE_WORLD=yes 31496045Sdougb unset COMP_CONFS 31596045Sdougb unset AUTO_RUN 31691193Sdougb ;; 31752400Sbillf m) 31852400Sbillf SOURCEDIR=${OPTARG} 31952400Sbillf ;; 32052400Sbillf t) 32152400Sbillf TEMPROOT=${OPTARG} 32252400Sbillf ;; 32352400Sbillf d) 32452400Sbillf TEMPROOT=${TEMPROOT}.`date +%m%d.%H.%M` 32552400Sbillf ;; 32652400Sbillf u) 32752400Sbillf NEW_UMASK=${OPTARG} 32852400Sbillf ;; 32952400Sbillf w) 33052400Sbillf SCREEN_WIDTH=${OPTARG} 33152400Sbillf ;; 33267949Sdougb D) 33367949Sdougb DESTDIR=${OPTARG} 33467949Sdougb ;; 33552400Sbillf *) 33652400Sbillf display_usage 33752400Sbillf exit 1 33852400Sbillf ;; 33952400Sbillf esac 34052400Sbillfdone 34152400Sbillf 342114501Sdougb# Don't force the user to set this in the mergemaster rc file 343114501Sdougbif [ -n "${PRESERVE_FILES}" -a -z "${PRESERVE_FILES_DIR}" ]; then 344114501Sdougb PRESERVE_FILES_DIR=/var/tmp/mergemaster/preserved-files-`date +%y%m%d-%H%M%S` 345114501Sdougbfi 346114501Sdougb 347186678Sdougb# Check for the mtree database in DESTDIR 348186678Sdougbcase "${AUTO_UPGRADE}" in 349186678Sdougb'') ;; # If the option is not set no need to run the test or warn the user 350186678Sdougb*) 351186678Sdougb if [ ! -f "${DESTDIR}${MTREEFILE}" ]; then 352186678Sdougb echo '' 353186678Sdougb echo "*** Unable to find mtree database. Skipping auto-upgrade." 354186678Sdougb echo '' 355186678Sdougb press_to_continue 356186678Sdougb unset AUTO_UPGRADE 357186678Sdougb fi 358186678Sdougb ;; 359186678Sdougbesac 360186678Sdougb 361186689Sdougbif [ -e "${DESTDIR}/etc/fstab" ]; then 362186689Sdougb if grep -q nodev ${DESTDIR}/etc/fstab; then 363186689Sdougb echo '' 364186689Sdougb echo "*** You have the deprecated 'nodev' option in ${DESTDIR}/etc/fstab." 365186689Sdougb echo " This can prevent the filesystem from being mounted on reboot." 366186689Sdougb echo " Please update your fstab before continuing." 367186689Sdougb echo " See fstab(5) for more information." 368186689Sdougb echo '' 369186689Sdougb exit 1 370186689Sdougb fi 371158149Sgordonfi 372158149Sgordon 37352400Sbillfecho '' 37452400Sbillf 37552400Sbillf# If the user has a pager defined, make sure we can run it 37652400Sbillf# 37752400Sbillfcase "${DONT_CHECK_PAGER}" in 37852400Sbillf'') 379186695Sdougbcheck_pager () { 380186695Sdougb while ! type "${PAGER%% *}" >/dev/null; do 38152400Sbillf echo " *** Your PAGER environment variable specifies '${PAGER}', but" 38264467Sbrian echo " due to the limited PATH that I use for security reasons," 38367859Sdougb echo " I cannot execute it. So, what would you like to do?" 38452400Sbillf echo '' 38552400Sbillf echo " Use 'e' to exit mergemaster and fix your PAGER variable" 38664467Sbrian if [ -x /usr/bin/less -o -x /usr/local/bin/less ]; then 38764467Sbrian echo " Use 'l' to set PAGER to 'less' for this run" 38852400Sbillf fi 38952400Sbillf echo " Use 'm' to use plain old 'more' as your PAGER for this run" 39052400Sbillf echo '' 39152400Sbillf echo " Default is to use plain old 'more' " 39252400Sbillf echo '' 39367859Sdougb echo -n "What should I do? [Use 'more'] " 39467859Sdougb read FIXPAGER 39567859Sdougb 39652400Sbillf case "${FIXPAGER}" in 39758910Salfred [eE]) 39852400Sbillf exit 0 39952400Sbillf ;; 40058910Salfred [lL]) 40164467Sbrian if [ -x /usr/bin/less ]; then 40264467Sbrian PAGER=/usr/bin/less 40364467Sbrian elif [ -x /usr/local/bin/less ]; then 40458910Salfred PAGER=/usr/local/bin/less 40564467Sbrian else 40664467Sbrian echo '' 40764467Sbrian echo " *** Fatal Error:" 40864467Sbrian echo " You asked to use 'less' as your pager, but I can't" 40964467Sbrian echo " find it in /usr/bin or /usr/local/bin" 41064467Sbrian exit 1 41158910Salfred fi 41252400Sbillf ;; 41360420Sbsd [mM]|'') 41452400Sbillf PAGER=more 41552400Sbillf ;; 41658910Salfred *) 41758910Salfred echo '' 41858910Salfred echo "invalid choice: ${FIXPAGER}" 41952400Sbillf esac 42052400Sbillf echo '' 42158910Salfred done 422186695Sdougb} 423186695Sdougb if [ -n "${PAGER}" ]; then 424186695Sdougb check_pager 425186695Sdougb fi 42652400Sbillf ;; 42752400Sbillfesac 42852400Sbillf 42952400Sbillf# If user has a pager defined, or got assigned one above, use it. 43052400Sbillf# If not, use more. 43152400Sbillf# 43252400SbillfPAGER=${PAGER:-more} 43352400Sbillf 43452400Sbillfif [ -n "${VERBOSE}" -a ! "${PAGER}" = "more" ]; then 43552400Sbillf echo " *** You have ${PAGER} defined as your pager so we will use that" 43652400Sbillf echo '' 43752400Sbillf sleep 3 43852400Sbillffi 43952400Sbillf 44052400Sbillf# Assign the diff flag once so we will not have to keep testing it 44152400Sbillf# 44252400SbillfDIFF_FLAG=${DIFF_FLAG:--u} 44352400Sbillf 44452400Sbillf# Assign the source directory 44552400Sbillf# 446186678SdougbSOURCEDIR=${SOURCEDIR:-/usr/src} 447186678Sdougbif [ ! -f ${SOURCEDIR}/Makefile.inc1 -a \ 448186678Sdougb -f ${SOURCEDIR}/../Makefile.inc1 ]; then 449186678Sdougb echo " *** The source directory you specified (${SOURCEDIR})" 450186678Sdougb echo " will be reset to ${SOURCEDIR}/.." 451186678Sdougb echo '' 452186678Sdougb sleep 3 453186678Sdougb SOURCEDIR=${SOURCEDIR}/.. 454186678Sdougbfi 45552400Sbillf 456186678Sdougb# Setup make to use system files from SOURCEDIR 457186695SdougbMM_MAKE="make ${ARCHSTRING} -m ${SOURCEDIR}/share/mk" 458186678Sdougb 459158149Sgordon# Check DESTDIR against the mergemaster mtree database to see what 460158149Sgordon# files the user changed from the reference files. 461158149Sgordon# 462158149SgordonCHANGED= 463186678Sdougbif [ -n "${AUTO_UPGRADE}" -a -f "${DESTDIR}${MTREEFILE}" ]; then 464186678Sdougb for file in `mtree -eq -f ${DESTDIR}${MTREEFILE} -p ${DESTDIR}/ \ 465158149Sgordon 2>/dev/null | awk '($2 == "changed") {print $1}'`; do 466158149Sgordon if [ -f "${DESTDIR}/$file" ]; then 467158149Sgordon CHANGED="${CHANGED} ${DESTDIR}/$file" 468158149Sgordon fi 469158149Sgordon done 470158149Sgordonfi 471158149Sgordon 47296045Sdougb# Check the width of the user's terminal 47396045Sdougb# 47496045Sdougbif [ -t 0 ]; then 475110377Sdougb w=`tput columns` 47696045Sdougb case "${w}" in 47796045Sdougb 0|'') ;; # No-op, since the input is not valid 47896045Sdougb *) 47996045Sdougb case "${SCREEN_WIDTH}" in 48096045Sdougb '') SCREEN_WIDTH="${w}" ;; 48196045Sdougb "${w}") ;; # No-op, since they are the same 48296045Sdougb *) 48396045Sdougb echo -n "*** You entered ${SCREEN_WIDTH} as your screen width, but stty " 48496045Sdougb echo "thinks it is ${w}." 48596045Sdougb echo '' 48696045Sdougb echo -n "What would you like to use? [${w}] " 48796045Sdougb read SCREEN_WIDTH 48897380Sdougb case "${SCREEN_WIDTH}" in 48997380Sdougb '') SCREEN_WIDTH="${w}" ;; 49097380Sdougb esac 49196045Sdougb ;; 49296045Sdougb esac 49396045Sdougb esac 49496045Sdougbfi 49596045Sdougb 49673651Sdougb# Define what CVS $Id tag to look for to aid portability. 49773651Sdougb# 49873651SdougbCVS_ID_TAG=FreeBSD 49973651Sdougb 50099152Sdougbdelete_temproot () { 501101362Sdougb rm -rf "${TEMPROOT}" 2>/dev/null 502101362Sdougb chflags -R 0 "${TEMPROOT}" 2>/dev/null 503101362Sdougb rm -rf "${TEMPROOT}" || exit 1 50499152Sdougb} 50599152Sdougb 50652400Sbillfcase "${RERUN}" in 50752400Sbillf'') 50852400Sbillf # Set up the loop to test for the existence of the 50952400Sbillf # temp root directory. 51052400Sbillf # 51152400Sbillf TEST_TEMP_ROOT=yes 51252400Sbillf while [ "${TEST_TEMP_ROOT}" = "yes" ]; do 51352400Sbillf if [ -d "${TEMPROOT}" ]; then 51452400Sbillf echo "*** The directory specified for the temporary root environment," 51567859Sdougb echo " ${TEMPROOT}, exists. This can be a security risk if untrusted" 51652400Sbillf echo " users have access to the system." 51752400Sbillf echo '' 51852400Sbillf case "${AUTO_RUN}" in 51952400Sbillf '') 52052400Sbillf echo " Use 'd' to delete the old ${TEMPROOT} and continue" 52152400Sbillf echo " Use 't' to select a new temporary root directory" 52252400Sbillf echo " Use 'e' to exit mergemaster" 52352400Sbillf echo '' 52452400Sbillf echo " Default is to use ${TEMPROOT} as is" 52552400Sbillf echo '' 52667859Sdougb echo -n "How should I deal with this? [Use the existing ${TEMPROOT}] " 52767859Sdougb read DELORNOT 52867859Sdougb 52967859Sdougb case "${DELORNOT}" in 53067859Sdougb [dD]) 53167859Sdougb echo '' 53267859Sdougb echo " *** Deleting the old ${TEMPROOT}" 53367859Sdougb echo '' 53499152Sdougb delete_temproot || exit 1 53567859Sdougb unset TEST_TEMP_ROOT 53652400Sbillf ;; 53767859Sdougb [tT]) 53867859Sdougb echo " *** Enter new directory name for temporary root environment" 53967859Sdougb read TEMPROOT 54067859Sdougb ;; 54167859Sdougb [eE]) 54267859Sdougb exit 0 54367859Sdougb ;; 54467859Sdougb '') 54567859Sdougb echo '' 54667859Sdougb echo " *** Leaving ${TEMPROOT} intact" 54767859Sdougb echo '' 54867859Sdougb unset TEST_TEMP_ROOT 54967859Sdougb ;; 55067859Sdougb *) 55167859Sdougb echo '' 55267859Sdougb echo "invalid choice: ${DELORNOT}" 55367859Sdougb echo '' 55467859Sdougb ;; 55567859Sdougb esac 55667859Sdougb ;; 55752400Sbillf *) 55877323Sdougb # If this is an auto-run, try a hopefully safe alternative then 55977323Sdougb # re-test anyway. 56052400Sbillf TEMPROOT=/var/tmp/temproot.`date +%m%d.%H.%M.%S` 56152400Sbillf ;; 56252400Sbillf esac 56352400Sbillf else 56452400Sbillf unset TEST_TEMP_ROOT 56552400Sbillf fi 56652400Sbillf done 56752400Sbillf 56852400Sbillf echo "*** Creating the temporary root environment in ${TEMPROOT}" 56952400Sbillf 57052400Sbillf if mkdir -p "${TEMPROOT}"; then 57152400Sbillf echo " *** ${TEMPROOT} ready for use" 57252400Sbillf fi 57352400Sbillf 57452400Sbillf if [ ! -d "${TEMPROOT}" ]; then 57552400Sbillf echo '' 57652400Sbillf echo " *** FATAL ERROR: Cannot create ${TEMPROOT}" 57752400Sbillf echo '' 57852400Sbillf exit 1 57952400Sbillf fi 58052400Sbillf 58152400Sbillf echo " *** Creating and populating directory structure in ${TEMPROOT}" 58252400Sbillf echo '' 58352400Sbillf 58452400Sbillf case "${VERBOSE}" in 58552400Sbillf '') ;; 58652400Sbillf *) 58797960Sdougb press_to_continue 58852400Sbillf ;; 58952400Sbillf esac 59052400Sbillf 59191193Sdougb case "${PRE_WORLD}" in 59291193Sdougb '') 59391193Sdougb { cd ${SOURCEDIR} && 59491193Sdougb case "${DESTDIR}" in 59591193Sdougb '') ;; 59691193Sdougb *) 597186695Sdougb ${MM_MAKE} DESTDIR=${DESTDIR} distrib-dirs 59891193Sdougb ;; 59991193Sdougb esac 600186749Sdougb od=${TEMPROOT}/usr/obj 601186695Sdougb ${MM_MAKE} DESTDIR=${TEMPROOT} distrib-dirs && 602186749Sdougb MAKEOBJDIRPREFIX=$od ${MM_MAKE} _obj SUBDIR_OVERRIDE=etc && 603186749Sdougb MAKEOBJDIRPREFIX=$od ${MM_MAKE} everything SUBDIR_OVERRIDE=etc && 604186749Sdougb MAKEOBJDIRPREFIX=$od ${MM_MAKE} DESTDIR=${TEMPROOT} distribution;} || 60591193Sdougb { echo ''; 60691193Sdougb echo " *** FATAL ERROR: Cannot 'cd' to ${SOURCEDIR} and install files to"; 60791193Sdougb echo " the temproot environment"; 60891193Sdougb echo ''; 60991193Sdougb exit 1;} 61091193Sdougb ;; 61191193Sdougb *) 61291193Sdougb # Only set up files that are crucial to {build|install}world 61391193Sdougb { mkdir -p ${TEMPROOT}/etc && 614186678Sdougb cp -p ${SOURCEDIR}/etc/master.passwd ${TEMPROOT}/etc && 615186678Sdougb cp -p ${SOURCEDIR}/etc/group ${TEMPROOT}/etc;} || 61691193Sdougb { echo ''; 61791193Sdougb echo ' *** FATAL ERROR: Cannot copy files to the temproot environment'; 61891193Sdougb echo ''; 61991193Sdougb exit 1;} 62091193Sdougb ;; 62191193Sdougb esac 62252400Sbillf 62377323Sdougb # Doing the inventory and removing files that we don't want to compare only 62477323Sdougb # makes sense if we are not doing a rerun, since we have no way of knowing 62577323Sdougb # what happened to the files during previous incarnations. 62667949Sdougb case "${VERBOSE}" in 62767949Sdougb '') ;; 62867949Sdougb *) 62967949Sdougb echo '' 63067949Sdougb echo ' *** The following files exist only in the installed version of' 63167949Sdougb echo " ${DESTDIR}/etc. In the vast majority of cases these files" 63267949Sdougb echo ' are necessary parts of the system and should not be deleted.' 63367949Sdougb echo ' However because these files are not updated by this process you' 63467949Sdougb echo ' might want to verify their status before rebooting your system.' 63567949Sdougb echo '' 63697960Sdougb press_to_continue 637101348Sdougb diff -qr ${DESTDIR}/etc ${TEMPROOT}/etc | grep "^Only in ${DESTDIR}/etc" | ${PAGER} 63867949Sdougb echo '' 63997960Sdougb press_to_continue 64067949Sdougb ;; 64167949Sdougb esac 64267949Sdougb 64352534Sbillf # Avoid comparing the motd if the user specifies it in .mergemasterrc 644186678Sdougb # Compatibility shim to be removed in FreeBSD 9.x 64552534Sbillf case "${IGNORE_MOTD}" in 64652534Sbillf '') ;; 647186678Sdougb *) IGNORE_FILES="${IGNORE_FILES} /etc/motd" 648186678Sdougb echo '' 649186678Sdougb echo "*** You have the IGNORE_MOTD option set in your mergemaster rc file." 650186678Sdougb echo " This option is deprecated in favor of the IGNORE_FILES option." 651186678Sdougb echo " Please update your rc file accordingly." 652186678Sdougb echo '' 653186678Sdougb press_to_continue 65452534Sbillf ;; 65552534Sbillf esac 65652534Sbillf 657186678Sdougb # Avoid comparing the following user specified files 658186678Sdougb for file in ${IGNORE_FILES}; do 659186688Sdougb test -e ${TEMPROOT}/${file} && unlink ${TEMPROOT}/${file} 660186678Sdougb done 66152400Sbillf ;; # End of the "RERUN" test 66252400Sbillfesac 66352400Sbillf 664111901Sdougb# We really don't want to have to deal with files like login.conf.db, pwd.db, 665111901Sdougb# or spwd.db. Instead, we want to compare the text versions, and run *_mkdb. 666111901Sdougb# Prompt the user to do so below, as needed. 66777478Sdougb# 668111905Sdougbrm -f ${TEMPROOT}/etc/*.db ${TEMPROOT}/etc/passwd 66977478Sdougb 67094196Sdougb# We only need to compare things like freebsd.cf once 67196045Sdougbfind ${TEMPROOT}/usr/obj -type f -delete 2>/dev/null 67294196Sdougb 673158149Sgordon# Delete 0 length files to make the mtree database as small as possible. 674158149Sgordonfind ${TEMPROOT} -type f -size 0 -delete 2>/dev/null 675158149Sgordon 676158149Sgordon# Build the mtree database in a temporary location. 677186678SdougbMTREENEW=`mktemp -t mergemaster.mtree` 678158149Sgordoncase "${PRE_WORLD}" in 679189761Sdougb'') mtree -ci -p ${TEMPROOT} -k size,md5digest > ${MTREENEW} 2>/dev/null 680158149Sgordon ;; 681158149Sgordon*) # We don't want to mess with the mtree database on a pre-world run. 682158149Sgordon ;; 683158149Sgordonesac 684158149Sgordon 68552400Sbillf# Get ready to start comparing files 68652400Sbillf 68798084Sdougb# Check umask if not specified on the command line, 68898084Sdougb# and we are not doing an autorun 68952400Sbillf# 69098084Sdougbif [ -z "${NEW_UMASK}" -a -z "${AUTO_RUN}" ]; then 69198084Sdougb USER_UMASK=`umask` 69252400Sbillf case "${USER_UMASK}" in 69377335Sdougb 0022|022) ;; 69452400Sbillf *) 69552400Sbillf echo '' 69698084Sdougb echo " *** Your umask is currently set to ${USER_UMASK}. By default, this script" 69798084Sdougb echo " installs all files with the same user, group and modes that" 698186678Sdougb echo " they are created with by ${SOURCEDIR}/etc/Makefile, compared to" 69998084Sdougb echo " a umask of 022. This umask allows world read permission when" 70098084Sdougb echo " the file's default permissions have it." 70152400Sbillf echo '' 70298084Sdougb echo " No world permissions can sometimes cause problems. A umask of" 70398084Sdougb echo " 022 will restore the default behavior, but is not mandatory." 70498084Sdougb echo " /etc/master.passwd is a special case. Its file permissions" 70598084Sdougb echo " will be 600 (rw-------) if installed." 70697960Sdougb echo '' 70798084Sdougb echo -n "What umask should I use? [${USER_UMASK}] " 70898084Sdougb read NEW_UMASK 70998084Sdougb 71098084Sdougb NEW_UMASK="${NEW_UMASK:-$USER_UMASK}" 71152400Sbillf ;; 71252400Sbillf esac 71352400Sbillf echo '' 71498084Sdougbfi 71552400Sbillf 71698084SdougbCONFIRMED_UMASK=${NEW_UMASK:-0022} 71798084Sdougb 71852400Sbillf# 719114501Sdougb# Warn users who still have old rc files 720114501Sdougb# 721179315Sbzfor file in atm devfs diskless1 diskless2 network network6 pccard \ 722114523Sdougb serial syscons sysctl alpha amd64 i386 ia64 sparc64; do 723114501Sdougb if [ -f "${DESTDIR}/etc/rc.${file}" ]; then 724114501Sdougb OLD_RC_PRESENT=1 725114501Sdougb break 726114501Sdougb fi 727114501Sdougbdone 728114501Sdougb 729114501Sdougbcase "${OLD_RC_PRESENT}" in 730114501Sdougb1) 73152400Sbillf echo '' 732114501Sdougb echo " *** There are elements of the old rc system in ${DESTDIR}/etc/." 73367949Sdougb echo '' 734114501Sdougb echo ' While these scripts will not hurt anything, they are not' 735114501Sdougb echo ' functional on an up to date system, and can be removed.' 73667949Sdougb echo '' 737114501Sdougb 73852400Sbillf case "${AUTO_RUN}" in 73952400Sbillf '') 740114501Sdougb echo -n 'Move these files to /var/tmp/mergemaster/old_rc? [yes] ' 741114501Sdougb read MOVE_OLD_RC 74267859Sdougb 743114501Sdougb case "${MOVE_OLD_RC}" in 744114501Sdougb [nN]*) ;; 74552400Sbillf *) 746114501Sdougb mkdir -p /var/tmp/mergemaster/old_rc 747179315Sbz for file in atm devfs diskless1 diskless2 network network6 pccard \ 748114523Sdougb serial syscons sysctl alpha amd64 i386 ia64 sparc64; do 749114501Sdougb if [ -f "${DESTDIR}/etc/rc.${file}" ]; then 750114501Sdougb mv ${DESTDIR}/etc/rc.${file} /var/tmp/mergemaster/old_rc/ 751114501Sdougb fi 752114501Sdougb done 753114501Sdougb echo ' The files have been moved' 754114501Sdougb press_to_continue 75552400Sbillf ;; 75652400Sbillf esac 75752400Sbillf ;; 75852400Sbillf *) ;; 75952400Sbillf esac 760114501Sdougbesac 76152400Sbillf 76298084Sdougb# Use the umask/mode information to install the files 76352400Sbillf# Create directories as needed 76452400Sbillf# 765186678Sdougbinstall_error () { 766186678Sdougb echo "*** FATAL ERROR: Unable to install ${1} to ${2}" 767186678Sdougb echo '' 768186678Sdougb exit 1 769186678Sdougb} 770186678Sdougb 77178490Sdougbdo_install_and_rm () { 772114501Sdougb case "${PRESERVE_FILES}" in 773114501Sdougb [Yy][Ee][Ss]) 774114501Sdougb if [ -f "${3}/${2##*/}" ]; then 775114565Sdougb mkdir -p ${PRESERVE_FILES_DIR}/${2%/*} 776114565Sdougb cp ${3}/${2##*/} ${PRESERVE_FILES_DIR}/${2%/*} 777114501Sdougb fi 778114501Sdougb ;; 779114501Sdougb esac 780114501Sdougb 781186678Sdougb if [ ! -d "${3}/${2##*/}" ]; then 782186678Sdougb if install -m ${1} ${2} ${3}; then 783186678Sdougb unlink ${2} 784186678Sdougb else 785186678Sdougb install_error ${2} ${3} 786186678Sdougb fi 787186678Sdougb else 788186678Sdougb install_error ${2} ${3} 789186678Sdougb fi 79078490Sdougb} 79178490Sdougb 79298084Sdougb# 4095 = "obase=10;ibase=8;07777" | bc 79398084Sdougbfind_mode () { 79498084Sdougb local OCTAL 79598084Sdougb OCTAL=$(( ~$(echo "obase=10; ibase=8; ${CONFIRMED_UMASK}" | bc) & 4095 & 796124053Sdougb $(echo "obase=10; ibase=8; $(stat -f "%OMp%OLp" ${1})" | bc) )) 79798084Sdougb printf "%04o\n" ${OCTAL} 79898084Sdougb} 79998084Sdougb 80052400Sbillfmm_install () { 80152400Sbillf local INSTALL_DIR 80252400Sbillf INSTALL_DIR=${1#.} 80352400Sbillf INSTALL_DIR=${INSTALL_DIR%/*} 80467949Sdougb 80552400Sbillf case "${INSTALL_DIR}" in 80652400Sbillf '') 80752400Sbillf INSTALL_DIR=/ 80852400Sbillf ;; 80952400Sbillf esac 81052400Sbillf 81167949Sdougb if [ -n "${DESTDIR}${INSTALL_DIR}" -a ! -d "${DESTDIR}${INSTALL_DIR}" ]; then 81298084Sdougb DIR_MODE=`find_mode "${TEMPROOT}/${INSTALL_DIR}"` 81367949Sdougb install -d -o root -g wheel -m "${DIR_MODE}" "${DESTDIR}${INSTALL_DIR}" 81452400Sbillf fi 81552400Sbillf 81698084Sdougb FILE_MODE=`find_mode "${1}"` 81752400Sbillf 81852400Sbillf if [ ! -x "${1}" ]; then 81952400Sbillf case "${1#.}" in 82064625Sgshapiro /etc/mail/aliases) 82152400Sbillf NEED_NEWALIASES=yes 82252400Sbillf ;; 82352400Sbillf /etc/login.conf) 82452400Sbillf NEED_CAP_MKDB=yes 82552400Sbillf ;; 82652400Sbillf /etc/master.passwd) 82778490Sdougb do_install_and_rm 600 "${1}" "${DESTDIR}${INSTALL_DIR}" 82852400Sbillf NEED_PWD_MKDB=yes 82952400Sbillf DONT_INSTALL=yes 83052400Sbillf ;; 83152400Sbillf /.cshrc | /.profile) 83277335Sdougb case "${AUTO_INSTALL}" in 83377335Sdougb '') 83452400Sbillf case "${LINK_EXPLAINED}" in 83552400Sbillf '') 83667859Sdougb echo " *** Historically BSD derived systems have had a" 83767859Sdougb echo " hard link from /.cshrc and /.profile to" 83867859Sdougb echo " their namesakes in /root. Please indicate" 83967859Sdougb echo " your preference below for bringing your" 84067859Sdougb echo " installed files up to date." 84152400Sbillf echo '' 84252400Sbillf LINK_EXPLAINED=yes 84352400Sbillf ;; 84452400Sbillf esac 84552400Sbillf 84652400Sbillf echo " Use 'd' to delete the temporary ${COMPFILE}" 84767949Sdougb echo " Use 'l' to delete the existing ${DESTDIR}${COMPFILE#.} and create the link" 84852400Sbillf echo '' 84952400Sbillf echo " Default is to leave the temporary file to deal with by hand" 85052400Sbillf echo '' 85167859Sdougb echo -n " How should I handle ${COMPFILE}? [Leave it to install later] " 85267859Sdougb read HANDLE_LINK 85377335Sdougb ;; 85477335Sdougb *) # Part of AUTO_INSTALL 85577335Sdougb HANDLE_LINK=l 85677335Sdougb ;; 85777335Sdougb esac 85867859Sdougb 85952400Sbillf case "${HANDLE_LINK}" in 86052400Sbillf [dD]*) 86152400Sbillf rm "${COMPFILE}" 86252400Sbillf echo '' 86352400Sbillf echo " *** Deleting ${COMPFILE}" 86452400Sbillf ;; 86552400Sbillf [lL]*) 86652400Sbillf echo '' 86767949Sdougb rm -f "${DESTDIR}${COMPFILE#.}" 86867949Sdougb if ln "${DESTDIR}/root/${COMPFILE##*/}" "${DESTDIR}${COMPFILE#.}"; then 86967949Sdougb echo " *** Link from ${DESTDIR}${COMPFILE#.} to ${DESTDIR}/root/${COMPFILE##*/} installed successfully" 87052400Sbillf rm "${COMPFILE}" 87152400Sbillf else 87267949Sdougb echo " *** Error linking ${DESTDIR}${COMPFILE#.} to ${DESTDIR}/root/${COMPFILE##*/}, ${COMPFILE} will remain to install by hand" 87352400Sbillf fi 87452400Sbillf ;; 87552400Sbillf *) 87652400Sbillf echo " *** ${COMPFILE} will remain for your consideration" 87752400Sbillf ;; 87852400Sbillf esac 87952400Sbillf DONT_INSTALL=yes 88052400Sbillf ;; 88152400Sbillf esac 88252400Sbillf 88352400Sbillf case "${DONT_INSTALL}" in 88452400Sbillf '') 88578490Sdougb do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}" 88652400Sbillf ;; 88752400Sbillf *) 88852400Sbillf unset DONT_INSTALL 88952400Sbillf ;; 89052400Sbillf esac 89178490Sdougb else # File matched -x 89278490Sdougb do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}" 89352400Sbillf fi 89452400Sbillf return $? 89552400Sbillf} 89652400Sbillf 897174841Sdougbif [ ! -d "${TEMPROOT}" ]; then 898174841Sdougb echo "*** FATAL ERROR: The temproot directory (${TEMPROOT})" 899174841Sdougb echo ' has disappeared!' 900174841Sdougb echo '' 901174841Sdougb exit 1 902174841Sdougbfi 903174841Sdougb 90467949Sdougbecho '' 90567949Sdougbecho "*** Beginning comparison" 90667949Sdougbecho '' 90752400Sbillf 908124136Sdougb# Pre-world does not populate /etc/rc.d. 909124053Sdougb# It is very possible that a previous run would have deleted files in 910124053Sdougb# ${TEMPROOT}/etc/rc.d, thus creating a lot of false positives. 911124136Sdougbif [ -z "${PRE_WORLD}" -a -z "${RERUN}" ]; then 912124053Sdougb echo " *** Checking ${DESTDIR}/etc/rc.d for stale files" 913124053Sdougb echo '' 914124053Sdougb cd "${DESTDIR}/etc/rc.d" && 915124053Sdougb for file in *; do 916124053Sdougb if [ ! -e "${TEMPROOT}/etc/rc.d/${file}" ]; then 917124053Sdougb STALE_RC_FILES="${STALE_RC_FILES} ${file}" 918124053Sdougb fi 919124053Sdougb done 920124053Sdougb case "${STALE_RC_FILES}" in 921126718Sdougb ''|' *') 922124053Sdougb echo ' *** No stale files found' 923124053Sdougb ;; 924124053Sdougb *) 925124053Sdougb echo " *** The following files exist in ${DESTDIR}/etc/rc.d but not in" 926124053Sdougb echo " ${TEMPROOT}/etc/rc.d/:" 927124053Sdougb echo '' 928124053Sdougb echo "${STALE_RC_FILES}" 929124053Sdougb echo '' 930124053Sdougb echo ' The presence of stale files in this directory can cause the' 931124053Sdougb echo ' dreaded unpredictable results, and therefore it is highly' 932124053Sdougb echo ' recommended that you delete them.' 933124053Sdougb case "${AUTO_RUN}" in 934124053Sdougb '') 935124053Sdougb echo '' 936153604Sdougb echo -n ' *** Delete them now? [n] ' 937124053Sdougb read DELETE_STALE_RC_FILES 938124053Sdougb case "${DELETE_STALE_RC_FILES}" in 939153604Sdougb [yY]) 940124053Sdougb echo ' *** Deleting ... ' 941124053Sdougb rm ${STALE_RC_FILES} 942124053Sdougb echo ' done.' 943124053Sdougb ;; 944153604Sdougb *) 945153604Sdougb echo ' *** Files will not be deleted' 946153604Sdougb ;; 947124053Sdougb esac 948124053Sdougb sleep 2 949124053Sdougb ;; 950124053Sdougb esac 951124053Sdougb ;; 952124053Sdougb esac 953124053Sdougb echo '' 954124136Sdougbfi 955124053Sdougb 95667949Sdougbcd "${TEMPROOT}" 95767949Sdougb 95867949Sdougbif [ -r "${MM_PRE_COMPARE_SCRIPT}" ]; then 95967949Sdougb . "${MM_PRE_COMPARE_SCRIPT}" 96067949Sdougbfi 96167949Sdougb 96252400Sbillf# Using -size +0 avoids uselessly checking the empty log files created 963186678Sdougb# by ${SOURCEDIR}/etc/Makefile and the device entries in ./dev, but does 96467949Sdougb# check the scripts in ./dev, as we'd like (assuming no devfs of course). 96552400Sbillf# 96652400Sbillffor COMPFILE in `find . -type f -size +0`; do 96767949Sdougb 96867949Sdougb # First, check to see if the file exists in DESTDIR. If not, the 96967949Sdougb # diff_loop function knows how to handle it. 97067949Sdougb # 97167949Sdougb if [ ! -e "${DESTDIR}${COMPFILE#.}" ]; then 97277325Sdougb case "${AUTO_RUN}" in 97377325Sdougb '') 97477325Sdougb diff_loop 97577325Sdougb ;; 97677325Sdougb *) 97777325Sdougb case "${AUTO_INSTALL}" in 97877325Sdougb '') 97977325Sdougb # If this is an auto run, make it official 98077325Sdougb echo " *** ${COMPFILE} will remain for your consideration" 98177325Sdougb ;; 98277325Sdougb *) 98377325Sdougb diff_loop 98477325Sdougb ;; 98577325Sdougb esac 98677325Sdougb ;; 98777325Sdougb esac # Auto run test 98867949Sdougb continue 98967949Sdougb fi 99067949Sdougb 99152400Sbillf case "${STRICT}" in 99252400Sbillf '' | [Nn][Oo]) 99352400Sbillf # Compare CVS $Id's first so if the file hasn't been modified 99452400Sbillf # local changes will be ignored. 99552400Sbillf # If the files have the same $Id, delete the one in temproot so the 99652400Sbillf # user will have less to wade through if files are left to merge by hand. 99752400Sbillf # 99873651Sdougb CVSID1=`grep "[$]${CVS_ID_TAG}:" ${DESTDIR}${COMPFILE#.} 2>/dev/null` 99990564Sdougb CVSID2=`grep "[$]${CVS_ID_TAG}:" ${COMPFILE} 2>/dev/null` || CVSID2=none 100052400Sbillf 100167949Sdougb case "${CVSID2}" in 100273651Sdougb "${CVSID1}") 100367949Sdougb echo " *** Temp ${COMPFILE} and installed have the same CVS Id, deleting" 100467949Sdougb rm "${COMPFILE}" 100567949Sdougb ;; 100667949Sdougb esac 100752400Sbillf ;; 100852400Sbillf esac 100952400Sbillf 101052400Sbillf # If the file is still here either because the $Ids are different, the 101152400Sbillf # file doesn't have an $Id, or we're using STRICT mode; look at the diff. 101252400Sbillf # 101352400Sbillf if [ -f "${COMPFILE}" ]; then 101452400Sbillf 101552400Sbillf # Do an absolute diff first to see if the files are actually different. 101652400Sbillf # If they're not different, delete the one in temproot. 101752400Sbillf # 1018110377Sdougb if diff -q ${DIFF_OPTIONS} "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" > \ 1019110377Sdougb /dev/null 2>&1; then 102052400Sbillf echo " *** Temp ${COMPFILE} and installed are the same, deleting" 102152400Sbillf rm "${COMPFILE}" 102252400Sbillf else 102377323Sdougb # Ok, the files are different, so show the user where they differ. 102477323Sdougb # Use user's choice of diff methods; and user's pager if they have one. 102577323Sdougb # Use more if not. 102667859Sdougb # Use unified diffs by default. Context diffs give me a headache. :) 102752400Sbillf # 1028189992Sdougb # If the user chose the -F option, test for that before proceeding 1029189992Sdougb # 1030189992Sdougb if [ -n "$FREEBSD_ID" ]; then 1031189992Sdougb if diff -q -I'[$]FreeBSD:.*$' "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" > \ 1032189992Sdougb /dev/null 2>&1; then 1033189992Sdougb if mm_install "${COMPFILE}"; then 1034189992Sdougb echo "*** Updated revision control Id for ${DESTDIR}${COMPFILE#.}" 1035189992Sdougb else 1036189992Sdougb echo "*** Problem installing ${COMPFILE}, it will remain to merge by hand later" 1037189992Sdougb fi 1038189992Sdougb continue 1039189992Sdougb fi 1040189992Sdougb fi 104152400Sbillf case "${AUTO_RUN}" in 104252400Sbillf '') 104358910Salfred # prompt user to install/delete/merge changes 104458910Salfred diff_loop 104552400Sbillf ;; 104652400Sbillf *) 104752400Sbillf # If this is an auto run, make it official 104852400Sbillf echo " *** ${COMPFILE} will remain for your consideration" 104952400Sbillf ;; 105052400Sbillf esac # Auto run test 105152400Sbillf fi # Yes, the files are different 105252400Sbillf fi # Yes, the file still remains to be checked 1053189763Sdougbdone # This is for the for way up there at the beginning of the comparison 105452400Sbillf 105552534Sbillfecho '' 105652400Sbillfecho "*** Comparison complete" 1057158149Sgordon 1058189761Sdougbif [ -f "${MTREENEW}" ]; then 1059158149Sgordon echo "*** Saving mtree database for future upgrades" 1060189761Sdougb test -e "${DESTDIR}${MTREEFILE}" && unlink ${DESTDIR}${MTREEFILE} 1061189761Sdougb mv ${MTREENEW} ${DESTDIR}${MTREEFILE} 1062158149Sgordonfi 1063158149Sgordon 106452400Sbillfecho '' 106552400Sbillf 106652400SbillfTEST_FOR_FILES=`find ${TEMPROOT} -type f -size +0 2>/dev/null` 106752400Sbillfif [ -n "${TEST_FOR_FILES}" ]; then 106852400Sbillf echo "*** Files that remain for you to merge by hand:" 106952400Sbillf find "${TEMPROOT}" -type f -size +0 107077335Sdougb echo '' 107152400Sbillffi 107252400Sbillf 107352400Sbillfcase "${AUTO_RUN}" in 107452400Sbillf'') 107567859Sdougb echo -n "Do you wish to delete what is left of ${TEMPROOT}? [no] " 107667859Sdougb read DEL_TEMPROOT 107767859Sdougb 107852400Sbillf case "${DEL_TEMPROOT}" in 107952400Sbillf [yY]*) 108099152Sdougb if delete_temproot; then 108152400Sbillf echo " *** ${TEMPROOT} has been deleted" 108252400Sbillf else 108352400Sbillf echo " *** Unable to delete ${TEMPROOT}" 108452400Sbillf fi 108552400Sbillf ;; 108652400Sbillf *) 108752400Sbillf echo " *** ${TEMPROOT} will remain" 108852400Sbillf ;; 108952400Sbillf esac 109052400Sbillf ;; 109152400Sbillf*) ;; 109252400Sbillfesac 109352400Sbillf 109468153Sdougbcase "${AUTO_INSTALLED_FILES}" in 109568153Sdougb'') ;; 109668153Sdougb*) 109773651Sdougb case "${AUTO_RUN}" in 109873651Sdougb '') 109973651Sdougb ( 110073651Sdougb echo '' 110177323Sdougb echo '*** You chose the automatic install option for files that did not' 110277323Sdougb echo ' exist on your system. The following were installed for you:' 110373651Sdougb echo "${AUTO_INSTALLED_FILES}" 110473651Sdougb ) | ${PAGER} 110573651Sdougb ;; 110673651Sdougb *) 110768153Sdougb echo '' 110877323Sdougb echo '*** You chose the automatic install option for files that did not' 110977323Sdougb echo ' exist on your system. The following were installed for you:' 111068153Sdougb echo "${AUTO_INSTALLED_FILES}" 111173651Sdougb ;; 111273651Sdougb esac 111368153Sdougb ;; 111468153Sdougbesac 111568153Sdougb 1116158149Sgordoncase "${AUTO_UPGRADED_FILES}" in 1117158149Sgordon'') ;; 1118158149Sgordon*) 1119158149Sgordon case "${AUTO_RUN}" in 1120158149Sgordon '') 1121158149Sgordon ( 1122158149Sgordon echo '' 1123158149Sgordon echo '*** You chose the automatic upgrade option for files that you did' 1124158149Sgordon echo ' not alter on your system. The following were upgraded for you:' 1125158149Sgordon echo "${AUTO_UPGRADED_FILES}" 1126158149Sgordon ) | ${PAGER} 1127158149Sgordon ;; 1128158149Sgordon *) 1129158149Sgordon echo '' 1130158149Sgordon echo '*** You chose the automatic upgrade option for files that you did' 1131158149Sgordon echo ' not alter on your system. The following were upgraded for you:' 1132158149Sgordon echo "${AUTO_UPGRADED_FILES}" 1133158149Sgordon ;; 1134158149Sgordon esac 1135158149Sgordon ;; 1136158149Sgordonesac 1137158149Sgordon 113873651Sdougbrun_it_now () { 113973651Sdougb case "${AUTO_RUN}" in 114073651Sdougb '') 114173651Sdougb unset YES_OR_NO 114273651Sdougb echo '' 114377335Sdougb echo -n ' Would you like to run it now? y or n [n] ' 114473651Sdougb read YES_OR_NO 114573651Sdougb 114673651Sdougb case "${YES_OR_NO}" in 114773651Sdougb y) 114877335Sdougb echo " Running ${1}" 114977335Sdougb echo '' 115073651Sdougb eval "${1}" 115173651Sdougb ;; 115277335Sdougb ''|n) 115377335Sdougb echo '' 115477335Sdougb echo " *** Cancelled" 115577335Sdougb echo '' 115677335Sdougb echo " Make sure to run ${1} yourself" 115777335Sdougb ;; 115873651Sdougb *) 115977335Sdougb echo '' 116077335Sdougb echo " *** Sorry, I do not understand your answer (${YES_OR_NO})" 116177335Sdougb echo '' 116277335Sdougb echo " Make sure to run ${1} yourself" 116373651Sdougb esac 116473651Sdougb ;; 116573651Sdougb *) ;; 116673651Sdougb esac 116773651Sdougb} 116873651Sdougb 116952400Sbillfcase "${NEED_NEWALIASES}" in 117052400Sbillf'') ;; 117152400Sbillf*) 117252400Sbillf echo '' 117377335Sdougb if [ -n "${DESTDIR}" ]; then 117477335Sdougb echo "*** You installed a new aliases file into ${DESTDIR}/etc/mail, but" 117577335Sdougb echo " the newaliases command is limited to the directories configured" 117677335Sdougb echo " in sendmail.cf. Make sure to create your aliases database by" 117777335Sdougb echo " hand when your sendmail configuration is done." 117877335Sdougb else 117977335Sdougb echo "*** You installed a new aliases file, so make sure that you run" 118077335Sdougb echo " '/usr/bin/newaliases' to rebuild your aliases database" 118177335Sdougb run_it_now '/usr/bin/newaliases' 118277335Sdougb fi 118352400Sbillf ;; 118452400Sbillfesac 118552400Sbillf 118652400Sbillfcase "${NEED_CAP_MKDB}" in 118752400Sbillf'') ;; 118852400Sbillf*) 118952400Sbillf echo '' 119052400Sbillf echo "*** You installed a login.conf file, so make sure that you run" 119177335Sdougb echo " '/usr/bin/cap_mkdb ${DESTDIR}/etc/login.conf'" 119277335Sdougb echo " to rebuild your login.conf database" 119377335Sdougb run_it_now "/usr/bin/cap_mkdb ${DESTDIR}/etc/login.conf" 119452400Sbillf ;; 119552400Sbillfesac 119652400Sbillf 119752400Sbillfcase "${NEED_PWD_MKDB}" in 119852400Sbillf'') ;; 119952400Sbillf*) 120052400Sbillf echo '' 120152400Sbillf echo "*** You installed a new master.passwd file, so make sure that you run" 120277335Sdougb if [ -n "${DESTDIR}" ]; then 120377335Sdougb echo " '/usr/sbin/pwd_mkdb -d ${DESTDIR}/etc -p ${DESTDIR}/etc/master.passwd'" 120477335Sdougb echo " to rebuild your password files" 120577335Sdougb run_it_now "/usr/sbin/pwd_mkdb -d ${DESTDIR}/etc -p ${DESTDIR}/etc/master.passwd" 120677335Sdougb else 120777335Sdougb echo " '/usr/sbin/pwd_mkdb -p /etc/master.passwd'" 120877335Sdougb echo " to rebuild your password files" 120977335Sdougb run_it_now '/usr/sbin/pwd_mkdb -p /etc/master.passwd' 121077335Sdougb fi 121152400Sbillf ;; 121252400Sbillfesac 121352400Sbillf 121452400Sbillfecho '' 121552400Sbillf 121667949Sdougbif [ -r "${MM_EXIT_SCRIPT}" ]; then 121767949Sdougb . "${MM_EXIT_SCRIPT}" 121867949Sdougbfi 121967949Sdougb 122091193Sdougbcase "${COMP_CONFS}" in 122191193Sdougb'') ;; 122291193Sdougb*) 122391193Sdougb . ${DESTDIR}/etc/defaults/rc.conf 122491193Sdougb 122591193Sdougb (echo '' 122691193Sdougb echo "*** Comparing conf files: ${rc_conf_files}" 122791193Sdougb 122891193Sdougb for CONF_FILE in ${rc_conf_files}; do 122991193Sdougb if [ -r "${DESTDIR}${CONF_FILE}" ]; then 123091193Sdougb echo '' 123191193Sdougb echo "*** From ${DESTDIR}${CONF_FILE}" 123291193Sdougb echo "*** From ${DESTDIR}/etc/defaults/rc.conf" 123391193Sdougb 123491193Sdougb for RC_CONF_VAR in `grep -i ^[a-z] ${DESTDIR}${CONF_FILE} | 123591193Sdougb cut -d '=' -f 1`; do 123691193Sdougb echo '' 123791223Sdougb grep -w ^${RC_CONF_VAR} ${DESTDIR}${CONF_FILE} 123891223Sdougb grep -w ^${RC_CONF_VAR} ${DESTDIR}/etc/defaults/rc.conf || 123991193Sdougb echo ' * No default variable with this name' 124091193Sdougb done 124191193Sdougb fi 124291193Sdougb done) | ${PAGER} 124391193Sdougb echo '' 124491193Sdougb ;; 124591193Sdougbesac 124691193Sdougb 124791193Sdougbcase "${PRE_WORLD}" in 124891193Sdougb'') ;; 124991193Sdougb*) 1250186678Sdougb MAKE_CONF="${SOURCEDIR}/share/examples/etc/make.conf" 125191193Sdougb 125291193Sdougb (echo '' 125391193Sdougb echo '*** Comparing make variables' 125491193Sdougb echo '' 125591193Sdougb echo "*** From ${DESTDIR}/etc/make.conf" 125691193Sdougb echo "*** From ${MAKE_CONF}" 125791193Sdougb 1258101348Sdougb for MAKE_VAR in `grep -i ^[a-z] ${DESTDIR}/etc/make.conf | cut -d '=' -f 1`; do 125991193Sdougb echo '' 126091223Sdougb grep -w ^${MAKE_VAR} ${DESTDIR}/etc/make.conf 126191223Sdougb grep -w ^#${MAKE_VAR} ${MAKE_CONF} || 126291193Sdougb echo ' * No example variable with this name' 126391193Sdougb done) | ${PAGER} 126491193Sdougb ;; 126591193Sdougbesac 126691193Sdougb 126752400Sbillfexit 0 126867850Sdougb 1269