summaryrefslogtreecommitdiff
path: root/maintainer/download-docs.sh
blob: 3514a57438fe7de1aca968e3adff28ae7bfffbdf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash

# Usage:
#  download-docs.sh TOP-LEVEL-DIR MANUAL-FILES...
distdir=${1}
shift

# Configurable portions
docs_git=https://github.com/crosstool-ng/crosstool-ng.github.io.git
docs_subdir=_pages/docs

# Clone a repository for docs. Github does not support 'git archive --remote='.
set -ex
git clone --depth=1 "${docs_git}" "${distdir}/site-docs"

# Copy the docs instead of the MANUAL_ONLINE placeholder
mkdir -p "${distdir}/docs/manual"
while [ -n "${1}" ]; do
    case "${1}" in
        docs/manual/*) ;;
        *) echo "Expected file not in docs/manual/: $1" >&2; exit 1;;
    esac
    input="${distdir}/site-docs/${docs_subdir}/${1#docs/manual/}"
    if [ ! -r "${input}" ]; then
        echo "Not found: ${1}" >&2
        exit 1
    fi
    awk '
BEGIN   { skip=0; }
        {
            if ($0=="---") {
                if (NR==1) {
                    skip=1
                    next
                }
                else if (skip) {
                    skip=0
                    next
                }
            }
            if (!skip) {
                print $0
            }
        }
    ' < "${input}" > "${distdir}/${1}"
    rm -f "${input}"
    shift
done
extra_md_pages=false
for i in "${distdir}/site-docs/${docs_subdir}/"*.md; do
    if [ -r "${i}" ]; then
        echo "Unpackaged page in the manual: ${i#${distdir}/site-docs/${docs_subdir}/}"
        extra_md_files=true
    fi
done
if [ "${extra_md_files}" = "true" ]; then
    exit 1
fi
rm -rf "${distdir}/site-docs"