Test for -E support

Jeffrey Walton <[email protected]> Sat, 28 Mar 2020 14:17:23 -0400
Newsgroups gmane.comp.tools.sudo.user
Message-ID <CAH8yC8mWuDbW-S8v0CEqKH9epFKAQb5nuDiP8bUhsd8Un2vKHw@mail.gmail.com>
Hi Everyone,

I've got a recipe that echo's a password during an install:

    echo "$password" | sudo -E -S make install

Some of the older machines in my testing environment does not support
-E. The first thing I need is, detect the problem. Preferably the test
would not use a password. It just tests for the -E option.

My attempts (like below) result in a password prompt that I would like to avoid.

    sudo -E ls

My second attempt used the following. It produces no output on Ubuntu
18.04, but produces the following out on an old PowerMac:

    $ sudo -E -h 1>/dev/null
    sudo: illegal option `-E'
    usage: sudo -K | -L | -V | -h | -k | -l | -v

So I'm thinking I can check for -E with:

    NO_E_OPT=`sudo -E -h 2>&1 | grep -i -c illegal`

And then:

    # PowerMac
    $ NO_E_OPT=`sudo -E -h 2>&1 | grep -i -c illegal`; echo $NO_E_OPT
    1
    # Ubuntu
    $ NO_E_OPT=`sudo -E -h 2>&1 | grep -i -c illegal`; echo $NO_E_OPT
    0

Does that look about right? Or is there a better way to do this?

Thanks in advance.
____________________________________________________________
sudo-users mailing list <[email protected]>
For list information, options, or to unsubscribe, visit:
https://www.sudo.ws/mailman/listinfo/sudo-users