publishAsteriskDocs.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #!/usr/bin/env bash
  2. #
  3. # Publish Asterisk documentation to the wiki
  4. #
  5. CIDIR=$(dirname $(readlink -fn $0))
  6. source $CIDIR/ci.functions
  7. ASTETCDIR=$DESTDIR/etc/asterisk
  8. ASTERISK="$DESTDIR/usr/sbin/asterisk"
  9. CONFFILE=$ASTETCDIR/asterisk.conf
  10. OUTPUTDIR=${OUTPUT_DIR:-tests/CI/output/publish-docs}
  11. [ ! -d ${OUTPUTDIR} ] && mkdir -p $OUTPUTDIR
  12. [ x"$USER_GROUP" != x ] && sudo chown -R $USER_GROUP $OUTPUTDIR
  13. rm -rf $ASTETCDIR/extensions.{ael,lua} || :
  14. if test -f ~/.asterisk-wiki.conf; then
  15. . ~/.asterisk-wiki.conf
  16. fi
  17. : ${AWK:=awk}
  18. : ${GREP:=grep}
  19. : ${MAKE:=make}
  20. : ${GIT:=git}
  21. function fail()
  22. {
  23. echo "${PROGNAME}: " "$@" >&2
  24. exit 1
  25. }
  26. function usage()
  27. {
  28. echo "usage: ${PROGNAME} --branch-name=<branch> [ --user-group=<user>:<group> ] [ --output-dir=<output_dir> ]"
  29. }
  30. #
  31. # Check settings from config file
  32. #
  33. if ! test ${CONFLUENCE_URL}; then
  34. fail "CONFLUENCE_URL not set in ~/.asterisk-wiki.conf"
  35. fi
  36. if ! test ${CONFLUENCE_USER}; then
  37. fail "CONFLUENCE_USER not set in ~/.asterisk-wiki.conf"
  38. fi
  39. if ! test ${CONFLUENCE_PASSWORD}; then
  40. fail "CONFLUENCE_PASSWORD not set in ~/.asterisk-wiki.conf"
  41. fi
  42. # needed by publishing scripts. pass via the environment so it doesn't show
  43. # up in the logs.
  44. export CONFLUENCE_PASSWORD
  45. # default space to AST
  46. : ${CONFLUENCE_SPACE:=AST}
  47. #
  48. # Check repository
  49. #
  50. if ! test -f main/asterisk.c; then
  51. fail "Must run from an Asterisk checkout"
  52. fi
  53. #
  54. # Check current working copy
  55. #
  56. CHANGES=$(${GIT} status | grep 'modified:' | wc -l)
  57. if test ${CHANGES} -ne 0; then
  58. fail "Asterisk checkout must be clean"
  59. fi
  60. # Verbose, and exit on any command failure
  61. set -ex
  62. AST_VER=$(export GREP; export AWK; ./build_tools/make_version .)
  63. # Generate latest ARI documentation
  64. make ari-stubs
  65. # Ensure docs are consistent with the implementation
  66. CHANGES=$(${GIT} status | grep 'modified:' | wc -l)
  67. if test ${CHANGES} -ne 0; then
  68. fail "Asterisk code out of date compared to the model"
  69. fi
  70. # make ari-stubs may modify the $Revision$ tags in a file; revert the
  71. # changes
  72. ${GIT} reset --hard
  73. #
  74. # Don't publish docs for non-main-release branches. We still want the above
  75. # validation to ensure that REST API docs are kept up to date though.
  76. #
  77. if [ -n "$WIKI_DOC_BRANCH_REGEX" ] ; then
  78. if [[ ! ${BRANCH_NAME} =~ $WIKI_DOC_BRANCH_REGEX ]] ; then
  79. exit 0;
  80. fi
  81. fi
  82. #
  83. # Publish the REST API.
  84. #
  85. ${OUTPUTDIR}/publish-rest-api.py --username="${CONFLUENCE_USER}" \
  86. --verbose \
  87. --ast-version="${AST_VER}" \
  88. ${CONFLUENCE_URL} \
  89. ${CONFLUENCE_SPACE} \
  90. "Asterisk ${BRANCH_NAME}"
  91. rm -f ${OUTPUTDIR}/full-en_US.xml
  92. sudo $ASTERISK ${USER_GROUP:+-U ${USER_GROUP%%:*} -G ${USER_GROUP##*:}} -gn -C $CONFFILE
  93. for n in {1..5} ; do
  94. sleep 3
  95. $ASTERISK -rx "core waitfullybooted" -C $CONFFILE && break
  96. done
  97. sleep 1
  98. $ASTERISK -rx "xmldoc dump ${OUTPUTDIR}/asterisk-docs.xml" -C $CONFFILE
  99. $ASTERISK -rx "core stop now" -C $CONFFILE
  100. #
  101. # Set the prefix argument for publishing docs
  102. #
  103. PREFIX="Asterisk ${BRANCH_NAME}"
  104. #
  105. # Publish XML documentation.
  106. #
  107. # Script assumes that it's running from TOPDIR
  108. pushd ${OUTPUTDIR}
  109. ./astxml2wiki.py --username="${CONFLUENCE_USER}" \
  110. --server=${CONFLUENCE_URL} \
  111. --prefix="${PREFIX}" \
  112. --space="${CONFLUENCE_SPACE}" \
  113. --file=asterisk-docs.xml \
  114. --ast-version="${AST_VER}" \
  115. -v
  116. popd