gnu-web-doc-update 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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=2022-01-27.18; # UTC
  5. # Copyright (C) 2009-2023 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. -u, --user the name of the CVS user on Savannah
  35. --help print this help, then exit
  36. --version print version number, then exit
  37. Report bugs and patches to <bug-gnulib@gnu.org>.
  38. EOF
  39. exit
  40. }
  41. version()
  42. {
  43. year=$(echo "$VERSION" | sed 's/[^0-9].*//')
  44. cat <<EOF
  45. $ME $VERSION
  46. Copyright (C) $year Free Software Foundation, Inc,
  47. License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>
  48. This is free software: you are free to change and redistribute it.
  49. There is NO WARRANTY, to the extent permitted by law.
  50. EOF
  51. exit
  52. }
  53. # find_tool ENVVAR NAMES...
  54. # -------------------------
  55. # Search for a required program. Use the value of ENVVAR, if set,
  56. # otherwise find the first of the NAMES that can be run (i.e.,
  57. # supports --version). If found, set ENVVAR to the program name,
  58. # die otherwise.
  59. #
  60. # FIXME: code duplication, see also bootstrap.
  61. find_tool ()
  62. {
  63. find_tool_envvar=$1
  64. shift
  65. find_tool_names=$@
  66. eval "find_tool_res=\$$find_tool_envvar"
  67. if test x"$find_tool_res" = x; then
  68. for i
  69. do
  70. if ($i --version </dev/null) >/dev/null 2>&1; then
  71. find_tool_res=$i
  72. break
  73. fi
  74. done
  75. else
  76. find_tool_error_prefix="\$$find_tool_envvar: "
  77. fi
  78. test x"$find_tool_res" != x \
  79. || die "one of these is required: $find_tool_names"
  80. ($find_tool_res --version </dev/null) >/dev/null 2>&1 \
  81. || die "${find_tool_error_prefix}cannot run $find_tool_res --version"
  82. eval "$find_tool_envvar=\$find_tool_res"
  83. eval "export $find_tool_envvar"
  84. }
  85. ## ------ ##
  86. ## Main. ##
  87. ## ------ ##
  88. # Requirements: everything required to bootstrap your package, plus
  89. # these.
  90. find_tool CVS cvs
  91. find_tool GIT git
  92. find_tool RSYNC rsync
  93. find_tool XARGS gxargs xargs
  94. builddir=.
  95. dryrun=
  96. rm_stale='echo'
  97. cvs_user="$USER"
  98. while test $# != 0
  99. do
  100. # Handle --option=value by splitting apart and putting back on argv.
  101. case $1 in
  102. --*=*)
  103. opt=$(echo "$1" | sed -e 's/=.*//')
  104. val=$(echo "$1" | sed -e 's/[^=]*=//')
  105. shift
  106. set dummy "$opt" "$val" "$@"; shift
  107. ;;
  108. esac
  109. case $1 in
  110. --help|--version) ${1#--};;
  111. -C|--builddir) shift; builddir=$1; shift ;;
  112. -n|--dry-run) dryrun=echo; shift;;
  113. -m|--mirror) rm_stale=''; shift;;
  114. -u|--user) shift; cvs_user=$1; shift ;;
  115. --*) die "unrecognized option: $1";;
  116. *) break;;
  117. esac
  118. done
  119. test $# = 0 \
  120. || die "too many arguments"
  121. prev=.prev-version
  122. version=$(cat $prev) || die "no $prev file?"
  123. pkg=$(sed -n 's/^PACKAGE = \(.*\)/\1/p' $builddir/Makefile) \
  124. || die "no Makefile?"
  125. tmp_branch=web-doc-$version-$$
  126. current_branch=$($GIT branch | sed -ne '/^\* /{s///;p;q;}')
  127. cleanup()
  128. {
  129. __st=$?
  130. $dryrun rm -rf "$tmp"
  131. $GIT checkout "$current_branch"
  132. $GIT submodule update --recursive
  133. $GIT branch -d $tmp_branch
  134. exit $__st
  135. }
  136. trap cleanup EXIT
  137. trap 'exit $?' HUP INT PIPE TERM
  138. # We must build using sources for which --version reports the
  139. # just-released version number, not some string like 7.6.18-20761.
  140. # That version string propagates into all documentation.
  141. set -e
  142. $GIT checkout -b $tmp_branch v$version
  143. $GIT submodule update --recursive
  144. ./bootstrap
  145. srcdir=$(pwd)
  146. cd "$builddir"
  147. builddir=$(pwd)
  148. ./config.status --recheck
  149. ./config.status
  150. make
  151. make web-manual
  152. cd "$srcdir"
  153. set +e
  154. tmp=$(mktemp -d web-doc-update.XXXXXX) || exit 1
  155. ( cd $tmp \
  156. && $CVS -d $cvs_user@cvs.sv.gnu.org:/webcvs/$pkg co $pkg )
  157. $RSYNC -avP "$builddir"/doc/manual/ $tmp/$pkg/manual
  158. (
  159. cd $tmp/$pkg/manual
  160. # Add all the files. This is simpler than trying to add only the
  161. # new ones because of new directories
  162. # First add non empty dirs individually
  163. find . -name CVS -prune -o -type d \! -empty -print \
  164. | $XARGS -n1 --no-run-if-empty -- $dryrun $CVS add -ko
  165. # Now add all files
  166. find . -name CVS -prune -o -type f -print \
  167. | $XARGS --no-run-if-empty -- $dryrun $CVS add -ko
  168. # Report/Remove stale files
  169. # excluding doc server specific files like CVS/* and .symlinks
  170. if test -n "$rm_stale"; then
  171. echo 'Consider the --mirror option if all of the manual is generated,' >&2
  172. echo 'which will run `cvs remove` to remove stale files.' >&2
  173. fi
  174. { find . \( -name CVS -o -type f -name '.*' \) -prune -o -type f -print
  175. (cd "$builddir"/doc/manual/ && find . -type f -print | sed p)
  176. } | sort | uniq -u \
  177. | $XARGS --no-run-if-empty -- ${rm_stale:-$dryrun} $CVS remove -f
  178. $dryrun $CVS ci -m $version
  179. )
  180. # Local variables:
  181. # eval: (add-hook 'before-save-hook 'time-stamp)
  182. # time-stamp-start: "VERSION="
  183. # time-stamp-format: "%:y-%02m-%02d.%02H"
  184. # time-stamp-time-zone: "UTC0"
  185. # time-stamp-end: "; # UTC"
  186. # End: