gnu-web-doc-update 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. #!/bin/sh
  2. # Run this after each non-alpha release, to update the web documentation at
  3. # https://www.gnu.org/software/$pkg/manual/
  4. VERSION=2018-03-07.03; # UTC
  5. # Copyright (C) 2009-2018 Free Software Foundation, Inc.
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. ME=$(basename "$0")
  17. warn() { printf '%s: %s\n' "$ME" "$*" >&2; }
  18. die() { warn "$*"; exit 1; }
  19. help()
  20. {
  21. cat <<EOF
  22. Usage: $ME
  23. Run this script from top_srcdir (no arguments) after each non-alpha
  24. release, to update the web documentation at
  25. https://www.gnu.org/software/\$pkg/manual/
  26. This script assumes you're using git for revision control, and
  27. requires a .prev-version file as well as a Makefile, from which it
  28. extracts the version number and package name, respectively. Also, it
  29. assumes all documentation is in the doc/ sub-directory.
  30. Options:
  31. -C, --builddir=DIR location of (configured) Makefile (default: .)
  32. -n, --dry-run don't actually commit anything
  33. -m, --mirror remove out of date files from document server
  34. --help print this help, then exit
  35. --version print version number, then exit
  36. Report bugs and patches to <bug-gnulib@gnu.org>.
  37. EOF
  38. exit
  39. }
  40. version()
  41. {
  42. year=$(echo "$VERSION" | sed 's/[^0-9].*//')
  43. cat <<EOF
  44. $ME $VERSION
  45. Copyright (C) $year Free Software Foundation, Inc,
  46. License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>
  47. This is free software: you are free to change and redistribute it.
  48. There is NO WARRANTY, to the extent permitted by law.
  49. EOF
  50. exit
  51. }
  52. # find_tool ENVVAR NAMES...
  53. # -------------------------
  54. # Search for a required program. Use the value of ENVVAR, if set,
  55. # otherwise find the first of the NAMES that can be run (i.e.,
  56. # supports --version). If found, set ENVVAR to the program name,
  57. # die otherwise.
  58. #
  59. # FIXME: code duplication, see also bootstrap.
  60. find_tool ()
  61. {
  62. find_tool_envvar=$1
  63. shift
  64. find_tool_names=$@
  65. eval "find_tool_res=\$$find_tool_envvar"
  66. if test x"$find_tool_res" = x; then
  67. for i
  68. do
  69. if ($i --version </dev/null) >/dev/null 2>&1; then
  70. find_tool_res=$i
  71. break
  72. fi
  73. done
  74. else
  75. find_tool_error_prefix="\$$find_tool_envvar: "
  76. fi
  77. test x"$find_tool_res" != x \
  78. || die "one of these is required: $find_tool_names"
  79. ($find_tool_res --version </dev/null) >/dev/null 2>&1 \
  80. || die "${find_tool_error_prefix}cannot run $find_tool_res --version"
  81. eval "$find_tool_envvar=\$find_tool_res"
  82. eval "export $find_tool_envvar"
  83. }
  84. ## ------ ##
  85. ## Main. ##
  86. ## ------ ##
  87. # Requirements: everything required to bootstrap your package, plus
  88. # these.
  89. find_tool CVS cvs
  90. find_tool GIT git
  91. find_tool RSYNC rsync
  92. find_tool XARGS gxargs xargs
  93. builddir=.
  94. dryrun=
  95. rm_stale='echo'
  96. while test $# != 0
  97. do
  98. # Handle --option=value by splitting apart and putting back on argv.
  99. case $1 in
  100. --*=*)
  101. opt=$(echo "$1" | sed -e 's/=.*//')
  102. val=$(echo "$1" | sed -e 's/[^=]*=//')
  103. shift
  104. set dummy "$opt" "$val" "$@"; shift
  105. ;;
  106. esac
  107. case $1 in
  108. --help|--version) ${1#--};;
  109. -C|--builddir) shift; builddir=$1; shift ;;
  110. -n|--dry-run) dryrun=echo; shift;;
  111. -m|--mirror) rm_stale=''; shift;;
  112. --*) die "unrecognized option: $1";;
  113. *) break;;
  114. esac
  115. done
  116. test $# = 0 \
  117. || die "too many arguments"
  118. prev=.prev-version
  119. version=$(cat $prev) || die "no $prev file?"
  120. pkg=$(sed -n 's/^PACKAGE = \(.*\)/\1/p' $builddir/Makefile) \
  121. || die "no Makefile?"
  122. tmp_branch=web-doc-$version-$$
  123. current_branch=$($GIT branch | sed -ne '/^\* /{s///;p;q;}')
  124. cleanup()
  125. {
  126. __st=$?
  127. $dryrun rm -rf "$tmp"
  128. $GIT checkout "$current_branch"
  129. $GIT submodule update --recursive
  130. $GIT branch -d $tmp_branch
  131. exit $__st
  132. }
  133. trap cleanup 0
  134. trap 'exit $?' 1 2 13 15
  135. # We must build using sources for which --version reports the
  136. # just-released version number, not some string like 7.6.18-20761.
  137. # That version string propagates into all documentation.
  138. set -e
  139. $GIT checkout -b $tmp_branch v$version
  140. $GIT submodule update --recursive
  141. ./bootstrap
  142. srcdir=$(pwd)
  143. cd "$builddir"
  144. builddir=$(pwd)
  145. ./config.status --recheck
  146. ./config.status
  147. make
  148. make web-manual
  149. cd "$srcdir"
  150. set +e
  151. tmp=$(mktemp -d web-doc-update.XXXXXX) || exit 1
  152. ( cd $tmp \
  153. && $CVS -d $USER@cvs.sv.gnu.org:/webcvs/$pkg co $pkg )
  154. $RSYNC -avP "$builddir"/doc/manual/ $tmp/$pkg/manual
  155. (
  156. cd $tmp/$pkg/manual
  157. # Add all the files. This is simpler than trying to add only the
  158. # new ones because of new directories
  159. # First add non empty dirs individually
  160. find . -name CVS -prune -o -type d \! -empty -print \
  161. | $XARGS -n1 --no-run-if-empty -- $dryrun $CVS add -ko
  162. # Now add all files
  163. find . -name CVS -prune -o -type f -print \
  164. | $XARGS --no-run-if-empty -- $dryrun $CVS add -ko
  165. # Report/Remove stale files
  166. # excluding doc server specific files like CVS/* and .symlinks
  167. if test -n "$rm_stale"; then
  168. echo 'Consider the --mirror option if all of the manual is generated,' >&2
  169. echo 'which will run `cvs remove` to remove stale files.' >&2
  170. fi
  171. { find . \( -name CVS -o -type f -name '.*' \) -prune -o -type f -print
  172. (cd "$builddir"/doc/manual/ && find . -type f -print | sed p)
  173. } | sort | uniq -u \
  174. | $XARGS --no-run-if-empty -- ${rm_stale:-$dryrun} $CVS remove -f
  175. $dryrun $CVS ci -m $version
  176. )
  177. # Local variables:
  178. # eval: (add-hook 'before-save-hook 'time-stamp)
  179. # time-stamp-start: "VERSION="
  180. # time-stamp-format: "%:y-%02m-%02d.%02H"
  181. # time-stamp-time-zone: "UTC0"
  182. # time-stamp-end: "; # UTC"
  183. # End: