Last active
June 4, 2018 19:45
-
-
Save h3/e05b3dac8517f4d26c13aa4a6ecc2125 to your computer and use it in GitHub Desktop.
Check recursively if repositories have been migrated to Gitlab
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Example usage: | |
# | |
# $ ./github-exodus.sh . | |
# $ ./github-exodus.sh venv/src/ | |
# | |
README_EXTENSIONS=('.md' '.rst' '.txt' '') | |
if [ -v "$1" ]; then | |
DIR="$1" | |
else | |
DIR=`pwd` | |
fi | |
function check_readme { | |
rawurl="${1/https:\/\/github/https:\/\/raw.githubusercontent}/master/README$2" | |
out=$(curl -k --silent -L -w "\n%{http_code}" $rawurl 2>&1) | |
status_code="${out##*$'\n'}" | |
content="${out%$'\n'*}" | |
} | |
for repo in $(find venv/src/ -name 'config' -type f -print0 | xargs -0 grep -ho 'github.com\/.*'); do | |
url="https://${repo%.*}" | |
for ext in ${README_EXTENSIONS[@]}; do | |
check_readme $url $ext | |
if [ "$status_code" -eq 200 ]; then | |
match=$(echo "$content" | grep 'https://gitlab.com/') | |
if [ $match ]; then | |
echo " - Likely moved: $url -> $match" | |
else | |
echo " - Checked: $url" | |
fi | |
break | |
else | |
sleep 1 | |
fi | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Oneliner using the raw URL: