mirror of
https://github.com/offa/android-foss.git
synced 2026-07-21 17:35:38 +02:00
Refactor check_manually to improve readability
This commit is contained in:
+68
-68
@@ -2,78 +2,78 @@
|
|||||||
|
|
||||||
SOURCE_FILE=README.md
|
SOURCE_FILE=README.md
|
||||||
|
|
||||||
LINKS=$(grep -oP "http.*" "$SOURCE_FILE" \
|
function check_deprecated_repos() {
|
||||||
| sed -e "s|)$||" -e "s|) .*||" \
|
GITHUB_LINKS=$(grep -o "https://github.com/.*" "$SOURCE_FILE" \
|
||||||
| grep -v img.shields.io \
|
|
||||||
| grep -v travis-ci.org)
|
|
||||||
|
|
||||||
mapfile -t LINKS <<< "$LINKS"
|
|
||||||
|
|
||||||
for link in "${LINKS[@]}"
|
|
||||||
do
|
|
||||||
echo "Testing $link"
|
|
||||||
STATUS_CODE="$(curl -LI "$link" -o /dev/null -w '%{http_code}\n' -s)"
|
|
||||||
if [[ "$STATUS_CODE" != "200" ]]
|
|
||||||
then
|
|
||||||
FALSE_LINKS+=("$link")
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
FDROID_LINKS=$(grep -oP "https://f-droid.*" "$SOURCE_FILE" \
|
|
||||||
| sed "s|)].*||" \
|
|
||||||
| grep -v "https://f-droid.org/)")
|
|
||||||
|
|
||||||
mapfile -t FDROID_LINKS <<< "$FDROID_LINKS"
|
|
||||||
|
|
||||||
for link in "${FDROID_LINKS[@]}"
|
|
||||||
do
|
|
||||||
echo "Testing $link"
|
|
||||||
STATUS_CODE="$(curl -LI "$link" -o /dev/null -w '%{http_code}\n' -s)"
|
|
||||||
if [[ "$STATUS_CODE" != "200" ]]
|
|
||||||
then
|
|
||||||
FALSE_LINKS+=("$link")
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
if [ -n "${FALSE_LINKS[*]}" ]
|
|
||||||
then
|
|
||||||
clear
|
|
||||||
echo "Some links weren't reachable."
|
|
||||||
for link in "${FALSE_LINKS[@]}"
|
|
||||||
do
|
|
||||||
echo "$link"
|
|
||||||
done
|
|
||||||
exit 1
|
|
||||||
else
|
|
||||||
echo "No false link was found"
|
|
||||||
fi
|
|
||||||
|
|
||||||
GITHUB_LINKS=$(grep -o "https://github.com/.*" README.md \
|
|
||||||
| sed 's|).*||')
|
| sed 's|).*||')
|
||||||
|
|
||||||
mapfile -t GITHUB_LINKS <<< "$GITHUB_LINKS"
|
mapfile -t GITHUB_LINKS <<< "$GITHUB_LINKS"
|
||||||
|
|
||||||
for link in "${GITHUB_LINKS[@]}"
|
for link in "${GITHUB_LINKS[@]}"; do
|
||||||
do
|
|
||||||
echo "Checking if repo $link is not deprecated"
|
echo "Checking if repo $link is not deprecated"
|
||||||
DEPRECATED=$(curl "$link" -s | awk -v result='false' \
|
DEPRECATED=$(curl "$link" -s | awk -v depr_repo_res='false' \
|
||||||
'/This repository has been archived by the owner. It is now read-only./ \
|
'/This repository has been archived by the owner. It is now read-only./ \
|
||||||
{result="true"} END {print result}')
|
{depr_repo_res="true"} END {print depr_repo_res}')
|
||||||
if [[ "$DEPRECATED" == "true" ]]
|
if [[ "$DEPRECATED" == "true" ]]; then
|
||||||
then
|
deprecated_repos+=("$link")
|
||||||
GITHUB_DEPRECATED_LINKS+=("$link")
|
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ -n "${GITHUB_DEPRECATED_LINKS[*]}" ]
|
if [ -n "${deprecated_repos[*]}" ]; then
|
||||||
then
|
depr_repo_res=1
|
||||||
clear
|
fi
|
||||||
echo "Deprecated Github Repos were found:"
|
}
|
||||||
for link in "${GITHUB_DEPRECATED_LINKS[@]}"
|
|
||||||
do
|
function check_false_links() {
|
||||||
echo "$link"
|
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
|
done
|
||||||
exit 1
|
fi
|
||||||
else
|
|
||||||
echo "No deprecated repo was found"
|
if [[ depr_repo_res -eq "1" ]]; then
|
||||||
fi
|
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
|
||||||
Reference in New Issue
Block a user