#!/usr/bin/env bash #set -x # Usage: write-user-docs [TOOLS] # # This script writes/updates the user documentation. User docs come from # three places: each tool's POD (pod2rst is used to convert their POD docs # to RST), static .rst file (docs/*.rst), and most head1 sections in # docs/percona-toolkit.pod (also converted writh pod2rst; this file is needed # in .pod form because it's used to make the percona-toolkit man page). # # Run this script from any directory in the branch whose user docs you want # to build. For example, to build user docs in the 2.0 branch: # $ cd ~dev/perona-toolkit/2.0 # $ util/write-user-docs # Unlike other scripts, this one does *not* use PERCONA_TOOLKIT_BRANCH. # # After all the RST files have been written, this script runs `make html' # in config/sphinx-build/ (which has a Makefile) to build the online HTML # docs, which are saved in docs/user/html. # # If no tools are specified on the command line, then docs for bin/* are # written (plus all the extra sections). # # To rewrite all user docs from scratch: # rm -rf docs/user/* # util/write-user-docs # # Exits 0 on success, else 1 on warnings and errors. # ############################################################################ # Parsing options # ############################################################################ usage() { echo "This script writes/updates the user documentation. Usage: write-user-docs [ -h ] [ -p ] [ -t ] [TOOLS] If no option (html, pdf) specified, builds both html and pdf. -h builds docs in html -t builds docs in html with new theme -p builds pdf doc TOOLS: If no tools are specified on the command line, then docs for bin/* are written (plus all the extra sections). " exit 2 } TEMP=$(getopt hpt $*) if [ $? -ne 0 ]; then usage fi eval set -- "$TEMP" unset TEMP while true; do case "$1" in -h) MAKE_HTML="true" MAKE_THTML="false" shift continue ;; -t) MAKE_THTML="true" MAKE_HTML="false" shift continue ;; -p) MAKE_PDF="true" shift continue ;; --) shift break ;; *) echo 'Internal error!' >&2 usage ;; esac done # if both specified or none, build both if [[ "$MAKE_HTML" == "$MAKE_PDF" ]]; then MAKE_HTML="true" MAKE_PDF="true" fi # ############################################################################ # Standard startup, find the branch's root directory # ############################################################################ exit_status=0 die() { echo "$1" >&2 exit 1 } warn() { echo "$1" >&2 exit_status=1 } cwd=$PWD while [ ! -f Makefile.PL ] && [ $(pwd) != "/" ]; do cd .. done if [ ! -f Makefile.PL ]; then die "Cannot find the root directory of the Percona Toolkit branch" fi BRANCH=`pwd` cd $cwd # ############################################################################ # Paths # ############################################################################ DOCS_DIR=$BRANCH/docs RST_DIR=$DOCS_DIR/user # ############################################################################ # Subroutines # ############################################################################ fix_html () { local name="$1" perl -MFile::Basename=basename -le ' my $f = shift; my $tool = basename($f); $tool =~ s/\.html//; my $out = do { open my $fh, q{<}, $f or die "$f: $!"; local $/; <$fh> }; $out =~ s{ \Q