|
| 1 | +#!/bin/bash |
| 2 | +set -e |
| 3 | + |
| 4 | +verbose=false |
| 5 | +install_deps=false |
| 6 | +build_docs=true |
| 7 | + |
| 8 | +function print_synopsis { |
| 9 | + echo "$0 [options] " |
| 10 | + echo " -h, --help print this help message and exit." |
| 11 | + echo " -v, --verbose print each executed command." |
| 12 | + echo " -i, --install-deps install dependencies before building." |
| 13 | + echo " --skip-build skip building and spellchecking docs." |
| 14 | + echo " Useful to just install dependencies." |
| 15 | +} |
| 16 | + |
| 17 | +function wrong_dir() { |
| 18 | + echo "Please run script from 'docs' directory" |
| 19 | + exit 1 |
| 20 | +} |
| 21 | + |
| 22 | +# https://stackoverflow.com/a/14203146 |
| 23 | +# Use -gt 1 to consume two arguments per pass in the loop (e.g. each |
| 24 | +# argument has a corresponding value to go with it). |
| 25 | +# Use -gt 0 to consume one or more arguments per pass in the loop (e.g. |
| 26 | +# some arguments don't have a corresponding value to go with it such |
| 27 | +# as in the --default example). |
| 28 | +# note: if this is set to -gt 0 the /etc/hosts part is not recognized ( may be a bug ) |
| 29 | +while [[ $# -gt 0 ]] |
| 30 | +do |
| 31 | +key="$1" |
| 32 | + |
| 33 | +case $key in |
| 34 | + -h|--help) |
| 35 | + print_synopsis |
| 36 | + exit 0 |
| 37 | + ;; |
| 38 | + -v|--verbose) |
| 39 | + verbose=true |
| 40 | + ;; |
| 41 | + -i|--install-deps) |
| 42 | + install_deps=true |
| 43 | + ;; |
| 44 | + --skip-build) |
| 45 | + build_docs=false |
| 46 | + ;; |
| 47 | + -*) |
| 48 | + # unknown option |
| 49 | + echo "error: unknown option '$key'" |
| 50 | + echo "" |
| 51 | + print_synopsis |
| 52 | + exit 1 |
| 53 | + ;; |
| 54 | + *) |
| 55 | + # no free arguments allowed |
| 56 | + echo "error: no free arguments allowed: '$key'" |
| 57 | + echo "" |
| 58 | + print_synopsis |
| 59 | + exit 1 |
| 60 | + ;; |
| 61 | +esac |
| 62 | +shift # past argument or value |
| 63 | +done |
| 64 | + |
| 65 | +if [ "$verbose" = true ]; then |
| 66 | + set -x |
| 67 | +fi |
| 68 | + |
| 69 | +if [ "$install_deps" = true ]; then |
| 70 | + echo "### Update apt cache ###" |
| 71 | + sudo apt-get update -qq |
| 72 | + echo "### install sphinx packages ###" |
| 73 | + echo " - pyhton3-sphinx - base package" |
| 74 | + echo " - python3-sphinx-rtd-theme - nice read-the-docs theme" |
| 75 | + echo " - python3-sphinxcontrib.spelling - spellcheck sphinx files" |
| 76 | + #echo " - texlive-latex-extra - latex support to render pdf and also math in html" |
| 77 | + #echo " - dvipng - convert math formulas to pngs for html output" |
| 78 | + #echo " - graphviz - support for dot, creating flowcharts and other graphs" |
| 79 | + echo " - python3-matplotlib - support for matplotlib plots" |
| 80 | + echo " - python3-myst-parser - support for markdown files" |
| 81 | + sudo DEBIAN_FRONTEND=noninteractive apt-get -yq install --no-install-recommends \ |
| 82 | + python3-sphinx python3-sphinx-rtd-theme python3-sphinxcontrib.spelling python3-matplotlib python3-myst-parser |
| 83 | +fi |
| 84 | + |
| 85 | +# determine build and install directory |
| 86 | +SCRIPT_DIR=$(dirname "$0") |
| 87 | +SCRIPT_DIR_ABS=$(realpath "${SCRIPT_DIR}") |
| 88 | + |
| 89 | +if [ "$build_docs" = true ]; then |
| 90 | + cd "${SCRIPT_DIR_ABS}" |
| 91 | + echo "### remove old build directories ###" |
| 92 | + rm -rf _build _static _spelling |
| 93 | + echo "### create _static dir ###" |
| 94 | + mkdir _static |
| 95 | + |
| 96 | + echo "### run sphinx-build ###" |
| 97 | + sphinx-build -v -W . _build |
| 98 | + echo "### run sphinx spell checking ###" |
| 99 | + sphinx-build -b spelling . _spelling |
| 100 | + echo "### done! ###" |
| 101 | +fi |
0 commit comments