Issue-ID: DOC-686
[doc.git] / tools / checkrtd.sh
1 #!/bin/bash
2 #set -x # uncomment for bash script debugging
3
4 branch=$1
5 file_to_process=$2
6
7 #
8 # NOTE: works NOT with elalto release and below because of the submodule structure used for documentation
9 #
10
11  url_start="https://docs.onap.org/projects/onap"
12   url_lang="en"
13 url_branch=${branch}
14
15 # "master" docs are available as "latest" in read-the-docs
16 if [ "${url_branch}" = "master" ]; then
17   url_branch="latest"
18 fi
19
20 #readarray -t array < ./${branch}_releasenotes.log;
21 readarray -t array < ${file_to_process};
22 for line in "${array[@]}"
23 do
24
25   # example line: [dmaap/messagerouter/messageservice]/docs/release-notes/release-notes.rst
26   # example url:  https://docs.onap.org/projects/onap-dmaap-messagerouter-messageservice/en/frankfurt/release-notes/release-notes.html
27
28   # extract repo name which comes in square bracktes ([...]) and convert slash (/) to minus (-)
29   # line:   [dmaap/messagerouter/messageservice]/docs/release-notes/release-notes.rst
30   # output:  dmaap-messagerouter-messageservice
31   url_repo=$(echo ${line} | sed -r 's/].+$//' | sed -r 's/\[//' | sed -r 's/\//-/g')
32
33   # extract rst filename and its path; replace .rst ending with .html
34   # warning: path does not always contain "docs"!
35   # line:   [dmaap/messagerouter/messageservice]/docs/release-notes/release-notes.rst
36   # output:                                           release-notes/release-notes.html
37   url_file=$(echo ${line} | sed -r 's/^.+\]//' | sed -r 's/^.*docs\///' | sed -r 's/\.rst$/\.html/' )
38
39   # build the full url
40   url="${url_start}-${url_repo}/${url_lang}/${url_branch}/${url_file}"
41
42   # check with curl if html page is accessible (no content check!)
43   curl --head --silent --fail "${url}" >/dev/null
44   curl_result=$?
45
46   # "0" and "22" are expected as a curl result
47   if [ "${curl_result}" = "0" ]; then
48     curl_result="ok   "
49   elif [ "${curl_result}" = "22" ]; then
50     curl_result="ERROR"
51   fi
52
53   echo -e "DBUG:       ${line}"
54   echo -e "DBUG: ${curl_result} ${url}"
55   echo " "
56
57   ((i++))
58 done
59 unset array
60 unset i