-
Notifications
You must be signed in to change notification settings - Fork 276
/
check_manually.sh
executable file
·79 lines (64 loc) · 1.7 KB
/
check_manually.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
SOURCE_FILE=README.md
function check_deprecated_repos() {
GITHUB_LINKS=$(grep -o "https://github.com/.*" "$SOURCE_FILE" \
| sed 's|).*||')
mapfile -t GITHUB_LINKS <<< "$GITHUB_LINKS"
for link in "${GITHUB_LINKS[@]}"; do
echo "Checking if repo $link is not deprecated"
DEPRECATED=$(curl "$link" -s | awk -v depr_repo_res='false' \
'/This repository has been archived by the owner. It is now read-only./ \
{depr_repo_res="true"} END {print depr_repo_res}')
if [[ "$DEPRECATED" == "true" ]]; then
deprecated_repos+=("$link")
fi
done
if [ -n "${deprecated_repos[*]}" ]; then
depr_repo_res=1
fi
}
function check_false_links() {
LINKS=$(grep -oP "http.*" "$SOURCE_FILE" \
| sed -e "s|)$||" -e "s|).*||" \
| grep -v img.shields.io \
| grep -v travis-ci.org)
mapfile -t LINKS <<< "$LINKS"
for link in "${LINKS[@]}"
do
echo "Checking $link"
STATUS_CODE="$(curl -LI "$link" -o /dev/null -w '%{http_code}\n' -s)"
if [[ "$STATUS_CODE" != "200" ]]
then
bad_links+=("$link")
fi
done
if [ -n "${bad_links[*]}" ]
then
link_res=1
fi
}
function check_links() {
local depr_repo_res=0
local deprecated_repos
check_deprecated_repos
local link_res=0
local bad_links
check_false_links
clear
if [[ link_res -eq "1" ]]; then
echo "Unreachable links were found:"
for link in "${bad_links[@]}"; do
echo "$link"
done
fi
if [[ depr_repo_res -eq "1" ]]; then
echo "Deprecated repo were found:"
for link in "${deprecated_repos[@]}"; do
echo "$link"
done
fi
if [[ depr_repo_res -eq 0 && link_res -eq 0 ]]; then
echo "All links are validated!"
fi
}
check_links