Page MenuHomePhabricator
Paste P7298

Find tools using `wb_terms`
ActivePublic

Authored by Lucas_Werkmeister_WMDE on Jun 26 2018, 4:01 PM.
#!/bin/bash
function check_tool {
if grep \
--quiet \
--no-messages \
--recursive \
--fixed-strings \
--binary-files=without-match \
--include='*.php' \
--include='*.sql' \
--include='*.py' \
--include='*.java' \
--include='*.pl' \
--include='*.bash' \
--include='*.sh' \
--include='*.c' \
--include='*.cxx' \
--include='*.cpp' \
--include='*.cc' \
--include='*.C' \
--include='*.c++' \
wb_terms \
"/data/project/$1/"; then
printf '%s\n' "$1"
else
status=$?
case $status in
1)
# no match
return 0
;;
2)
printf >&2 'grep error while searching tool %s\n' "$1"
return 2
;;
*)
printf >&2 'unknown grep exit code while searching tool %s: %d\n' "$1" "$status"
return $status
;;
esac
fi
}
if (($#)); then
for tool; do check_tool "$tool"; done
else
cd /data/project
for dir in */; do
tool=${dir%/}
check_tool "$tool"
done
fi

Event Timeline

Modified version of the script that works on the NFS primary servers (labstore100{4,5}.eqiad.wmnet)

find_wb_terms_tools.sh
#!/bin/bash

function check_tool {
    if grep \
        --quiet \
        --no-messages \
        --recursive \
        --fixed-strings \
        --binary-files=without-match \
        --include='*.php' \
        --include='*.sql' \
        --include='*.py' \
        --include='*.java' \
        --include='*.pl' \
        --include='*.bash' \
        --include='*.sh' \
        --include='*.c' \
        --include='*.cxx' \
        --include='*.cpp' \
        --include='*.cc' \
        --include='*.C' \
        --include='*.c++' \
        wb_terms \
        "/srv/tools/shared/tools/project/$1/"
    then
        printf '%s\n' "$1"
    else
        status=$?
        case $status in
        1)
            # no match
            return 0
        ;;
        2)
            printf >&2 'grep error while searching tool %s\n' "$1"
            return 2
        ;;
        *)
            printf >&2 'unknown grep exit code while searching tool %s: %d\n' "$1" "$status"
            return $status
        ;;
        esac
    fi
}

if (($#)); then
    for tool; do check_tool "$tool"; done
else
    for dir in /srv/tools/shared/tools/project/*; do
        tool=${dir##*/}
        check_tool "$tool"
    done
fi