[PATCH 3/3] checkupdates: Do not use sudo when run as root

Daniel M. Capella polyzen at archlinux.org
Sun Nov 1 20:04:45 UTC 2020


On October 23, 2020 10:53:54 AM EDT, "Johannes Löthberg" <johannes at kyriasis.com> wrote:
> Excerpts from Daniel M. Capella's message of September 3, 2020 3:36:
> > +die() {
> > +	error "$@"
> > +	exit 1
> > +}
> > +
> > +runcmd() {
> > +	if (( EUID != 0 )); then
> > +		msg 'Escalating privileges using sudo'
> > +		if sudo -v &>/dev/null && sudo -l &>/dev/null; then
> > +			sudo "$@"
> > +		else
> > +			die 'Failed to escalate'
> > +		fi
> > +	else
> > +		"$@"
> > +	fi
> > +}
> > +
> 
> Might make more sense to move it to a lib/ script and m4_include it in
>  
> both places rather than copy-pasting it around?

`runcmd()` here doesn't use a `needsroot` variable as in paccache. `pacman -Sw` always needs root afaik.

--
Best,
Daniel <https://danielcapella.com>


More information about the pacman-contrib mailing list