[PATCH 3/3] checkupdates: Do not use sudo when run as root
Johannes Löthberg
johannes at kyriasis.com
Wed Nov 25 18:45:38 UTC 2020
Excerpts from Daniel M. Capella's message of November 1, 2020 21:04:
> 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.
>
I still think that they're similar enough that it would make sense to
just have one function that takes an argument saying which user the
command should be run as.
However, since it's just used in two places for now we could leave it as
is, and just merge it if we get a third use.
`die` should be merged however, but that's a separate thing, since it's
already duplicated in multiple places.
Applied.
--
Sincerely,
Johannes Löthberg :: SA0DEM
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 1727 bytes
Desc: not available
URL: <https://lists.archlinux.org/pipermail/pacman-contrib/attachments/20201125/62dcd2fd/attachment.sig>
More information about the pacman-contrib
mailing list