Issue-ID: DOC-686
[doc.git] / tools / checkrtd.sh
1 #!/bin/bash
2 #set -x # uncomment for bash script debugging
3
4 # branch, e.g. "master" or "guilin"
5 branch=$1
6 # logfile produced by checkdocs that contains the list of links
7 file_to_process=$2
8
9 #
10 # NOTE: works NOT with elalto release and below because of the submodule structure used for documentation
11 #
12
13 # url
14 # important! only doc project needs a different url base
15 url_lang="en"
16 url_branch=${branch}
17 unique=$(date +%s)
18
19 # "master" branch documentation is available as "latest" in RTD
20 if [[ ${url_branch} == "master" ]]; then
21   url_branch="latest"
22 fi
23
24 #readarray -t array < ./${branch}_releasenotes.log;
25 readarray -t array < ${file_to_process};
26 for line in "${array[@]}"
27 do
28
29   reponame=$(echo ${line} | cut -d "[" -f2 | cut -d "]" -f1)
30   #echo "DBUG: reponame=${reponame}"
31
32   # example line: [dmaap/messagerouter/messageservice]/docs/release-notes/release-notes.rst
33   # example url:  https://docs.onap.org/projects/onap-dmaap-messagerouter-messageservice/en/frankfurt/release-notes/release-notes.html
34
35   # extract repo name which comes in square bracktes ([...]) and convert slash (/) to minus (-)
36   # line:   [dmaap/messagerouter/messageservice]/docs/release-notes/release-notes.rst
37   # output:  dmaap-messagerouter-messageservice
38   url_repo=$(echo ${line} | sed -r 's/].+$//' | sed -r 's/\[//' | sed -r 's/\//-/g')
39
40   # extract rst filename and its path; replace .rst ending with .html
41   # warning: path does not always contain "docs"!
42   # line:   [dmaap/messagerouter/messageservice]/docs/release-notes/release-notes.rst
43   # output:                                           release-notes/release-notes.html
44   url_file=$(echo ${line} | sed -r 's/^.+\]//' | sed -r 's/^.*docs\///' | sed -r 's/\.rst$/\.html/' )
45
46   # build the full url
47   if [[ ${reponame} == "doc" ]]; then
48     # build the full url for the doc project
49     url_start="https://docs.onap.org"
50     url="${url_start}/${url_lang}/${url_branch}/${url_file}"
51   else
52     # build the full url for the other projects
53     url_start="https://docs.onap.org/projects/onap"
54     url="${url_start}-${url_repo}/${url_lang}/${url_branch}/${url_file}"
55   fi
56   #echo "DBUG: url=$url"
57
58   # check with curl if html page is accessible (no content check!)
59   # to prevent (server side) cached results a unique element is added to the request
60   curl --head --silent --fail "${url}?${unique}" >/dev/null
61   curl_result=$?
62
63   # "0" and "22" are expected as a curl result
64   if [ "${curl_result}" = "0" ]; then
65     curl_result="accessible"
66   elif [ "${curl_result}" = "22" ]; then
67     curl_result="does not exist"
68   fi
69
70   #echo -e "DBUG:       ${line}"
71   #echo -e "DBUG: ${curl_result} ${url}"
72   #echo " "
73
74   echo "${line},${url},${curl_result}"
75
76   ((i++))
77 done
78 unset array
79 unset i