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 updating
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=`TMPDIR=/var/tmp mktemp -d -t 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 -DDB_FROM_SRC"
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 ${MM_MAKE} DESTDIR=${TEMPROOT} distrib-dirs &&
118 ${MM_MAKE} _obj SUBDIR_OVERRIDE=etc &&
119 ${MM_MAKE} everything SUBDIR_OVERRIDE=etc &&
120 ${MM_MAKE} DESTDIR=${TEMPROOT} distribution;} ||
122 echo " *** FATAL ERROR: Cannot 'cd' to ${SOURCEDIR} and install files to";
123 echo " the temproot environment";
127 # We really don't want to have to deal with files like login.conf.db, pwd.db,
128 # or spwd.db. Instead, we want to compare the text versions, and run *_mkdb.
129 # Prompt the user to do so below, as needed.
131 rm -f ${TEMPROOT}/etc/*.db ${TEMPROOT}/etc/passwd
133 # We only need to compare things like freebsd.cf once
134 find ${TEMPROOT}/usr/obj -type f -delete 2>/dev/null
136 # Delete stuff we do not need to keep the mtree database small,
137 # and to make the actual comparison faster.
138 find ${TEMPROOT}/usr -type l -delete 2>/dev/null
139 find ${TEMPROOT} -type f -size 0 -delete 2>/dev/null
140 find -d ${TEMPROOT} -type d -empty -delete 2>/dev/null
142 # Build the mtree database in a temporary location.
143 MTREENEW=`mktemp -t mergemaster.mtree`
144 mtree -nci -p ${TEMPROOT} -k size,md5digest > ${MTREENEW} 2>/dev/null
146 if [ -s "${MTREENEW}" ]; then
147 echo "*** Saving mtree database for future upgrades"
148 test -e "${DESTDIR}${MTREEFILE}" && unlink ${DESTDIR}${MTREEFILE}
149 mv ${MTREENEW} ${DESTDIR}${MTREEFILE}