From bc3a1f13fd5fddb9fa8f3ecff6144b512ed9d08b Mon Sep 17 00:00:00 2001 From: KatolaZ Date: Wed, 8 Jan 2020 07:45:14 +0000 Subject: initial commit --- parse_cgit | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100755 parse_cgit (limited to 'parse_cgit') diff --git a/parse_cgit b/parse_cgit new file mode 100755 index 0000000..34029fe --- /dev/null +++ b/parse_cgit @@ -0,0 +1,59 @@ +#!/bin/sh + +# +# Parse a cgit-style repo index provided on stdin +# + +if [ $# -lt 2 ]; then + printf "Usage: %s \n" $0 + exit 1 +fi + +FIN="/dev/stdin" +URLBASE="$1" +DEST="$2" + +SUBPATH="/plain" + +CURL="torify curl -Ls " + +PROTO=${URLBASE%%:\/\/*} +DIRBASE="$PROTO/${URLBASE##[a-z]*:\/\/}" +echo "proto: $PROTO" +echo "dirbase: $DIRBASE" + +READMES="README README.txt README.md readme readme.txt readme.md" + + +repos=$(${CURL} "$URLBASE" | xml2tsv | grep -Ei "/html/body/div/div/table/tr/td/a[[:blank:]]+title=" \ + | awk -F'\t' '{print $3,$4}' \ + | sed -E 's/href=//g;s/ /\|/'\ + ) + + +for r in $repos; do + printf "Retrieving repo %s...\n" $repo + link=$(echo "$r" | cut -d "|" -f 1 ) + name=$(echo "$r" | cut -d "|" -f 2 ) + baselink=$(printf "%s%s" $URLBASE $link) + REPODIR="$DEST/$DIRBASE/$link/" + mkdir -p $REPODIR + for f in $READMES; do + printf " trying file %s..." $baselink/$SUBPATH/$f + torify curl -Ls "$baselink/$SUBPATH/$f" > $REPODIR/$f + failure=$(xml2tsv < $REPODIR/$f 2>/dev/null | \ + grep -Eaic "/html/body/div/div/div[[:blank:]]+class=error[[:blank:]]+Not found") + echo $failure + if [ "$failure" != 0 ]; then + rm -f $REPODIR/$f + printf "[FAILED]\n" + else + printf "[OK]\n" + fi + #sleep 1 + done +done + +### the readme file is at REPLINK/plain/README + +### if not found, look for "/html/body/div/div/div class=error Not found" -- cgit v1.2.3