02574f83b58b73f8006838e1c0b9188dd9450aea
[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_start="https://docs.onap.org/projects/onap"
14   url_lang="en"
15 url_branch=${branch}
16 unique=$(date +%s)
17
18 # "master" docs are available as "latest" in read-the-docs
19 if [ "${url_branch}" = "master" ]; then
20   url_branch="latest"
21 fi
22
23 #readarray -t array < ./${branch}_releasenotes.log;
24 readarray -t array < ${file_to_process};
25 for line in "${array[@]}"
26 do
27
28   # example line: [dmaap/messagerouter/messageservice]/docs/release-notes/release-notes.rst
29   # example url:  https://docs.onap.org/projects/onap-dmaap-messagerouter-messageservice/en/frankfurt/release-notes/release-notes.html
30
31   # extract repo name which comes in square bracktes ([...]) and convert slash (/) to minus (-)
32   # line:   [dmaap/messagerouter/messageservice]/docs/release-notes/release-notes.rst
33   # output:  dmaap-messagerouter-messageservice
34   url_repo=$(echo ${line} | sed -r 's/].+$//' | sed -r 's/\[//' | sed -r 's/\//-/g')
35
36   # extract rst filename and its path; replace .rst ending with .html
37   # warning: path does not always contain "docs"!
38   # line:   [dmaap/messagerouter/messageservice]/docs/release-notes/release-notes.rst
39   # output:                                           release-notes/release-notes.html
40   url_file=$(echo ${line} | sed -r 's/^.+\]//' | sed -r 's/^.*docs\///' | sed -r 's/\.rst$/\.html/' )
41
42   # build the full url
43   url="${url_start}-${url_repo}/${url_lang}/${url_branch}/${url_file}"
44
45   # check with curl if html page is accessible (no content check!)
46   # to prevent (server side) cached results a unique element is added to the request
47   curl --head --silent --fail "${url}?${unique}" >/dev/null
48   curl_result=$?
49
50   # "0" and "22" are expected as a curl result
51   if [ "${curl_result}" = "0" ]; then
52     curl_result="accessible"
53   elif [ "${curl_result}" = "22" ]; then
54     curl_result="NOT ACCESSIBLE"
55   fi
56
57   #echo -e "DBUG:       ${line}"
58   #echo -e "DBUG: ${curl_result} ${url}"
59   #echo " "
60
61   echo "${line},${url},${curl_result}"
62
63   ((i++))
64 done
65 unset array
66 unset i