mm-mtree.sh revision 254951
1196434Sdougb#!/bin/sh 2196434Sdougb 3196434Sdougb# mergemaster mtree database generator 4196434Sdougb 5196434Sdougb# This script is intended to be used as part of the release building 6196434Sdougb# process to generate the /var/db/mergemaster.mtree file relevant to 7196434Sdougb# the source tree used to create the release so that users can make 8196434Sdougb# use of mergemaster's -U option to update their files after csup'ing 9196434Sdougb# to -stable. 10196434Sdougb 11196434Sdougb# Copyright 2009 Douglas Barton 12196434Sdougb# dougb@FreeBSD.org 13196434Sdougb 14196434Sdougb# $FreeBSD: head/release/scripts/mm-mtree.sh 254951 2013-08-27 04:42:42Z will $ 15196434Sdougb 16196434SdougbPATH=/bin:/usr/bin:/usr/sbin 17196434Sdougb 18196434Sdougbdisplay_usage () { 19196434Sdougb VERSION_NUMBER=`grep "[$]FreeBSD:" $0 | cut -d ' ' -f 4` 20196434Sdougb echo "${0##*/} version ${VERSION_NUMBER}" 21196434Sdougb echo "Usage: ${0##*/} [-m /path] [-t /path] [-A arch] [-F <make args>] [-D /path]" 22196434Sdougb echo "Options:" 23196434Sdougb echo " -m /path/directory Specify location of source to do the make in" 24196434Sdougb echo " -t /path/directory Specify temp root directory" 25196434Sdougb echo " -A architecture Alternative architecture name to pass to make" 26196434Sdougb echo " -F <arguments for make> Specify what to put on the make command line" 27196434Sdougb echo ' -D /path/directory Specify the destination directory to install files to' 28196434Sdougb echo '' 29196434Sdougb} 30196434Sdougb 31196434Sdougb# Set the default path for the temporary root environment 32196434Sdougb# 33196434SdougbTEMPROOT='/var/tmp/temproot' 34196434Sdougb 35196434Sdougb# Assign the location of the mtree database 36196434Sdougb# 37196434SdougbMTREEDB=${MTREEDB:-/var/db} 38196434SdougbMTREEFILE="${MTREEDB}/mergemaster.mtree" 39196434Sdougb 40196434Sdougb# Check the command line options 41196434Sdougb# 42196434Sdougbwhile getopts "m:t:A:F:D:h" COMMAND_LINE_ARGUMENT ; do 43196434Sdougb case "${COMMAND_LINE_ARGUMENT}" in 44196434Sdougb m) 45196434Sdougb SOURCEDIR=${OPTARG} 46196434Sdougb ;; 47196434Sdougb t) 48196434Sdougb TEMPROOT=${OPTARG} 49196434Sdougb ;; 50196434Sdougb A) 51196434Sdougb ARCHSTRING='TARGET_ARCH='${OPTARG} 52196434Sdougb ;; 53196434Sdougb F) 54196434Sdougb MM_MAKE_ARGS="${OPTARG}" 55196434Sdougb ;; 56196434Sdougb D) 57196434Sdougb DESTDIR=${OPTARG} 58196434Sdougb ;; 59196434Sdougb h) 60196434Sdougb display_usage 61196434Sdougb exit 0 62196434Sdougb ;; 63196434Sdougb *) 64196434Sdougb echo '' 65196434Sdougb display_usage 66196434Sdougb exit 1 67196434Sdougb ;; 68196434Sdougb esac 69196434Sdougbdone 70196434Sdougb 71196434Sdougb# Assign the source directory 72196434Sdougb# 73196434SdougbSOURCEDIR=${SOURCEDIR:-/usr/src} 74196434Sdougbif [ ! -f ${SOURCEDIR}/Makefile.inc1 -a \ 75196434Sdougb -f ${SOURCEDIR}/../Makefile.inc1 ]; then 76196434Sdougb echo " *** The source directory you specified (${SOURCEDIR})" 77196434Sdougb echo " will be reset to ${SOURCEDIR}/.." 78196434Sdougb echo '' 79196434Sdougb sleep 3 80196434Sdougb SOURCEDIR=${SOURCEDIR}/.. 81196434Sdougbfi 82196434Sdougb 83196434Sdougb# Setup make to use system files from SOURCEDIR 84254951Swillobjp=${MAKEOBJDIRPREFIX} 85254951Swill[ -z "${objp}" ] && objp=/usr/obj 86254951Swilllegacydir=${objp}${SOURCEDIR}/tmp/legacy 87254951Swilllegacypath=${legacydir}/usr/sbin:${legacydir}/usr/bin:${legacydir}/bin 88254951SwillMM_MAKE_ARGS="${MM_MAKE_ARGS} PATH=${legacypath}:${PATH}" 89196434SdougbMM_MAKE="make ${ARCHSTRING} ${MM_MAKE_ARGS} -m ${SOURCEDIR}/share/mk" 90196434Sdougb 91196434Sdougbdelete_temproot () { 92196434Sdougb rm -rf "${TEMPROOT}" 2>/dev/null 93196434Sdougb chflags -R 0 "${TEMPROOT}" 2>/dev/null 94196434Sdougb rm -rf "${TEMPROOT}" || exit 1 95196434Sdougb} 96196434Sdougb 97196434Sdougb[ -d "${TEMPROOT}" ] && delete_temproot 98196434Sdougb 99196434Sdougbecho "*** Creating the temporary root environment in ${TEMPROOT}" 100196434Sdougb 101196434Sdougbif mkdir -p "${TEMPROOT}"; then 102196434Sdougb echo " *** ${TEMPROOT} ready for use" 103196434Sdougbfi 104196434Sdougb 105196434Sdougbif [ ! -d "${TEMPROOT}" ]; then 106196434Sdougb echo '' 107196434Sdougb echo " *** FATAL ERROR: Cannot create ${TEMPROOT}" 108196434Sdougb echo '' 109196434Sdougb exit 1 110196434Sdougbfi 111196434Sdougb 112196434Sdougbecho " *** Creating and populating directory structure in ${TEMPROOT}" 113196434Sdougbecho '' 114196434Sdougb 115196434Sdougb{ cd ${SOURCEDIR} || { echo "*** Cannot cd to ${SOURCEDIR}" ; exit 1;} 116196434Sdougb case "${DESTDIR}" in 117196434Sdougb '') ;; 118196434Sdougb *) 119196434Sdougb ${MM_MAKE} DESTDIR=${DESTDIR} distrib-dirs 120196434Sdougb ;; 121196434Sdougb esac 122196434Sdougb od=${TEMPROOT}/usr/obj 123196434Sdougb ${MM_MAKE} DESTDIR=${TEMPROOT} distrib-dirs && 124196434Sdougb MAKEOBJDIRPREFIX=$od ${MM_MAKE} _obj SUBDIR_OVERRIDE=etc && 125196434Sdougb MAKEOBJDIRPREFIX=$od ${MM_MAKE} everything SUBDIR_OVERRIDE=etc && 126196434Sdougb MAKEOBJDIRPREFIX=$od ${MM_MAKE} DESTDIR=${TEMPROOT} distribution;} || 127196434Sdougb { echo ''; 128196434Sdougb echo " *** FATAL ERROR: Cannot 'cd' to ${SOURCEDIR} and install files to"; 129196434Sdougb echo " the temproot environment"; 130196434Sdougb echo ''; 131196434Sdougb exit 1;} 132196434Sdougb 133196434Sdougb# We really don't want to have to deal with files like login.conf.db, pwd.db, 134196434Sdougb# or spwd.db. Instead, we want to compare the text versions, and run *_mkdb. 135196434Sdougb# Prompt the user to do so below, as needed. 136196434Sdougb# 137196434Sdougbrm -f ${TEMPROOT}/etc/*.db ${TEMPROOT}/etc/passwd 138196434Sdougb 139196434Sdougb# We only need to compare things like freebsd.cf once 140196434Sdougbfind ${TEMPROOT}/usr/obj -type f -delete 2>/dev/null 141196434Sdougb 142196434Sdougb# Delete stuff we do not need to keep the mtree database small, 143196434Sdougb# and to make the actual comparison faster. 144196434Sdougbfind ${TEMPROOT}/usr -type l -delete 2>/dev/null 145196434Sdougbfind ${TEMPROOT} -type f -size 0 -delete 2>/dev/null 146196434Sdougbfind -d ${TEMPROOT} -type d -empty -delete 2>/dev/null 147196434Sdougb 148196434Sdougb# Build the mtree database in a temporary location. 149196434SdougbMTREENEW=`mktemp -t mergemaster.mtree` 150196434Sdougbmtree -ci -p ${TEMPROOT} -k size,md5digest > ${MTREENEW} 2>/dev/null 151196434Sdougb 152196434Sdougbif [ -s "${MTREENEW}" ]; then 153196434Sdougb echo "*** Saving mtree database for future upgrades" 154196434Sdougb test -e "${DESTDIR}${MTREEFILE}" && unlink ${DESTDIR}${MTREEFILE} 155196434Sdougb mv ${MTREENEW} ${DESTDIR}${MTREEFILE} 156196434Sdougbfi 157196434Sdougb 158196434Sdougbdelete_temproot 159196434Sdougb 160196434Sdougbexit 0 161