You are not logged in.

#1 2015-08-30 10:55:15

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,597
Website

Script needs sudo access to /usr/bin/mount. Elegant check? [solved]

Within a shell script, what an elegant way to check to see if the user invoking the script, has sudo access to specifically /usr/bin/mount and /usr/bin/umount?

I have added this line to /etc/sudoers

foo ALL=(ALL) NOPASSWD: /usr/bin/mount,/usr/bin/umount

What I thought about doing:
`sudo -n mount &>/dev/null` which should return 0 if the user can run it as sudo and `sudo -n umount -V` which also will return 0.

Last edited by graysky (2015-09-01 16:36:50)


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#2 2015-08-30 11:32:41

brebs
Member
Registered: 2007-04-03
Posts: 3,742

Re: Script needs sudo access to /usr/bin/mount. Elegant check? [solved]

Looks like mount with the options -f and -n, would be a better test of whether the command would actually succeed.

Offline

#3 2015-08-30 11:32:56

jsoy9pQbYVNu5nfU
Member
Registered: 2013-04-19
Posts: 108

Re: Script needs sudo access to /usr/bin/mount. Elegant check? [solved]

^ That's better.
--
How about adding -k to prevent a lingering timestamp from influencing the result:

sudo -kn mount &>/dev/null && echo "Can run" || echo "Can't ruN"

Last edited by jsoy9pQbYVNu5nfU (2015-08-30 11:33:58)

Offline

#4 2015-09-01 02:06:09

Mr.Elendig
#archlinux@freenode channel op
From: The intertubes
Registered: 2004-11-07
Posts: 4,092

Re: Script needs sudo access to /usr/bin/mount. Elegant check? [solved]


Evil #archlinux@libera.chat channel op and general support dude.
. files on github, Screenshots, Random pics and the rest

Offline

#5 2015-09-01 14:22:48

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,597
Website

Re: Script needs sudo access to /usr/bin/mount. Elegant check? [solved]

Thanks all.  I opted for:

    sudo -nk mount &>/dev/null
    [[ $? -ne 0 ]] && FAILCODE=1

    sudo -nk umount -V &>/dev/null
    [[ $? -ne 0 ]] && FAILCODE=1

EDIT:  I opened a new thread here to solicit feedback from udisks/udisks2 users to achieve this without the bash helper script.

Last edited by graysky (2015-09-18 19:31:13)


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

Board footer

Powered by FluxBB