Blame build-aux/gnu-web-doc-update

Packit 709fb3
#!/bin/sh
Packit 709fb3
# Run this after each non-alpha release, to update the web documentation at
Packit 709fb3
# http://www.gnu.org/software/$pkg/manual/
Packit 709fb3
Packit 709fb3
VERSION=2016-01-12.23; # UTC
Packit 709fb3
Packit 709fb3
# Copyright (C) 2009-2017 Free Software Foundation, Inc.
Packit 709fb3
Packit 709fb3
# This program is free software: you can redistribute it and/or modify
Packit 709fb3
# it under the terms of the GNU General Public License as published by
Packit 709fb3
# the Free Software Foundation, either version 3 of the License, or
Packit 709fb3
# (at your option) any later version.
Packit 709fb3
Packit 709fb3
# This program is distributed in the hope that it will be useful,
Packit 709fb3
# but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 709fb3
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 709fb3
# GNU General Public License for more details.
Packit 709fb3
Packit 709fb3
# You should have received a copy of the GNU General Public License
Packit 709fb3
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
Packit 709fb3
Packit 709fb3
ME=$(basename "$0")
Packit 709fb3
warn() { printf '%s: %s\n' "$ME" "$*" >&2; }
Packit 709fb3
die() { warn "$*"; exit 1; }
Packit 709fb3
Packit 709fb3
help()
Packit 709fb3
{
Packit 709fb3
  cat <
Packit 709fb3
Usage: $ME
Packit 709fb3
Packit 709fb3
Run this script from top_srcdir (no arguments) after each non-alpha
Packit 709fb3
release, to update the web documentation at
Packit 709fb3
http://www.gnu.org/software/\$pkg/manual/
Packit 709fb3
Packit 709fb3
This script assumes you're using git for revision control, and
Packit 709fb3
requires a .prev-version file as well as a Makefile, from which it
Packit 709fb3
extracts the version number and package name, respectively.  Also, it
Packit 709fb3
assumes all documentation is in the doc/ sub-directory.
Packit 709fb3
Packit 709fb3
Options:
Packit 709fb3
  -C, --builddir=DIR  location of (configured) Makefile (default: .)
Packit 709fb3
  -n, --dry-run       don't actually commit anything
Packit 709fb3
  -m, --mirror        remove out of date files from document server
Packit 709fb3
  --help              print this help, then exit
Packit 709fb3
  --version           print version number, then exit
Packit 709fb3
Packit 709fb3
Report bugs and patches to <bug-gnulib@gnu.org>.
Packit 709fb3
EOF
Packit 709fb3
  exit
Packit 709fb3
}
Packit 709fb3
Packit 709fb3
version()
Packit 709fb3
{
Packit 709fb3
  year=$(echo "$VERSION" | sed 's/[^0-9].*//')
Packit 709fb3
  cat <
Packit 709fb3
$ME $VERSION
Packit 709fb3
Copyright (C) $year Free Software Foundation, Inc,
Packit 709fb3
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
Packit 709fb3
This is free software: you are free to change and redistribute it.
Packit 709fb3
There is NO WARRANTY, to the extent permitted by law.
Packit 709fb3
EOF
Packit 709fb3
  exit
Packit 709fb3
}
Packit 709fb3
Packit 709fb3
# find_tool ENVVAR NAMES...
Packit 709fb3
# -------------------------
Packit 709fb3
# Search for a required program.  Use the value of ENVVAR, if set,
Packit 709fb3
# otherwise find the first of the NAMES that can be run (i.e.,
Packit 709fb3
# supports --version).  If found, set ENVVAR to the program name,
Packit 709fb3
# die otherwise.
Packit 709fb3
#
Packit 709fb3
# FIXME: code duplication, see also bootstrap.
Packit 709fb3
find_tool ()
Packit 709fb3
{
Packit 709fb3
  find_tool_envvar=$1
Packit 709fb3
  shift
Packit 709fb3
  find_tool_names=$@
Packit 709fb3
  eval "find_tool_res=\$$find_tool_envvar"
Packit 709fb3
  if test x"$find_tool_res" = x; then
Packit 709fb3
    for i
Packit 709fb3
    do
Packit 709fb3
      if ($i --version </dev/null) >/dev/null 2>&1; then
Packit 709fb3
       find_tool_res=$i
Packit 709fb3
       break
Packit 709fb3
      fi
Packit 709fb3
    done
Packit 709fb3
  else
Packit 709fb3
    find_tool_error_prefix="\$$find_tool_envvar: "
Packit 709fb3
  fi
Packit 709fb3
  test x"$find_tool_res" != x \
Packit 709fb3
    || die "one of these is required: $find_tool_names"
Packit 709fb3
  ($find_tool_res --version </dev/null) >/dev/null 2>&1 \
Packit 709fb3
    || die "${find_tool_error_prefix}cannot run $find_tool_res --version"
Packit 709fb3
  eval "$find_tool_envvar=\$find_tool_res"
Packit 709fb3
  eval "export $find_tool_envvar"
Packit 709fb3
}
Packit 709fb3
Packit 709fb3
## ------ ##
Packit 709fb3
## Main.  ##
Packit 709fb3
## ------ ##
Packit 709fb3
Packit 709fb3
# Requirements: everything required to bootstrap your package, plus
Packit 709fb3
# these.
Packit 709fb3
find_tool CVS cvs
Packit 709fb3
find_tool GIT git
Packit 709fb3
find_tool RSYNC rsync
Packit 709fb3
find_tool XARGS gxargs xargs
Packit 709fb3
Packit 709fb3
builddir=.
Packit 709fb3
dryrun=
Packit 709fb3
rm_stale='echo'
Packit 709fb3
while test $# != 0
Packit 709fb3
do
Packit 709fb3
  # Handle --option=value by splitting apart and putting back on argv.
