/release/scripts/mm-mtree.sh

https://bitbucket.org/freebsd/freebsd-head/ · Shell · 155 lines · 103 code · 25 blank · 27 comment · 12 complexity · 96cf7e599fd4c09d71f07857fa42ca8c MD5 · raw file

  1. #!/bin/sh
  2. # mergemaster mtree database generator
  3. # This script is intended to be used as part of the release building
  4. # process to generate the /var/db/mergemaster.mtree file relevant to
  5. # the source tree used to create the release so that users can make
  6. # use of mergemaster's -U option to update their files after csup'ing
  7. # to -stable.
  8. # Copyright 2009 Douglas Barton
  9. # dougb@FreeBSD.org
  10. # $FreeBSD$
  11. PATH=/bin:/usr/bin:/usr/sbin
  12. display_usage () {
  13. VERSION_NUMBER=`grep "[$]FreeBSD:" $0 | cut -d ' ' -f 4`
  14. echo "${0##*/} version ${VERSION_NUMBER}"
  15. echo "Usage: ${0##*/} [-m /path] [-t /path] [-A arch] [-F <make args>] [-D /path]"
  16. echo "Options:"
  17. echo " -m /path/directory Specify location of source to do the make in"
  18. echo " -t /path/directory Specify temp root directory"
  19. echo " -A architecture Alternative architecture name to pass to make"
  20. echo " -F <arguments for make> Specify what to put on the make command line"
  21. echo ' -D /path/directory Specify the destination directory to install files to'
  22. echo ''
  23. }
  24. # Set the default path for the temporary root environment
  25. #
  26. TEMPROOT='/var/tmp/temproot'
  27. # Assign the location of the mtree database
  28. #
  29. MTREEDB=${MTREEDB:-/var/db}
  30. MTREEFILE="${MTREEDB}/mergemaster.mtree"
  31. # Check the command line options
  32. #
  33. while getopts "m:t:A:F:D:h" COMMAND_LINE_ARGUMENT ; do
  34. case "${COMMAND_LINE_ARGUMENT}" in
  35. m)
  36. SOURCEDIR=${OPTARG}
  37. ;;
  38. t)
  39. TEMPROOT=${OPTARG}
  40. ;;
  41. A)
  42. ARCHSTRING='TARGET_ARCH='${OPTARG}
  43. ;;
  44. F)
  45. MM_MAKE_ARGS="${OPTARG}"
  46. ;;
  47. D)
  48. DESTDIR=${OPTARG}
  49. ;;
  50. h)
  51. display_usage
  52. exit 0
  53. ;;
  54. *)
  55. echo ''
  56. display_usage
  57. exit 1
  58. ;;
  59. esac
  60. done
  61. # Assign the source directory
  62. #
  63. SOURCEDIR=${SOURCEDIR:-/usr/src}
  64. if [ ! -f ${SOURCEDIR}/Makefile.inc1 -a \
  65. -f ${SOURCEDIR}/../Makefile.inc1 ]; then
  66. echo " *** The source directory you specified (${SOURCEDIR})"
  67. echo " will be reset to ${SOURCEDIR}/.."
  68. echo ''
  69. sleep 3
  70. SOURCEDIR=${SOURCEDIR}/..
  71. fi
  72. # Setup make to use system files from SOURCEDIR
  73. MM_MAKE="make ${ARCHSTRING} ${MM_MAKE_ARGS} -m ${SOURCEDIR}/share/mk"
  74. delete_temproot () {
  75. rm -rf "${TEMPROOT}" 2>/dev/null
  76. chflags -R 0 "${TEMPROOT}" 2>/dev/null
  77. rm -rf "${TEMPROOT}" || exit 1
  78. }
  79. [ -d "${TEMPROOT}" ] && delete_temproot
  80. echo "*** Creating the temporary root environment in ${TEMPROOT}"
  81. if mkdir -p "${TEMPROOT}"; then
  82. echo " *** ${TEMPROOT} ready for use"
  83. fi
  84. if [ ! -d "${TEMPROOT}" ]; then
  85. echo ''
  86. echo " *** FATAL ERROR: Cannot create ${TEMPROOT}"
  87. echo ''
  88. exit 1
  89. fi
  90. echo " *** Creating and populating directory structure in ${TEMPROOT}"
  91. echo ''
  92. { cd ${SOURCEDIR} || { echo "*** Cannot cd to ${SOURCEDIR}" ; exit 1;}
  93. case "${DESTDIR}" in
  94. '') ;;
  95. *)
  96. ${MM_MAKE} DESTDIR=${DESTDIR} distrib-dirs
  97. ;;
  98. esac
  99. od=${TEMPROOT}/usr/obj
  100. ${MM_MAKE} DESTDIR=${TEMPROOT} distrib-dirs &&
  101. MAKEOBJDIRPREFIX=$od ${MM_MAKE} _obj SUBDIR_OVERRIDE=etc &&
  102. MAKEOBJDIRPREFIX=$od ${MM_MAKE} everything SUBDIR_OVERRIDE=etc &&
  103. MAKEOBJDIRPREFIX=$od ${MM_MAKE} DESTDIR=${TEMPROOT} distribution;} ||
  104. { echo '';
  105. echo " *** FATAL ERROR: Cannot 'cd' to ${SOURCEDIR} and install files to";
  106. echo " the temproot environment";
  107. echo '';
  108. exit 1;}
  109. # We really don't want to have to deal with files like login.conf.db, pwd.db,
  110. # or spwd.db. Instead, we want to compare the text versions, and run *_mkdb.
  111. # Prompt the user to do so below, as needed.
  112. #
  113. rm -f ${TEMPROOT}/etc/*.db ${TEMPROOT}/etc/passwd
  114. # We only need to compare things like freebsd.cf once
  115. find ${TEMPROOT}/usr/obj -type f -delete 2>/dev/null
  116. # Delete stuff we do not need to keep the mtree database small,
  117. # and to make the actual comparison faster.
  118. find ${TEMPROOT}/usr -type l -delete 2>/dev/null
  119. find ${TEMPROOT} -type f -size 0 -delete 2>/dev/null
  120. find -d ${TEMPROOT} -type d -empty -delete 2>/dev/null
  121. # Build the mtree database in a temporary location.
  122. MTREENEW=`mktemp -t mergemaster.mtree`
  123. mtree -ci -p ${TEMPROOT} -k size,md5digest > ${MTREENEW} 2>/dev/null
  124. if [ -s "${MTREENEW}" ]; then
  125. echo "*** Saving mtree database for future upgrades"
  126. test -e "${DESTDIR}${MTREEFILE}" && unlink ${DESTDIR}${MTREEFILE}
  127. mv ${MTREENEW} ${DESTDIR}${MTREEFILE}
  128. fi
  129. delete_temproot
  130. exit 0