#!/usr/bin/env bash

# This script resides in this path because it is responsible for building documentation
# via github actions. It uses the ../Dockerfile and there is no other use for it.

# © Copyright EnterpriseDB UK Limited 2011-2025
#
# This file is part of Barman.
#
# Barman is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Barman is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Barman.  If not, see <http://www.gnu.org/licenses/>.

set -xeu

DOCDIR="${BASEDIR}/docs"
DISTDIR="${DOCDIR}/dist"

USERMAP=$(docker run --rm -v "${BASEDIR}":"${BASEDIR}" "${SPHINX_IMAGE}" \
  stat -c %u:%g "${BASEDIR}")
docker run --rm -u "${USERMAP}" -w "$(pwd)" -v "${BASEDIR}:${BASEDIR}" \
  "$SPHINX_IMAGE" tox -e docs -- html latexpdf

pwd
ls
mkdir -p "${DISTDIR}"
cp -va "${DOCDIR}"/_build/html/* "${DISTDIR}"
cp -va "${DOCDIR}"/_build/latex/Barman.pdf "${DISTDIR}"/manual.pdf
