SeekquarrySeekquarry - Yioop Repo - Seekquarry

/ devlog / devscripts / check_errors_shown.sh⤓
#!/bin/sh
# Checks that a server left running for a walk was started with errors
# shown. A sandbox with errors off hides what Chris's machine prints, and
# a warning standing in front of a body that should be JSON stops that
# body parsing, so a screen reading it shows nothing at all. Three
# browser walks passed with errors off while the contact box on his
# machine offered no names.
#
# With no argument it looks at any php server running on this machine.
# With an argument it reads that address and refuses when what comes
# back does not begin the way a body of that kind should.
found=0
fail=0
# Errors are shown through Yioop's own profile, where ERROR_INFO in
# DEBUG_LEVEL makes Config.php report every level, not through flags
# given to php on the command line.
if ps ax -o args= 2>/dev/null | grep -q "[i]ndex.php"; then
    found=1
    shown=`php -r 'require "src/configs/Config.php";
        $info = seekquarry\yioop\configs\ERROR_INFO;
        echo ((seekquarry\yioop\configs\p("DEBUG_LEVEL") & $info) ==
            $info) ? "yes" : "no";' 2>/dev/null`
    if [ "$shown" != "yes" ]; then
        echo "check_errors_shown: FAIL the profile does not show errors."
        echo "  Run php src/configs/ConfigureTool.php debug +error and"
        echo "  start the server again."
        fail=1
    fi
fi
if [ -n "$1" ]; then
    body=`curl -s --max-time 8 "$1" 2>/dev/null`
    first=`printf '%s' "$body" | cut -c1`
    case "$first" in
        '{'|'['|'<'|'')
            ;;
        *)
            echo "check_errors_shown: FAIL what came back begins with"
            echo "  '$first' rather than a body. A warning ahead of a"
            echo "  body stops it being read:"
            printf '%s' "$body" | head -2 | sed 's/^/    /'
            fail=1
            ;;
    esac
fi
if [ "$fail" -eq 0 ]; then
    if [ "$found" -eq 0 ] && [ -z "$1" ]; then
        echo "check_errors_shown: no server is running to look at"
    else
        echo "check_errors_shown: PASS errors are shown and nothing"
        echo "  stands in front of a body"
    fi
fi
exit $fail