Subject: Re: pkgsrc.txt and sudo
To: None <netbsd-docs@NetBSD.org>
From: Alan Barrett <apb@cequrux.com>
List: netbsd-docs
Date: 04/28/2007 22:34:21
On Sat, 28 Apr 2007, Aleksey Cheusov wrote:
>     .if exists(${LOCALBASE}/bin/sudo)
>     SU_CMD=        ${LOCALBASE}/bin/sudo /bin/sh -c
>     .endif
> 
> First, this .if doesn't work.

What do you mean by "doesn't work"?  I have used something similar for a
long time, and it works for me.  However, sudo doesn't work well when
${HOME} or ${SHELL} don't exist, so I also test for them.  Here's
the relavent part of my mk.conf file:

.if exists(${SHELL}) && exists(${HOME})
.  for _sudo_cmd in ${LOCALBASE}/bin/sudo /usr/pkg/bin/sudo /usr/local/bin/sudo
.    if exists(${_sudo_cmd})
SU_CMD?=${_sudo_cmd} /bin/sh -c            # requires security/sudo package
.    endif
.  endfor
SU_CMD?=/usr/bin/su -m root -c  # "su -m" does not clobber environment
.endif

> Second, IMHO it is better to NOT use pkgsrc version of sudo
> for building pkgsrc packages just because A wants B and B wants A...

There's no cyclic dependency.  Because if the ".if exists" test, sudo
won't be used if it's not already installed.

--apb (Alan Barrett)