How/where to set global environment variables?

Need support for GhostBSD. Ask here if your question does not fit elsewhere.

How/where to set global environment variables?

Postby WytWun » Wed Aug 23, 2017 6:46 am

I need to set global environment variables HTTP_PROXY, HTTPS_PROXY and FTP_PROXY so that anything that needs to connect to the internet can do so via the squid proxy on this network, regardless of the logged in user.

The most effective way of doing this I've found in FreeBSD is via the setenv capability in /etc/login.conf, however the GhostBSD desktop environment (Xfce) doesn't appear to respect that (i.e. the variables set this way aren't visible in a user shell when logged in) :?

The other way I expected might work was to export the variables in /etc/profile, however that doesn't appear to work either (either with sh or fish shells).

So how/where is one expected to set global environment variables like this? TIA
WytWun
 
Posts: 13
Joined: Sat Aug 12, 2017 7:54 am
Has thanked: 0 time
Been thanked: 2 times

How/where to set global environment variables?


Re: How/where to set global environment variables?

Postby NeverSimple » Sat Aug 26, 2017 5:55 pm

Seems to work for me when I put them in /etc/profile:

Code: Select all
HTTP_PROXY=blabla; export HTTP_PROXY

After I log out any existing user and log in again, the environment variables are accessible in a (fish) shell under Xfce as root or a user

Code: Select all
root@ghostbsd:~ # echo $HTTP_PROXY
blabla
root@ghostbsd:~ # su rherman
rherman@ghostbsd /root> echo $HTTP_PROXY
blabla

Using GhostBSD 11.1 ALPHA1

Richard
NeverSimple
 
Posts: 27
Joined: Sun Aug 20, 2017 9:08 am
Has thanked: 3 times
Been thanked: 1 time

Re: How/where to set global environment variables?

Postby WytWun » Sun Aug 27, 2017 3:55 am

Thanks for the followup. I'm glad the /etc/profile approach works for you, but it doesn't work for me in either 11.1alpha1 or 10.3 :(
WytWun
 
Posts: 13
Joined: Sat Aug 12, 2017 7:54 am
Has thanked: 0 time
Been thanked: 2 times

Re: How/where to set global environment variables?

Postby ASX » Mon Aug 28, 2017 12:20 pm

/etc/profile is the global profile for the default shell /bin/sh, other shells usually make use of the same profile for compatibility, some shell probably don't.

I would suggest, for a test, to make use of the default shell /bin/sh (please see man chsh for details).
ASX
Developer
 
Posts: 940
Joined: Wed May 06, 2015 11:46 am
Has thanked: 53 times
Been thanked: 120 times

Re: How/where to set global environment variables?

Postby WytWun » Tue Aug 29, 2017 6:55 am

I get the same behaviour with /bin/sh :(
WytWun
 
Posts: 13
Joined: Sat Aug 12, 2017 7:54 am
Has thanked: 0 time
Been thanked: 2 times

Re: How/where to set global environment variables?

Postby ASX » Tue Aug 29, 2017 8:28 am

WytWun wrote:I get the same behaviour with /bin/sh :(

can you copy &paste here your /etc/profile ?
ASX
Developer
 
Posts: 940
Joined: Wed May 06, 2015 11:46 am
Has thanked: 53 times
Been thanked: 120 times

Re: How/where to set global environment variables?

Postby WytWun » Wed Aug 30, 2017 8:38 am

Code: Select all
# $FreeBSD: releng/11.1/etc/profile 208116 2010-05-15 17:49:56Z jilles $
#
# System-wide .profile file for sh(1).
#
# Uncomment this to give you the default 4.2 behavior, where disk
# information is shown in K-Blocks
# BLOCKSIZE=K; export BLOCKSIZE
#
# For the setting of languages and character sets please see
# login.conf(5) and in particular the charset and lang options.
# For full locales list check /usr/share/locale/*
# You should also read the setlocale(3) man page for information
# on how to achieve more precise control of locale settings.
#
# Check system messages
# msgs -q
# Allow terminal messages
# mesg y
CHARSET=UTF-8; export CHARSET
LANG=en_US.UTF-8; export LANG
GDM_LANG=en_US.UTF-8; export GDM_LANG
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
HTTP_PROXY=http://192.168.3.1:3128/; export HTTP_PROXY
HTTPS_PROXY=$HTTP_PROXY; export HTTPS_PROXY


When sourced (. /etc/profile) into /bin/sh the environment variables are set as expected. It appears to me like it is not being read for a GUI login...
WytWun
 
Posts: 13
Joined: Sat Aug 12, 2017 7:54 am
Has thanked: 0 time
Been thanked: 2 times

Re: How/where to set global environment variables?

Postby kraileth » Tue Sep 12, 2017 7:58 pm

As far as I know that's what ~/.xprofile is for - but I think SLiM does not use this file. You can also try /usr/local/etc/X11/xinit/xinitrc or ~/.xinitrc for defining environment variables. Does that maybe do the trick?
kraileth
Developer
 
Posts: 301
Joined: Sun Sep 04, 2016 11:30 am
Has thanked: 53 times
Been thanked: 48 times

Re: How/where to set global environment variables?

Postby WytWun » Thu Sep 14, 2017 7:25 am

I would rather not rely on X related scripts as I want these environment variables set for SSH logins as well as local desktop sessions.
WytWun
 
Posts: 13
Joined: Sat Aug 12, 2017 7:54 am
Has thanked: 0 time
Been thanked: 2 times

Re: How/where to set global environment variables?

Postby ASX » Thu Sep 14, 2017 9:06 am

I'm starting to think you have come across that FreeBSD cap_mkdb(1) obscenity:

from login.conf(5) manpage:

The default /etc/login.conf shipped with FreeBSD is an out of the box
configuration. Whenever changes to this, or the user's ~/.login_conf,
file are made, the modifications will not be picked up until cap_mkdb(1)
is used to compile the file into a database
. This database file will
have a .db extension and is accessed through cgetent(3). See getcap(3)
for a more in-depth description of the format of a capability database.
ASX
Developer
 
Posts: 940
Joined: Wed May 06, 2015 11:46 am
Has thanked: 53 times
Been thanked: 120 times

Next

Return to General support

Who is online

Users browsing this forum: No registered users and 3 guests