genmans.sh 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/bin/bash
  2. #
  3. # ntpman.sh -- Create man pages for ntp
  4. #
  5. VERSION=$1
  6. if [[ -z ${VERSION} ]] ; then
  7. VERSION=$(ls -1d ntp-*/ 2>/dev/null | LC_COLLATE=C sort | sed -n '${s:/::;p;Q}')
  8. if [[ -z ${VERSION} ]] ; then
  9. VERSION=$(ls "${0%/*}"/../../ntp-*.ebuild | LC_COLLATE=C sort | sed -n '${s:.*/::;s:_::;s:[.]ebuild::;p;Q}')
  10. if [[ -z ${VERSION} ]] ; then
  11. echo "Usage: $0 <version>"
  12. exit 1
  13. fi
  14. fi
  15. fi
  16. [[ ${VERSION} != ntp-* ]] && VERSION="ntp-${VERSION}"
  17. SRCDIR=${0%/*}
  18. HTMLDIR=${SRCDIR}/${VERSION}/html
  19. DISTFILE=/usr/portage/distfiles/${VERSION}.tar.gz
  20. MANDIR=${SRCDIR}/man
  21. rm -rf ${SRCDIR}/${VERSION}
  22. if [[ ! -d ${HTMLDIR} ]] ; then
  23. if [[ -f ${DISTFILE} ]] ; then
  24. tar zxf ${DISTFILE} -C ${SRCDIR} || exit 1
  25. else
  26. echo "ERROR: $HTMLDIR / $DISTFILE does not exist"
  27. exit 1
  28. fi
  29. fi
  30. # Process a single HTML file
  31. processfile() {
  32. HTMLFILE=$1
  33. MANFILE=$2
  34. echo -n "Processing $HTMLFILE ..."
  35. sed -e "s:<csobj.*<:csobj>/:" $HTMLDIR/$HTMLFILE > .$HTMLFILE
  36. xsltproc --html --stringparam version $VERSION ${SRCDIR}/ntp.xsl .$HTMLFILE > $MANDIR/$MANFILE || exit 1
  37. rm -f .$HTMLFILE
  38. echo "Done."
  39. }
  40. # Print information
  41. echo "Generates ntp man files from HTML documentation. Using:"
  42. echo "VERSION: $VERSION"
  43. echo "HTMLDIR: $HTMLDIR"
  44. echo "MANDIR: $MANDIR"
  45. echo "Press enter to continue, or Ctrl-C to cancel."
  46. read
  47. # Process HTML files
  48. rm -rf ${MANDIR}
  49. mkdir ${MANDIR}
  50. for f in ntp{date,dc,d,q,time,trace,dsim} keygen tickadj ; do
  51. processfile ${f}.html ${f}.8
  52. done
  53. echo
  54. cp -vi /usr/local/src/freebsd/src/usr.sbin/ntp/doc/*.5 ${MANDIR}
  55. (
  56. d=${PWD}
  57. cd ${MANDIR}
  58. shopt -s nullglob
  59. for p in $d/*.5.patch ; do
  60. patch -F0 -p0 < $p || exit 1
  61. done
  62. ) || exit 1
  63. cp -vi ${SRCDIR}/*.patch ${SRCDIR}/genmans.sh ${SRCDIR}/ntp.xsl ${MANDIR}
  64. tar -jcf ${VERSION}-manpages.tar.bz2 -C ${MANDIR}/.. man
  65. du -b ${VERSION}-manpages.tar.bz2
  66. rm -rf ${MANDIR} ${SRCDIR}/${VERSION}