4 echo "Verifying url links of: ${PROJECT}"
7 echo "Directory passed does not exist"
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"
14 set -o nounset # Treat unset variables as an error
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+&@#/%=~_|]')
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 '*' ' ')
29 for UNIQ_URL in ${!dict[@]} # loop urls
31 CURL_RES=$(curl -si --user-agent "$(USER_AGENT)" ${UNIQ_URL} 2>/dev/null| head -n 1 | cut -f 2 -d ' ')
34 if [ "${CURL_RES}" == '' -o "${CURL_RES}" != '200' ]
36 echo "URL is: ${UNIQ_URL}"
37 echo "File names: ${dict[$UNIQ_URL]}"
38 if [ "${CURL_RES}" == '' ] # curl returned an error
42 echo ERROR: Result is: "${CURL_RES}"
43 elif [ "${CURL_RES}" == '403' ]
46 echo ERROR: Result is: "${CURL_RES}"
48 echo WARNING: Result is: "${CURL_RES}"
50 echo "================================="
54 if [ "${SCRIPT_RET}" -eq 0 ]