Page 1 of 2

How/where to set global environment variables?

Posted: Wed Aug 23, 2017 7:46 am
by WytWun
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

Re: How/where to set global environment variables?

Posted: Sat Aug 26, 2017 6:55 pm
by NeverSimple
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

Re: How/where to set global environment variables?

Posted: Sun Aug 27, 2017 4:55 am
by WytWun
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 :(

Re: How/where to set global environment variables?

Posted: Mon Aug 28, 2017 1:20 pm
by ASX
/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).

Re: How/where to set global environment variables?

Posted: Tue Aug 29, 2017 7:55 am
by WytWun
I get the same behaviour with /bin/sh :(

Re: How/where to set global environment variables?

Posted: Tue Aug 29, 2017 9:28 am
by ASX
WytWun wrote:I get the same behaviour with /bin/sh :(
can you copy &paste here your /etc/profile ?

Re: How/where to set global environment variables?

Posted: Wed Aug 30, 2017 9:38 am
by WytWun

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...

Re: How/where to set global environment variables?

Posted: Tue Sep 12, 2017 8:58 pm
by kraileth
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?

Re: How/where to set global environment variables?

Posted: Thu Sep 14, 2017 8:25 am
by WytWun
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.

Re: How/where to set global environment variables?

Posted: Thu Sep 14, 2017 10:06 am
by ASX
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.