]> begriffs open source - freertos/blob - .github/actions/url_verifier.sh
Do not call exit() on MSVC Port when calling vPortEndScheduler (#624)
[freertos] / .github / actions / url_verifier.sh
1 #!/bin/bash -
2
3 PROJECT=$1
4 echo "Verifying url links of: ${PROJECT}"
5 if [ ! -d "$PROJECT" ]
6 then
7     echo "Directory passed does not exist"
8     exit 2
9 fi
10
11 USER_AGENT="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.146 Safari/537.36"
12 SCRIPT_RET=0
13
14 set -o nounset        # Treat unset variables as an error
15
16 declare -A dict
17
18 function test {
19     while IFS= read -r LINE; do
20         FILE=$(echo $LINE | cut -f 1 -d ':')
21         URL=$(echo $LINE | grep -IoE '\b(https?|ftp|file)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]*[-A-Za-z0-9+&@#/%=~_|]')
22
23         # remove trailing / if it exists curl diferenciate between links with
24         # and without / at the end
25         # URL=`echo "$URL" | sed 's,/$,,'`
26         dict+=(["$URL"]="$FILE ")
27     done < <(grep -e 'https\?://' ${PROJECT} -RIa --exclude='*.exe' --exclude-dir=.git | tr '*' ' ')
28
29     for UNIQ_URL in ${!dict[@]} # loop urls
30     do
31      CURL_RES=$(curl -si --user-agent "$(USER_AGENT)" ${UNIQ_URL} 2>/dev/null| head -n 1 | cut -f 2 -d ' ')
32      RES=$?
33
34         if [ "${CURL_RES}" == '' -o "${CURL_RES}" != '200' ]
35         then
36             echo "URL is: ${UNIQ_URL}"
37             echo "File names: ${dict[$UNIQ_URL]}"
38             if [ "${CURL_RES}" == '' ]  # curl returned an error
39             then
40                 CURL_RES=$RES
41                 SCRIPT_RET=1
42                 echo ERROR: Result is: "${CURL_RES}"
43             elif [ "${CURL_RES}" == '403' ]
44             then
45                 SCRIPT_RET=1
46                 echo ERROR: Result is: "${CURL_RES}"
47             else
48                 echo WARNING: Result is: "${CURL_RES}"
49             fi
50             echo "================================="
51         fi
52     done
53
54     if [ "${SCRIPT_RET}" -eq 0 ]
55     then
56         exit 0
57     else
58         exit 1
59     fi
60 }
61
62 test