#!/bin/bash
cd "$( dirname "$0" )" || exit
typeset -i iTotal

typeset -i iErr
typeset -i iWarn


# ----------------------------------------------------------------------
# FUNCTIONS
# ----------------------------------------------------------------------

function getChecks(){
    grep "inc_pluginfunctions" * 2>/dev/null | cut -f 1 -d ":" | grep -vE "^(zz_|inc)"
}

# ----------------------------------------------------------------------
# MAIN
# ----------------------------------------------------------------------

iTotal=$( getChecks | wc -l )
echo
echo "CHECK IML CHECKS - $( date )"
echo
for check in $( getChecks )
do
    if ./$check -h 2>/dev/null| grep -q "https://os-docs.iml.unibe.ch"; then
        # echo "✅ OK $check"
        url=$( ./$check -h | grep "https://os-docs.iml.unibe.ch" )
        if curl -sI $url | grep -q "200 OK"; then
            echo "✅ OK   : $check"
        else
            echo "⚠️ WARN : $check - $url"
            iWarn+=1
        fi
    else
        echo "❌ ERROR: $check"
        iErr+=1
        # ./$check -h
    fi 
done

echo
echo "---- Total   : $iTotal"
echo "  Errors     : $iErr checks with wrong help"
echo "  Warnings   : $iWarn checks with wrong url"
echo
# ----------------------------------------------------------------------