Packit 709fb3
  case $1 in
Packit 709fb3
    --*=*)
Packit 709fb3
      opt=$(echo "$1" | sed -e 's/=.*//')
Packit 709fb3
      val=$(echo "$1" | sed -e 's/[^=]*=//')
Packit 709fb3
      shift
Packit 709fb3
      set dummy "$opt" "$val" "$@"; shift
Packit 709fb3
      ;;
Packit 709fb3
  esac
Packit 709fb3
Packit 709fb3
  case $1 in
Packit 709fb3
    --help|--version) ${1#--};;
Packit 709fb3
    -C|--builddir) shift; builddir=$1; shift ;;
Packit 709fb3
    -n|--dry-run) dryrun=echo; shift;;
Packit 709fb3
    -m|--mirror) rm_stale=''; shift;;
Packit 709fb3
    --*) die "unrecognized option: $1";;
Packit 709fb3
    *) break;;
Packit 709fb3
  esac
Packit 709fb3
done
Packit 709fb3
Packit 709fb3
test $# = 0 \
Packit 709fb3
  || die "too many arguments"
Packit 709fb3
Packit 709fb3
prev=.prev-version
Packit 709fb3
version=$(cat $prev) || die "no $prev file?"
Packit 709fb3
pkg=$(sed -n 's/^PACKAGE = \(.*\)/\1/p' $builddir/Makefile) \
Packit 709fb3
  || die "no Makefile?"
Packit 709fb3
tmp_branch=web-doc-$version-$$
Packit 709fb3
current_branch=$($GIT branch | sed -ne '/^\* /{s///;p;q;}')
Packit 709fb3
Packit 709fb3
cleanup()
Packit 709fb3
{
Packit 709fb3
  __st=$?
Packit 709fb3
  $dryrun rm -rf "$tmp"
Packit 709fb3
  $GIT checkout "$current_branch"
Packit 709fb3
  $GIT submodule update --recursive
Packit 709fb3
  $GIT branch -d $tmp_branch
Packit 709fb3
  exit $__st
Packit 709fb3
}
Packit 709fb3
trap cleanup 0
Packit 709fb3
trap 'exit $?' 1 2 13 15
Packit 709fb3
Packit 709fb3
# We must build using sources for which --version reports the
Packit 709fb3
# just-released version number, not some string like 7.6.18-20761.
Packit 709fb3
# That version string propagates into all documentation.
Packit 709fb3
set -e
Packit 709fb3
$GIT checkout -b $tmp_branch v$version
Packit 709fb3
$GIT submodule update --recursive
Packit 709fb3
./bootstrap
Packit 709fb3
srcdir=$(pwd)
Packit 709fb3
cd "$builddir"
Packit 709fb3
builddir=$(pwd)
Packit 709fb3
  ./config.status --recheck
Packit 709fb3
  ./config.status
Packit 709fb3
  make
Packit 709fb3
  make web-manual
Packit 709fb3
cd "$srcdir"
Packit 709fb3
set +e
Packit 709fb3
Packit 709fb3
tmp=$(mktemp -d web-doc-update.XXXXXX) || exit 1
Packit 709fb3
( cd $tmp \
Packit 709fb3
    && $CVS -d $USER@cvs.sv.gnu.org:/webcvs/$pkg co $pkg )
Packit 709fb3
$RSYNC -avP "$builddir"/doc/manual/ $tmp/$pkg/manual
Packit 709fb3
Packit 709fb3
(
Packit 709fb3
  cd $tmp/$pkg/manual
Packit 709fb3
Packit 709fb3
  # Add all the files.  This is simpler than trying to add only the
Packit 709fb3
  # new ones because of new directories
Packit 709fb3
  # First add non empty dirs individually
Packit 709fb3
  find . -name CVS -prune -o -type d \! -empty -print             \
Packit 709fb3
    | $XARGS -n1 --no-run-if-empty -- $dryrun $CVS add -ko
Packit 709fb3
  # Now add all files
Packit 709fb3
  find . -name CVS -prune -o -type f -print             \
Packit 709fb3
    | $XARGS --no-run-if-empty -- $dryrun $CVS add -ko
Packit 709fb3
Packit 709fb3
  # Report/Remove stale files
Packit 709fb3
  #   excluding doc server specific files like CVS/* and .symlinks
Packit 709fb3
  if test -n "$rm_stale"; then
Packit 709fb3
    echo 'Consider the --mirror option if all of the manual is generated,' >&2
Packit 709fb3
    echo 'which will run `cvs remove` to remove stale files.' >&2
Packit 709fb3
  fi
Packit 709fb3
  { find . \( -name CVS -o -type f -name '.*' \) -prune -o -type f -print
Packit 709fb3
    (cd "$builddir"/doc/manual/ && find . -type f -print | sed p)
Packit 709fb3
  } | sort | uniq -u \
Packit 709fb3
    | $XARGS --no-run-if-empty -- ${rm_stale:-$dryrun} $CVS remove -f
Packit 709fb3
Packit 709fb3
  $dryrun $CVS ci -m $version
Packit 709fb3
)
Packit 709fb3
Packit 709fb3
# Local variables:
Packit 709fb3
# eval: (add-hook 'write-file-hooks 'time-stamp)
Packit 709fb3
# time-stamp-start: "VERSION="
Packit 709fb3
# time-stamp-format: "%:y-%02m-%02d.%02H"
Packit 709fb3
# time-stamp-time-zone: "UTC0"
Packit 709fb3
# time-stamp-end: "; # UTC"
Packit 709fb3
# End: