| 1 | #! /bin/bash |
| 2 | |
| 3 | J=6 |
| 4 | OUT_FILE=deprecated.txt |
| 5 | |
| 6 | if [ "$1" = "--help" ] || [ "$1" = "-h" ] || [ "$1" = "help" ]; then |
| 7 | cat <<EOF |
| 8 | $ check-for-deprecation.sh |
| 9 | Check all github apps in the readme for deprecation. |
| 10 | Running $J processes in parallel. |
| 11 | |
| 12 | Found deprecated repos are written to: $OUT_FILE |
| 13 | EOF |
| 14 | exit |
| 15 | fi |
| 16 | |
| 17 | check_if_archived_on_github() { |
| 18 | APPS=$(grep -e "- \[.\+\]\(.\+\)\s" readme.md | grep 'github.com' | awk -F "(" '{ print $2 }' | cut -d ")" -f1) |
| 19 | |
| 20 | check_deprecation() { |
| 21 | REPO="$1" |
| 22 | if nice curl -SsL "$REPO" | grep "This repository has been archived by the owner on" >/dev/null; then |
| 23 | echo "DEPRECATED $REPO" | tee -a $OUT_FILE |
| 24 | else |
| 25 | echo "CHECKED $REPO" |
| 26 | fi |
| 27 | } |
| 28 | |
| 29 | # parallel exec: https://unix.stackexchange.com/a/216475 |
| 30 | for app in $(echo $APPS); do |
| 31 | ((i=i%J)); ((i++==0)) && wait |
| 32 | check_deprecation "$app" & |
| 33 | done |
| 34 | } |
| 35 | |
| 36 | check_if_link_is_dead() { |
| 37 | command -v deadlink >/dev/null || { echo "deadlink is not installed" 1>&2; exit 127; } |
| 38 | |
| 39 | tmp=$(mktemp) |
| 40 | grep -Po "http[^)]+" readme.md | grep -v "https://github.com" >$tmp |
| 41 | deadlink check $tmp |
| 42 | } |
| 43 | |
| 44 | check_if_archived_on_github |
| 45 | check_if_link_is_dead |