foreachwikiindblist: check groups before attempting to sudo

The approach is directly copied from files/misc/scripts/mwscript.
Fixes I29259bad8.

Change-Id: Ic41b22361247410c0df1df3ee56d2ef07d7d40ea