Signed-off-by: Thomas Kulik <thomas.kulik@telekom.de>
[doc.git] / tools / checkdocs.sh
1 #!/bin/bash
2 #set -x # uncomment for bash script debugging
3
4 ### ============================================================================
5 ### Licensed under the Apache License, Version 2.0 (the "License");
6 ### you may not use this file except in compliance with the License.
7 ### You may obtain a copy of the License at
8 ###
9 ###       http://www.apache.org/licenses/LICENSE-2.0
10 ###
11 ### Unless required by applicable law or agreed to in writing, software
12 ### distributed under the License is distributed on an "AS IS" BASIS,
13 ### WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 ### See the License for the specific language governing permissions and
15 ### limitations under the License.
16 ### ============LICENSE_END=====================================================
17
18 ###
19 ### checkdocs.sh
20 ###
21 ### AUTHOR(S):
22 ### Thomas Kulik, Deutsche Telekom AG, 2020
23 ###
24 ### DESCRIPTION:
25 ### Retrieves a full list of ONAP repos from gerrit inluding their state.
26 ### Clones all active repos of the ONAP master branch plus other requested ONAP
27 ### branches. Then the script does some docs related analyses depending on the
28 ### clone results. It creates logfiles containing filtered results. In addition
29 ### a table.csv is created which can be used to import it in a spreadsheed.
30 ### Also a zip-file is created which contains all the results.
31 ###
32 ### IMPORTANT:
33 ### - in the output, repo names are shown in square brackets for readability
34 ###   e.g [aai/aai-common]/docs/release-notes.rst
35 ### - in the table.csv file you see data for the requested branch if available.
36 ###   if not available, data is retrieved from the master branch. it will be
37 ###   denoted in round brackets, e.g. (3) (tox.ini)
38 ###
39 ### REQUIREMENTS:
40 ### curl
41 ### jq
42 ###
43
44 ###
45 ### SOME HELPING COMMANDS TO PROCESS LOG FILES:
46 ### create repo list
47 ### curl -s https://git.onap.org/ | grep "^<tr><td class='toplevel-repo'><a title='" | sed -r "s:^<tr><td class='toplevel-repo'><a title='::" | sed -r "s:'.*::"
48 ###
49 ### remove branchname from the line
50 ### cat frankfurt_repoclone.log | sed 's:frankfurt|::'
51 ###
52 ### list only image names
53 ### cat master_dockerimagesfull.log | grep image | sed -r 's:image\:::' | sed -r 's:^ +::' | sed '/^[[:space:]]*$/d'
54 ###
55 ### more interesting stuff ...
56 ### curl https://gerrit.onap.org/r/projects/?d
57 ### LONG:  curl -s 'https://gerrit.onap.org/r/projects/?d' | awk '{if(NR>1)print}' | jq -c '.[] | {id, state}' | sed -r 's:%2F:/:g' | sed -r 's:["{}]::g' | sed -r 's:id\:::' | sed -r 's:,state\::|:' | sed '/All-Projects/d' | sed '/All-Users/d'
58 ### SHORT: curl -s 'https://gerrit.onap.org/r/projects/?d' | awk '{if(NR>1)print}' | jq -c '.[] | {id, state}' | sed -r 's:%2F:/:g; s:["{}]::g; s:id\:::; s:,state\::|:; /All-Projects/d; /All-Users/d'
59 ###
60
61 script_version="1.5 (2021/03/29)"
62
63 # save command for the restart with logging enabled
64 command=$0
65 arguments=$@
66 fullcommand="${command} ${arguments}"
67
68 ###
69 ### functions
70 ###
71
72 # print usage
73 function usage() {
74   echo "                                                           "
75   echo " checkdocs.sh Version ${script_version}"
76   echo "                                                           "
77   echo " USAGE:                                                    "
78   echo "  ./checkdocs.sh <arguments>                               "
79   echo "                                                           "
80   echo " ARGUMENTS:                                                "
81   echo "  -u|--user username                                       "
82   echo "  linux foundation username used to clone ONAP repositories"
83   echo "                                                           "
84   echo "  -b|--branches branch1,branch2,branch3                    "
85   echo "  list of branches to be cloned. master is automatically   "
86   echo "  added to the list. do not add manually!                  "
87   echo "                                                           "
88   echo "  -d|--dev                                                 "
89   echo "  development-mode - limits number of repos to be cloned   "
90   echo "                                                           "
91 }
92
93 # draw a simple line
94 function drawline {
95   echo "*******************************************************************************"
96 }
97
98 # remove lockfile in case script is interrupted
99 trap InterruptedScript SIGINT SIGTERM SIGHUP SIGKILL SIGSTOP
100 function InterruptedScript {
101   echo " "
102   echo "Script was interrupted."
103   if [ -f $lockfile ] ; then
104     rm $lockfile
105   fi
106   exit 0
107 }
108
109 ###
110 ### arguments handling
111 ###
112
113 PARAMS=""
114
115 while (( "$#" )); do
116   case "$1" in
117     -d|--dev)
118       devmode="TRUE"
119       shift
120       ;;
121     -b|--branches)
122       if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
123         branches_csv=$2
124         shift 2
125       else
126         echo "Error: Argument for $1 is missing" >&2
127         usage
128         exit 1
129       fi
130       ;;
131     -u|--user)
132       if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
133         lfusername=$2
134         shift 2
135       else
136         echo "Error: Argument for $1 is missing" >&2
137         usage
138         exit 1
139       fi
140         ;;
141     -*|--*=) # unsupported flags
142       echo "Error: Unsupported argument $1" >&2
143       usage
144       exit 1
145       ;;
146     *) # preserve positional arguments
147       PARAMS="$PARAMS $1"
148       shift
149       ;;
150   esac
151 done
152
153 # set positional arguments in their proper place
154 eval set -- "$PARAMS"
155
156 # old: declare -a branches=("master" "frankfurt" "guilin")
157 if [[ $branches_csv == "" || $lfusername == "" ]]; then
158   usage
159   exit -1
160 fi
161
162 # master branch is automatically added and must not part of the user arguments
163 if [[ $branches_csv == *"master"* ]]; then
164   usage
165   exit -1
166 fi
167 # clone master first, then the other branches
168 branches_csv="master,${branches_csv}"
169
170 # create the branches array by readinging in the values from the variable
171 IFS=',' read -r -a branches <<< "${branches_csv}"
172
173 #echo "DBUG: devmode      = \"${devmode}\""
174 #echo "DBUG: branches_csv = \"${branches_csv}\""
175 #echo "DBUG: lfusername   = \"${lfusername}\""
176 #echo "DBUG: branches     = \"${branches[@]}\""
177
178 # restart script with logging enabled
179 lockfile="checkdocs-runtime-lockfile"
180 if [ ! -f $lockfile ] ; then
181   touch $lockfile
182   echo "Restarting script with logging enabled."
183   ${fullcommand} 2>&1 | tee checkdocs.log
184   rm $lockfile
185   exit
186 fi
187
188 echo " "
189 echo "checkdocs.sh Version ${script_version}"
190 echo " "
191
192 # curl must be installed
193 if ! command -v curl &> /dev/null
194 then
195   echo "ERROR: curl command could not be found"
196   exit -1
197 fi
198
199 today=$(date '+%Y-%m-%d');
200 repolist="gerrit-repos-master-"$today".txt";
201 unique=$(date +%s)
202
203 echo "Retrieving a full list of ONAP repositories (master) from gerrit.onap.org."
204
205 # retrieve the full repolist from gerrit
206 # workaround because of the (wrong?) response of gerrit.onap.org which makes jq command fail
207 # "| awk '{if(NR>1)print}'" filters the first line of the response so that jq will work again (thx marek)
208 curl -s 'https://gerrit.onap.org/r/projects/?d' | awk '{if(NR>1)print}' | jq -c '.[] | {id, state}' | sed -r 's:%2F:/:g; s:["{}]::g; s:id\:::; s:,state\::|:; /All-Projects/d; /All-Users/d' >./$repolist
209
210 # process the created repolist and try to clone the projects from the mirror
211
212 source="git://cloud.onap.org/mirror"
213 echo "Using \"${source}\" as the source and username \"${lfusername}\" for cloning the repositories."
214 echo "Start cloning of repositories ..."
215
216 for branch in "${branches[@]}"
217 do
218
219   echo " "
220   echo "###"
221   echo "### ${branch}"
222   echo "###"
223   echo " "
224
225   branch_upper=$(echo "${branch}" | tr '[:lower:]' '[:upper:]')
226
227   mkdir $branch
228   cp $repolist $branch
229   cd $branch
230
231   devcounter=0
232
233   # process repolist
234   while read line
235   do
236
237   if [[ $devmode == "TRUE" ]]; then
238     devcounter=$((devcounter+1))
239   fi
240
241   if [[ $devcounter -lt "50" ]]; then
242
243       if [[ $devmode == "TRUE" ]]; then
244         echo "INFO: devmode! counter=${devcounter}"
245       fi
246
247       drawline
248       reponame=$(echo $line | awk -F "|" '{print $1}');
249       repostate=$(echo $line | awk -F "|" '{print $2}');
250       echo $reponame
251       echo $repostate
252
253       if [[ $repostate == "ACTIVE" ]] || [[ $repostate == "READ_ONLY" ]]; then
254         echo "Cloning \"${branch}\" branch of \"${repostate}\" project ${reponame}..."
255
256         # previously used:   git clone --branch ${branch} --recurse-submodules ssh://${lfusername}@gerrit.onap.org:29418/$reponame ./$reponame
257         # clone script Jess: git clone "git://cloud.onap.org/mirror/${i}" "${LOCALNAME}"
258         git clone --branch ${branch} --recurse-submodules ${source}/${reponame} ./${reponame}
259         gitexitcode=$?
260
261         if [[ ! ${gitexitcode} == "0" ]]; then
262           errormsg=$(tail -1 ../checkdocs.log)
263         else
264           errormsg="cloned"
265         fi
266
267         # repoclone.log format:  $1=gitexitcode|$2=reponame|$3=repostate|$4=errormsg
268         echo "${gitexitcode}|${reponame}|${repostate}|${errormsg}" | tee -a ${branch}_repoclone.log
269
270       #elif [[ $repostate == "READ_ONLY" ]]; then
271         #echo "-|${reponame}|${repostate}|ignored" | tee -a ${branch}_repoclone.log
272       else
273         echo "-|${reponame}|unknown repo state \"${repostate}\"|-" | tee -a ${branch}_repoclone.log
274       fi
275
276       # examine repo
277       if [[ ${gitexitcode} == "0" ]]; then
278
279         printf "\ndocs directories:\n"
280         find ./$reponame -type d -name docs | sed -r 's:./::' | sed -r s:${reponame}:[${reponame}]: | tee -a ${branch}_docs.log
281
282         printf "\nrst files:\n"
283         find ./$reponame -type f -name *.rst | sed -r 's:./::' | sed -r s:${reponame}:[${reponame}]: | tee -a ${branch}_rstfiles.log
284
285         printf "\nrelease notes rst:\n"
286         find ./$reponame -type f | grep 'release.*note.*.rst' | sed -r 's:./::' | sed -r s:${reponame}:[${reponame}]: | tee -a ${branch}_releasenotes.log
287
288         printf "\ntox.ini files:\n"
289         find ./$reponame -type f -name tox.ini | sed -r 's:./::' | sed -r s:${reponame}:[${reponame}]: | tee -a ${branch}_toxini.log
290
291         printf "\nconf.py files:\n"
292         find ./$reponame -type f -name conf.py | sed -r 's:./::' | sed -r s:${reponame}:[${reponame}]: | tee -a ${branch}_confpy.log
293
294         printf "\nindex.rst files:\n"
295         find ./$reponame -type f -name index.rst | sed -r 's:./::' | sed -r s:${reponame}:[${reponame}]: | tee -a ${branch}_indexrst.log
296
297         printf "\nINFO.yaml files:\n"
298         find ./$reponame -type f -name INFO.yaml | sed -r 's:./::' | sed -r s:${reponame}:[${reponame}]: | tee -a ${branch}_infoyaml.log
299
300       fi
301
302     # end defcounter loop
303     fi
304
305     gitexitcode=""
306
307   done <${repolist}
308
309   # examine repos
310   drawline
311   find . -type f -name values.yaml -print -exec grep "image:" {} \; | sed -r 's:^ +::' | tee ${branch}_dockerimagesfull.log
312   drawline
313   ls --format single-column -d */ | sed 's:/$::' | tee ${branch}_directories.log
314   drawline
315   cat ${branch}_dockerimagesfull.log | grep image | sed -r 's:image\:::' | sed -r 's:^ +::' | sed '/^[[:space:]]*$/d' >${branch}_dockerimages.log
316   drawline
317   ls --format single-column -d oom/kubernetes/*/ | tee ${branch}_oomkubernetes.log
318   drawline
319
320   # examine docs
321   readarray -t docs_array < ./${branch}_docs.log;
322
323   for line in "${docs_array[@]}"
324   do
325
326     echo $line | tee -a ${branch}_docsconfig.log
327
328     # remove [ and ] which are distinguish the project name in the output
329     line=$(echo $line | sed -r 's:\[:: ; s:\]::')
330
331     if [ -f ./${line}/conf.py ] ; then
332       echo "  conf.py ..... found" | tee -a ${branch}_docsconfig.log
333     else
334       echo "  conf.py ..... NOT FOUND" | tee -a ${branch}_docsconfig.log
335     fi
336
337     if [ -f ./${line}/index.rst ] ; then
338       echo "  index.rst ... found" | tee -a ${branch}_docsconfig.log
339     else
340       echo "  index.rst ... NOT FOUND" | tee -a ${branch}_docsconfig.log
341     fi
342
343     if [ -f ./${line}/tox.ini ] ; then
344       echo "  tox.ini ..... found" | tee -a ${branch}_docsconfig.log
345     else
346       echo "  tox.ini ..... NOT FOUND" | tee -a ${branch}_docsconfig.log
347     fi
348
349     echo " " | tee -a ${branch}_docsconfig.log
350
351   done
352   unset docs_array
353
354   drawline
355
356   ###
357   ### build a csv table that combines results
358   ###
359
360   #
361   # csv column #1: project name
362   #
363
364   readarray -t array < ./${repolist};
365   i=0
366   csv[i]="project"
367   ((i++))
368   for line in "${array[@]}"
369   do
370     reponame=$(echo $line | awk -F "|" '{print $1}');
371     project=$(echo $reponame | sed 's:/.*$::')
372     #echo "DBUG: reponame=${reponame}"
373     #echo "DBUG:  project=${project}"
374     #echo "DBUG:        i=${i}"
375     csv[i]=${project}
376     ((i++))
377   done
378   unset array
379   unset i
380   unset reponame
381   unset project
382
383   #
384   # csv column #2: repo name
385   #
386
387   readarray -t array < ./${repolist};
388   i=0
389   csv[i]="${csv[i]},MASTER repo name"
390   ((i++))
391   for line in "${array[@]}"
392   do
393     reponame=$(echo $line | awk -F "|" '{print $1}');
394     csv[i]="${csv[i]},${reponame}"
395     ((i++))
396   done
397   unset array
398   unset i
399   unset reponame
400
401   #
402   # csv column #3: repo state
403   #
404
405   readarray -t array < ./${repolist};
406   i=0
407   csv[i]="${csv[i]},MASTER repo state"
408   ((i++))
409   for line in "${array[@]}"
410   do
411     repostate=$(echo $line | awk -F "|" '{print $2}');
412     csv[i]="${csv[i]},${repostate}"
413     ((i++))
414   done
415   unset array
416   unset i
417   unset repostate
418
419   #
420   # csv column #4: clone message
421   #
422
423   readarray -t array < ./${branch}_repoclone.log;
424   i=0
425   csv[i]="${csv[i]},${branch_upper} clone message"
426   ((i++))
427   for line in "${array[@]}"
428   do
429     # repoclone.log format:  $1=gitexitcode|$2=reponame|$3=repostate|$4=errormsg
430     errormsg=$(echo $line | awk -F "|" '{print $4}');
431     csv[i]="${csv[i]},${errormsg}"
432     ((i++))
433   done
434   unset array
435   unset i
436   unset errormsg
437
438   #
439   # csv column #5: lifecycle state
440   # extracted from the INFO.yaml
441   #
442
443   readarray -t array < ./${repolist};
444   i=0
445   csv[i]="${csv[i]},project lifecycle state"
446   ((i++))
447   for line in "${array[@]}"
448   do
449     reponame=$(echo $line | awk -F "|" '{print $1}');
450     if [ -f ./${reponame}/INFO.yaml ] ; then
451       # check if repo/branch has a INFO.yaml
452       lifecycleproject=$(grep '^project: ' ./${reponame}/INFO.yaml | awk -F ":" '{print $2}' | sed 's:^ ::' | sed "s:'::g" | tr '[:upper:]' '[:lower:]' | sed 's/\r$//')
453       lifecyclestate=$(grep '^lifecycle_state: ' ./${reponame}/INFO.yaml | awk -F ":" '{print $2}' | sed 's:^ ::' | sed "s:'::g" | tr '[:upper:]' '[:lower:]' | sed 's/\r$//')
454     elif [ ${branch} != "master" ] && [ -f ../master/${reponame}/INFO.yaml ] ; then
455       # if current branch is not master AND if info.yaml not found in the current repo/branch THAN use INFO.yaml of repo/master if available
456       #echo "DBUG: branch=${branch} - checking master for INFO.yaml"
457       lifecycleproject=$(grep '^project: ' ../master/${reponame}/INFO.yaml | awk -F ":" '{print $2}' | sed 's:^ ::' | sed "s:'::g" | tr '[:upper:]' '[:lower:]' | sed 's/\r$//')
458       lifecyclestate=$(grep '^lifecycle_state: ' ../master/${reponame}/INFO.yaml | awk -F ":" '{print $2}' | sed 's:^ ::' | sed "s:'::g" | tr '[:upper:]' '[:lower:]' | sed 's/\r$//')
459       lifecyclestate="(${lifecyclestate})"
460     else
461       lifecyclestate="INFO.yaml not found"
462     fi
463     #echo "DBUG: working dir is ...";pwd
464     #echo "DBUG: lifecycleproject=${lifecycleproject}"
465     #echo "DBUG:   lifecyclestate=${lifecyclestate}"
466     csv[i]="${csv[i]},${lifecyclestate}"
467     ((i++))
468   done
469   unset array
470   unset i
471   unset lifecycleproject
472   unset lifecyclestate
473
474   #
475   # csv column #6: RELEASE component (yes|maybe|unknown)
476   # to be filled with values of the planned release config file maintained by
477   # the onap release manager
478   #
479
480   # repoclone.log format:  $1=gitexitcode|$2=reponame|$3=repostate|$4=errormsg
481   readarray -t array < ./${branch}_repoclone.log;
482   i=0
483   csv[i]="${csv[i]},${branch_upper} component"
484   ((i++))
485   for line in "${array[@]}"
486   do
487
488     # repoclone.log format:  $1=gitexitcode|$2=reponame|$3=repostate|$4=errormsg
489     gitexitcode=$(echo $line | awk -F "|" '{print $1}');
490        reponame=$(echo $line | awk -F "|" '{print $2}');
491       repostate=$(echo $line | awk -F "|" '{print $3}');
492        errormsg=$(echo $line | awk -F "|" '{print $4}');
493
494     if [[ ${repostate} == "ACTIVE" && ${gitexitcode} == "0" ]]; then
495       releasecomponent="yes"
496     elif [ ${repostate} == "ACTIVE" ]; then
497     #elif [[ ${repostate} == "ACTIVE" && ${gitexitcode} == "128" ]]; then
498       releasecomponent="maybe"
499     elif [[ ${repostate} == "READ_ONLY" && ${gitexitcode} == "0" ]]; then
500       releasecomponent="yes"
501     elif [ ${repostate} == "READ_ONLY" ]; then
502       releasecomponent="maybe"
503     else
504       releasecomponent="unknown"
505     fi
506
507     csv[i]="${csv[i]},${releasecomponent}"
508     ((i++))
509   done
510   unset array
511   unset i
512   unset gitexitcode
513   unset reponame
514   unset repostate
515   unset errormsg
516   unset releasecomponent
517
518   #
519   # csv column #7:  docs (at repo root directory only; no recursive search!)
520   # csv column #8:  conf.py
521   # csv column #9:  tox.ini
522   # csv column #10: index.rst
523   #
524   # columns are filled with values from requested branch.
525   # if data is not available values from master branch are used.
526   # to identify master branch values, data is put into brackets "(...)"
527   #
528
529   readarray -t array < ./${repolist};
530   i=0
531   csv[$i]="${csv[i]},docs,conf.py,tox.ini,index.rst"
532   ((i++))
533   for line in "${array[@]}"
534   do
535     line=$(echo $line | sed 's:|.*$::')
536     #echo "DBUG: line=${line}"
537     #echo "DBUG: i=${i}"
538
539     # docs
540     if [ -d ./${line}/docs ] ; then
541       docs="docs"
542     elif [ -d ../master/${line}/docs ] ; then
543       docs="(docs)"
544     else
545       docs="-"
546     fi
547
548     # conf.py
549     if [ -f ./${line}/docs/conf.py ] ; then
550       docs="${docs},conf.py"
551     elif [ -f ../master/${line}/docs/conf.py ] ; then
552       docs="${docs},(conf.py)"
553     else
554       docs="${docs},-"
555     fi
556
557     # tox.ini
558     if [ -f ./${line}/docs/tox.ini ] ; then
559       docs="${docs},tox.ini"
560     elif [ -f ../master/${line}/docs/tox.ini ] ; then
561       docs="${docs},(tox.ini)"
562     else
563       docs="${docs},-"
564     fi
565
566     # index.rst
567     if [ -f ./${line}/docs/index.rst ] ; then
568       docs="${docs},index.rst"
569     elif [ -f ../master/${line}/docs/index.rst ] ; then
570       docs="${docs},(index.rst)"
571     else
572       docs="${docs},-"
573     fi
574
575     #echo "DBUG: docs=${docs}"
576     line="${csv[i]},${docs}"
577     csv[$i]=${line}
578     ((i++))
579   done
580   unset array
581   unset i
582   unset docs
583
584   #
585   # csv column #11: index.html@RTD accessibility check
586   # csv column #12: index.html url
587   #
588
589   readarray -t array < ./${branch}_repoclone.log;
590   i=0
591   csv[i]="${csv[i]},index.html@RTD,index.html url"
592   ((i++))
593   for line in "${array[@]}"
594   do
595     # repoclone.log format:  $1=gitexitcode|$2=reponame|$3=repostate|$4=errormsg
596     gitexitcode=$(echo $line | awk -F "|" '{print $1}');
597        reponame=$(echo $line | awk -F "|" '{print $2}');
598       repostate=$(echo $line | awk -F "|" '{print $3}');
599        errormsg=$(echo $line | awk -F "|" '{print $4}');
600
601             url=""
602     curl_result=""
603
604     # this script works only with release "frankfurt" and later because
605     # earlier releases are using submodule structure for documentation files
606     if echo "$branch" | grep -q '^[abcde]'; then
607       curl_result="unsupported release"
608       url="-"
609     else
610
611       # we are working on "frankfurt" branch or later ...
612       if [[ ${repostate} == "ACTIVE" ]] || [[ ${repostate} == "READ_ONLY" ]]; then
613
614         # OPTIONAL: USE ALSO GITEXITCODE AS A FILTER CRITERIA ???
615
616         # url base
617         # important! only doc project needs a different url base
618         if [[ ${reponame} == "doc" ]]; then
619           url_start="https://docs.onap.org"
620         else
621           url_start="https://docs.onap.org/projects/onap"
622         fi
623         url_lang="en"
624         url_branch=${branch}
625
626         # "master" branch documentation is available as "latest" in RTD
627         if [[ ${url_branch} == "master" ]]; then
628           url_branch="latest"
629         fi
630
631         # replace all / characters in repo name with - charachter
632         url_repo=$(echo ${reponame} | sed -r 's/\//-/g')
633         url_file="index.html"
634
635         # build the full url
636         if [[ ${reponame} == "doc" ]]; then
637           # build the full url for the doc project
638           url="${url_start}/${url_lang}/${url_branch}/${url_file}"
639         else
640           # build the full url for the other projects
641           url="${url_start}-${url_repo}/${url_lang}/${url_branch}/${url_file}"
642         fi
643         #echo "DBUG: url=$url"
644
645         # test accessibility of url
646         curl --head --silent --fail "${url}?${unique}" >/dev/null
647         curl_result=$?
648
649         # convert numeric results to text
650         if [ "${curl_result}" = "0" ]; then
651           curl_result="accessible"
652         elif [ "${curl_result}" = "22" ]; then
653           curl_result="does not exist"
654         else
655           curl_result="ERROR:${curl_result}"
656         fi
657
658         # url does not exist for this branch.
659         # in case the requested url is not already for "master" branch,
660         # we try to access the url of the master branch and denote the
661         # result by using round brackets (result)
662         if [[ ${curl_result} == "does not exist" && ! $branch == "master" ]]; then
663
664           # build the full (master/latest) url
665           url="${url_start}-${url_repo}/${url_lang}/latest/${url_file}"
666           #echo "DBUG: url=$url"
667
668           # test accessibility of url in "master branch" (latest)
669           curl --head --silent --fail "${url}?${unique}" >/dev/null
670           curl_result=$?
671           # denote result as a value from "master" branch (latest)
672           url="(${url})"
673
674           # convert numeric results to text
675           if [ "${curl_result}" = "0" ]; then
676             curl_result="(accessible)"
677           elif [ "${curl_result}" = "22" ]; then
678             curl_result="(does not exist)"
679           else
680             curl_result="(ERROR:${curl_result})"
681           fi
682
683         fi
684       else
685         # repostate IS NOT ACTIVE OR READ_ONLY - no curl test required
686         curl_result="-"
687         url="-"
688       fi
689     fi
690
691     echo "$url ... $curl_result"
692     csv[i]="${csv[i]},${curl_result},${url}"
693     #echo "DBUG: csv line=${csv[i]}"
694
695     ((i++))
696   done
697
698   #
699   # csv column #13: release notes
700   #
701
702   readarray -t array < ../${repolist};
703   i=0
704   csv[i]="${csv[i]},release notes"
705   ((i++))
706   for line in "${array[@]}"
707   do
708     line=$(echo $line | sed 's:|.*$::')
709     #echo "DBUG: line=\"${line}\""
710     #echo "DBUG: i=${i}"
711     relnote=""
712
713     # put repo name in square brackets for increased grep hit rate
714     # escape minus and bracket characters to avoid problems with the grep command
715     #repo_grepable=$(echo ${line} | sed -r s:${line}:[${line}]: | sed -r 's/-/\\-/g' | sed -r 's/\[/\\[/g' | sed -r 's/\]/\\]/g')
716     #echo "DBUG: repo_grepable=\"${repo_grepable}\""
717
718     # check if repo dir exists in this branch
719     if [ -d ./${line} ] ; then
720       # if yes, check if repo name appears in the branch releasenotes.log
721       relnote=$(find "./${line}" -type f | grep 'release.*note.*.rst' | wc -l);
722       #echo "DBUG: relnote=${relnote}"
723       # repo dir DOES NOT exist in this branch - so check if repo dir exists in MASTER branch
724     elif [ -d ../master/${line} ] ; then
725       # if yes, check if repo name appears in the MASTER releasenotes.log
726       # count release notes files in MASTER branch (in repo root and its subdirectories)
727       relnote=$(find "../master/${line}" -type f | grep 'release.*note.*.rst' | wc -l);
728       #echo "DBUG: relnote=${relnote}"
729       # put results in round brackets to show that this is MASTER data
730       relnote=$(echo ${relnote} | sed -r s:${relnote}:\(${relnote}\):)
731     else
732       relnote="-"
733     fi
734     #echo "DBUG: relnote=${relnote}"
735
736     line="${csv[i]},${relnote}"
737     csv[i]=${line}
738     ((i++))
739
740   done
741   unset array
742   unset i
743   unset relnote
744   unset repo_grepable
745
746   #
747   # build the table.csv file
748   #
749
750   for i in "${csv[@]}"
751   do
752     echo "$i" | tee -a ./${branch}_table.csv
753   done
754
755   #
756   # create data package for this branch and zip it
757   #
758
759   datadir=${branch}_data
760   mkdir $datadir
761   cp $repolist $datadir
762   cp ${branch}_table.csv $datadir
763   cp ${branch}_*.log $datadir
764   zip -r ${datadir}.zip $datadir
765
766   # return from the branch directory
767   cd ..
768
769 # return and work on the next requested branch ... or exit
770 done