3 # mergemaster mtree database generator
5 # This script is intended to be used as part of the release building
6 # process to generate the /var/db/mergemaster.mtree file relevant to
7 # the source tree used to create the release so that users can make
8 # use of mergemaster's -U option to update their files after csup'ing
11 # Copyright 2009 Douglas Barton
16 PATH=/bin:/usr/bin:/usr/sbin
19 VERSION_NUMBER=`grep "[$]FreeBSD:" $0 | cut -d ' ' -f 4`
20 echo "${0##*/} version ${VERSION_NUMBER}"
21 echo "Usage: ${0##*/} [-m /path] [-t /path] [-A arch] [-F <make args>] [-D /path]"
23 echo " -m /path/directory Specify location of source to do the make in"
24 echo " -t /path/directory Specify temp root directory"
25 echo " -A architecture Alternative architecture name to pass to make"
26 echo " -F <arguments for make> Specify what to put on the make command line"
27 echo ' -D /path/directory Specify the destination directory to install files to'
31 # Set the default path for the temporary root environment
33 TEMPROOT='/var/tmp/temproot'
35 # Assign the location of the mtree database
37 MTREEDB=${MTREEDB:-/var/db}
38 MTREEFILE="${MTREEDB}/mergemaster.mtree"
40 # Check the command line options
42 while getopts "m:t:A:F:D:h" COMMAND_LINE_ARGUMENT ; do
43 case "${COMMAND_LINE_ARGUMENT}" in
51 ARCHSTRING='TARGET_ARCH='${OPTARG}
54 MM_MAKE_ARGS="${OPTARG}"
71 # Assign the source directory
73 SOURCEDIR=${SOURCEDIR:-/usr/src}
74 if [ ! -f ${SOURCEDIR}/Makefile.inc1 -a \
75 -f ${SOURCEDIR}/../Makefile.inc1 ]; then
76 echo " *** The source directory you specified (${SOURCEDIR})"
77 echo " will be reset to ${SOURCEDIR}/.."
80 SOURCEDIR=${SOURCEDIR}/..
83 # Setup make to use system files from SOURCEDIR
84 MM_MAKE="make ${ARCHSTRING} ${MM_MAKE_ARGS} -m ${SOURCEDIR}/share/mk"
87 rm -rf "${TEMPROOT}" 2>/dev/null
88 chflags -R 0 "${TEMPROOT}" 2>/dev/null
89 rm -rf "${TEMPROOT}" || exit 1
92 [ -d "${TEMPROOT}" ] && delete_temproot
94 echo "*** Creating the temporary root environment in ${TEMPROOT}"
96 if mkdir -p "${TEMPROOT}"; then
97 echo " *** ${TEMPROOT} ready for use"
100 if [ ! -d "${TEMPROOT}" ]; then
102 echo " *** FATAL ERROR: Cannot create ${TEMPROOT}"
107 echo " *** Creating and populating directory structure in ${TEMPROOT}"
110 { cd ${SOURCEDIR} || { echo "*** Cannot cd to ${SOURCEDIR}" ; exit 1;}
114 ${MM_MAKE} DESTDIR=${DESTDIR} distrib-dirs
117 od=${TEMPROOT}/usr/obj
118 ${MM_MAKE} DESTDIR=${TEMPROOT} distrib-dirs &&
119 MAKEOBJDIRPREFIX=$od ${MM_MAKE} _obj SUBDIR_OVERRIDE=etc &&
120 MAKEOBJDIRPREFIX=$od ${MM_MAKE} everything SUBDIR_OVERRIDE=etc &&
121 MAKEOBJDIRPREFIX=$od ${MM_MAKE} DESTDIR=${TEMPROOT} distribution;} ||
123 echo " *** FATAL ERROR: Cannot 'cd' to ${SOURCEDIR} and install files to";
124 echo " the temproot environment";
128 # We really don't want to have to deal with files like login.conf.db, pwd.db,
129 # or spwd.db. Instead, we want to compare the text versions, and run *_mkdb.
130 # Prompt the user to do so below, as needed.
132 rm -f ${TEMPROOT}/etc/*.db ${TEMPROOT}/etc/passwd
134 # We only need to compare things like freebsd.cf once
135 find ${TEMPROOT}/usr/obj -type f -delete 2>/dev/null
137 # Delete stuff we do not need to keep the mtree database small,
138 # and to make the actual comparison faster.
139 find ${TEMPROOT}/usr -type l -delete 2>/dev/null
140 find ${TEMPROOT} -type f -size 0 -delete 2>/dev/null
141 find -d ${TEMPROOT} -type d -empty -delete 2>/dev/null
143 # Build the mtree database in a temporary location.
144 MTREENEW=`mktemp -t mergemaster.mtree`
145 mtree -ci -p ${TEMPROOT} -k size,md5digest > ${MTREENEW} 2>/dev/null
147 if [ -s "${MTREENEW}" ]; then
148 echo "*** Saving mtree database for future upgrades"
149 test -e "${DESTDIR}${MTREEFILE}" && unlink ${DESTDIR}${MTREEFILE}
150 mv ${MTREENEW} ${DESTDIR}${MTREEFILE}