Removal of the rememberance of Al
[opnfvdocs.git] / docs / pre-hook.sh
1 #!/bin/bash
2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) 2016 NEC and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10
11 GIT_CLONE_BASE=${GIT_CLONE_BASE:-ssh://gerrit.opnfv.org:29418}
12 GERRIT_BRANCH=${GERRIT_BRANCH:-master}
13 WORKSPACE=${WORKSPACE:-.}
14
15 get_repo_names() {
16     # NOTE: Not all repositories are ready for the composite docs,
17     #       so we have the repo name list here to add project docs
18     #       one by one. This will be replaced by the list in project.cfg .
19     # grep -v '^#' releng/jjb/opnfvdocs/project.cfg | sort
20     echo "apex"
21     echo "bottlenecks"
22     echo "compass4nfv"
23     echo "copper"
24     echo "daisy"
25     echo "doctor"
26     echo "fastpathmetrics"
27     echo "fuel"
28     echo "functest"
29     echo "ipv6"
30     echo "joid"
31     echo "ovsnfv"
32     echo "pharos"
33     echo "prediction"
34     echo "promise"
35     echo "sdnvpn"
36     echo "vswitchperf"
37     echo "yardstick"
38 }
39
40 git_clone() {
41     _repo="$1"
42
43     [[ -d "$WORKSPACE/$_repo" ]] && return 0
44     pushd $WORKSPACE
45     git clone -b $GERRIT_BRANCH --depth 1 --quiet $GIT_CLONE_BASE/$_repo
46     popd
47 }
48
49 repos=$(get_repo_names)
50
51 [[ -e docs/projects ]] && rm -rf docs/projects
52 mkdir -p docs/projects
53
54 echo
55 echo "Cloning repos of participating OPNFV Projects and copying docs"
56 echo
57 for repo in $repos; do
58     echo "    $repo ($GERRIT_BRANCH)"
59     git_clone $repo
60     [[ -e $WORKSPACE/$repo/docs ]] || continue
61     [[ -e docs/projects/$repo ]] && rm -rf docs/projects/$repo
62     cp -r $WORKSPACE/$repo/docs docs/projects/$repo
63 done
64
65 # NOTE: Removing index.rst in project repos to reduce number of docs.
66 find docs/projects -type f -name 'index.rst' -print | xargs -I i rm -f i
67
68 # fix relative file paths
69 pattern='.. \(include\|figure\):: *[^ \/]'
70 base_path="/$(pwd)/docs_build/_src"
71 find docs/projects -type f -name '*.rst' -print | while read f
72 do
73     sed -i -e "/$pattern/s|:: *|:: $base_path/$(dirname ${f#docs/})/|" $f
74 done
75
76 # for debug
77 grep -e '.. include::' -e '.. figure::' -r docs/projects
78
79 # NOTE: automated link generation is not ready...
80 echo
81 echo "Creating document links"
82 echo
83 targets="
84 configurationguide/configuration.options.render.rst
85 configurationguide/scenario.description.rst
86 userguide/feature.userguide.render.rst
87 testframework/framework.installation.procedure.render.rst
88 testframework/framework.userguide.render.rst
89 "
90 # configurationguide/post-install.rst
91 for guide in $targets
92 do
93     mainfile="$WORKSPACE/docs/$guide"
94     basefilename=$(basename ${guide/-/})
95     for repo in $repos
96     do
97         targetfile="$WORKSPACE/docs/projects/$repo/${guide/-/}"
98         targetlink="../projects/$repo/${guide/-/}"
99         projectfilename="${basefilename/.rst/-$repo.rst}"
100         projectfile="$(dirname $mainfile)/$projectfilename"
101         [[ -e "$targetfile" ]] || continue
102         echo "Adding $repo to $guide ..."
103         echo "" >> $mainfile
104         echo ".. toctree::" >> $mainfile
105         echo "" >> $mainfile
106         echo "    $projectfilename" >> $mainfile
107         echo ".. include:: $targetlink" > $projectfile
108     done
109     echo
110     echo "Generated $guide:"
111     cat $mainfile
112     echo
113 done