Discussion:
Switching user and environment variables to root to install packages
Rocky Hotas
2014-07-02 07:14:17 UTC
Permalink
Hi everybody!
In order to install new pagkages with pkgsrc it is necessary to set the environment variables PATH and PKG_PATH.
This can be done for root, which have the needed permissions to install new packages.
With a common user and the command su it can be still possible to have the necessary permissions, but the variable PATH and PKG_PATH are not set.
So, I would like to ask two question:
- which is in such cases the best approach? To set PATH and PKG_PATH in /etc/profile for all users or to mantain the actual configuration?
- Is there a way to completely switch the user and its environment variables?
Thanks!

Rocky
Greg Troxel
2014-07-02 11:29:11 UTC
Permalink
"Rocky Hotas" <***@post.com> writes:

> Hi everybody!
> In order to install new pagkages with pkgsrc it is necessary to set the environment variables PATH and PKG_PATH.
> This can be done for root, which have the needed permissions to install new packages.
> With a common user and the command su it can be still possible to have the necessary permissions, but the variable PATH and PKG_PATH are not set.
> So, I would like to ask two question:
> - which is in such cases the best approach? To set PATH and PKG_PATH in /etc/profile for all users or to mantain the actual configuration?
> - Is there a way to completely switch the user and its environment variables?
> Thanks!

See the man pages for su and sudo (a package). In particular see -l and
-m to su, and -E to sudo. What I do is set environment variables I want
in my own dotfiles, and then use "sudo -E" to get a root shell with my
variables. There are lots of ways to do it, and it's really just a
matter of preference.
Chris Bannister
2014-07-02 11:31:32 UTC
Permalink
On Wed, Jul 02, 2014 at 09:14:17AM +0200, Rocky Hotas wrote:
> Hi everybody!
> In order to install new pagkages with pkgsrc it is necessary to set the environment variables PATH and PKG_PATH.
> This can be done for root, which have the needed permissions to install new packages.
> With a common user and the command su it can be still possible to have the necessary permissions, but the variable PATH and PKG_PATH are not set.
> So, I would like to ask two question:
> - which is in such cases the best approach? To set PATH and PKG_PATH in /etc/profile for all users or to mantain the actual configuration?
> - Is there a way to completely switch the user and its environment variables?
> Thanks!

Try 'su -'
The '-' should inherit the environment.

--
"If you're not careful, the newspapers will have you hating the people
who are being oppressed, and loving the people who are doing the
oppressing." --- Malcolm X
Brett Lymn
2014-07-02 12:28:04 UTC
Permalink
On Wed, Jul 02, 2014 at 11:31:32PM +1200, Chris Bannister wrote:
>
> Try 'su -'
> The '-' should inherit the environment.
>

No. It does exactly the opposite.

--
Brett Lymn
Let go, or be dragged - Zen proverb.
Rocky Hotas
2014-07-07 17:26:11 UTC
Permalink
Really?
After "su -" with root password the installation of a package worked, so maybe the variables were inherited.
Anyway thank you for all your advices, I will try the various suggested options.

Rocky



> Sent: Wednesday, July 02, 2014 at 2:28 PM
> From: "Brett Lymn" <***@internode.on.net>
> To: "NetBSD Users Mailing List" <netbsd-***@netbsd.org>
> Subject: Re: Switching user and environment variables to root to install packages
>
> On Wed, Jul 02, 2014 at 11:31:32PM +1200, Chris Bannister wrote:
> >
> > Try 'su -'
> > The '-' should inherit the environment.
> >
>
> No. It does exactly the opposite.
>
> --
> Brett Lymn
> Let go, or be dragged - Zen proverb.
>
Brett Lymn
2014-07-08 11:02:29 UTC
Permalink
On Mon, Jul 07, 2014 at 07:26:11PM +0200, Rocky Hotas wrote:
> Really?

really. try it yourself and/or check the man page. Do a "su -" and
check the environment using env.

> After "su -" with root password the installation of a package worked, so maybe the variables were inherited.
>

they shouldn't be - perhaps it just works without them or you have
inserted them into root's environment another way.

--
Brett Lymn
Let go, or be dragged - Zen proverb.
Ottavio Caruso
2014-07-02 11:52:09 UTC
Permalink
On 2 July 2014 09:14, Rocky Hotas <***@post.com> wrote:
> In order to install new pagkages with pkgsrc it is necessary to set the environment variables PATH and PKG_PATH.

If you're planning to install from precompiled binaries consistently,
I suggest that you use pkgin instead. Once you have adjusted your
pkgin.conf, it doesn't matter if you use a root shell or sudo, because
you don't rely on env variables.

--
Ottavio
Aleksej Saushev
2014-07-02 21:47:53 UTC
Permalink
Hello,

"Rocky Hotas" <***@post.com> writes:

> Hi everybody!
> In order to install new pagkages with pkgsrc it is necessary to set the environment variables PATH and PKG_PATH.

No, pkg_install.conf(5) gives you another way to configure it.


--
HE CE3OH...
Continue reading on narkive:
Search results for 'Switching user and environment variables to root to install packages' (Questions and Answers)
6
replies
who win the match for jonh and randy ortan?
started 2007-08-19 06:00:21 UTC
rugby league
Loading...