update link to upper-constraints.txt
[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   #reponame="[${reponame}]"
31   #echo "DBUG: reponame=${reponame}"
32
33   # example line: [dmaap/messagerouter/messageservice]/docs/release-notes/release-notes.rst
34   # example url:  https://docs.onap.org/projects/onap-dmaap-messagerouter-messageservice/en/frankfurt/release-notes/release-notes.html
35
36   # extract repo name which comes in square bracktes ([...]) and convert slash (/) to minus (-)
37   # line:   [dmaap/messagerouter/messageservice]/docs/release-notes/release-notes.rst
38   # output:  dmaap-messagerouter-messageservice
39   url_repo=$(echo ${line} | sed -r 's/].+$//' | sed -r 's/\[//' | sed -r 's/\//-/g')
40
41   # extract rst filename and its path; replace .rst ending with .html
42   # warning: path does not always contain "docs"!
43   # line:   [dmaap/messagerouter/messageservice]/docs/release-notes/release-notes.rst
44   # output:                                           release-notes/release-notes.html
45   url_file=$(echo ${line} | sed -r 's/^.+\]//' | sed -r 's/^.*\/docs\///' | sed -r 's/\.rst$/\.html/' )
46
47   #echo "DBUG:     line = ${line}"
48   #echo "DBUG: url_file = ${url_file}"
49   #echo "DBUG: url_repo = ${url_repo}"
50   #echo "DBUG: reponame = ${reponame}"
51
52   # build the full url
53   if [[ ${reponame} == "doc" ]]; then
54     # build the full url for the doc project
55     url_start="https://docs.onap.org"
56     url="${url_start}/${url_lang}/${url_branch}/${url_file}"
57   else
58     # build the full url for the other projects
59     url_start="https://docs.onap.org/projects/onap"
60     url="${url_start}-${url_repo}/${url_lang}/${url_branch}/${url_file}"
61   fi
62
63   #echo "DBUG:      url = $url"
64
65   # check with curl if html page is accessible (no content check!)
66   # to prevent (server side) cached results a unique element is added to the request
67   curl --head --silent --fail "${url}?${unique}" >/dev/null
68   curl_result=$?
69
70   # "0" and "22" are expected as a curl result
71   if [ "${curl_result}" = "0" ]; then
72     curl_result="accessible"
73   elif [ "${curl_result}" = "22" ]; then
74     curl_result="does not exist"
75   fi
76
77   #echo -e "DBUG:       ${line}"
78   #echo -e "DBUG: ${curl_result} ${url}"
79   #echo " "
80
81   echo "${line},${url},${curl_result}"
82
83   ((i++))
84 done
85 unset array
86 unset i