Updating Installation and fixing the toc.tree
[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 "doctor"
25     echo "fastpathmetrics"
26     echo "fuel"
27     echo "functest"
28     echo "ipv6"
29     echo "joid"
30     echo "ovsnfv"
31     echo "pharos"
32     echo "prediction"
33     echo "promise"
34     echo "sdnvpn"
35     echo "vswitchperf"
36     echo "yardstick"
37 }
38
39 git_clone() {
40     _repo="$1"
41
42     [[ -d "$WORKSPACE/$_repo" ]] && return 0
43     pushd $WORKSPACE
44     git clone -b $GERRIT_BRANCH --depth 1 --quiet $GIT_CLONE_BASE/$_repo
45     popd
46 }
47
48 repos=$(get_repo_names)
49
50 [[ -e docs/projects ]] && rm -rf docs/projects
51 mkdir -p docs/projects
52
53 echo
54 echo "Cloning repos of participating OPNFV Projects and copying docs"
55 echo
56 for repo in $repos; do
57     echo "    $repo ($GERRIT_BRANCH)"
58     git_clone $repo
59     [[ -e $WORKSPACE/$repo/docs ]] || continue
60     [[ -e docs/projects/$repo ]] && rm -rf docs/projects/$repo
61     cp -r $WORKSPACE/$repo/docs docs/projects/$repo
62 done
63
64 # NOTE: Removing index.rst in project repos to reduce number of docs.
65 find docs/projects -type f -name 'index.rst' -print | xargs -I i rm -f i
66
67 # fix relative file paths
68 pattern='.. \(include\|figure\):: *[^ \/]'
69 base_path="/$(pwd)/docs_build/_src"
70 find docs/projects -type f -name '*.rst' -print | while read f
71 do
72     sed -i -e "/$pattern/s|:: *|:: $base_path/$(dirname ${f#docs/})/|" $f
73 done
74
75 # for debug
76 grep -e '.. include::' -e '.. figure::' -r docs/projects
77
78 # NOTE: automated link generation is not ready...
79 echo
80 echo "Creating document links"
81 echo
82 targets="
83 configurationguide/configuration.options.render.rst
84 configurationguide/scenario.description.rst
85 userguide/feature.userguide.render.rst
86 testframework/framework.installation.procedure.render.rst
87 testframework/framework.userguide.render.rst
88 "
89 # configurationguide/post-install.rst
90 for guide in $targets
91 do
92     mainfile="$WORKSPACE/docs/$guide"
93     basefilename=$(basename ${guide/-/})
94     for repo in $repos
95     do
96         targetfile="$WORKSPACE/docs/projects/$repo/${guide/-/}"
97         targetlink="../projects/$repo/${guide/-/}"
98         projectfilename="${basefilename/.rst/-$repo.rst}"
99         projectfile="$(dirname $mainfile)/$projectfilename"
100         [[ -e "$targetfile" ]] || continue
101         echo "Adding $repo to $guide ..."
102         echo "" >> $mainfile
103         echo ".. toctree::" >> $mainfile
104         echo "" >> $mainfile
105         echo "    $projectfilename" >> $mainfile
106         echo ".. include:: $targetlink" > $projectfile
107     done
108     echo
109     echo "Generated $guide:"
110     cat $mainfile
111     echo
112 done