#!/usr/bin/env bash

# © Copyright EnterpriseDB UK Limited 2011-2023
#
# 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}/doc"
SRCDIR="${BASEDIR}"
DISTDIR="${DOCDIR}/dist"


cd "${SRCDIR}/doc/build"
mkdir -p source
cp -va "${SRCDIR}"/doc/*.md source
cp -va "${SRCDIR}"/doc/*.d source
cp -va "${SRCDIR}"/doc/manual .
cp -va "${SRCDIR}"/doc/images .
pwd
ls

USERMAP=$(docker run --rm -v "${BASEDIR}":"${BASEDIR}" "${PANDOC_IMAGE}" \
  stat -c %u:%g "${BASEDIR}")
docker run --rm -u "${USERMAP}" -w "$(pwd)" -v "${BASEDIR}:${BASEDIR}" \
  "$PANDOC_IMAGE" make clean all

pwd
ls
mkdir -p "${DISTDIR}"
cp -va *.html *.pdf "${DISTDIR}"
mkdir -p "${DISTDIR}/html-templates"
cp -va html-templates/*.css "${DISTDIR}/html-templates"
mkdir -p "${DISTDIR}/images"
cp -va images/* "${DISTDIR}/images"
