How/where to set global environment variables?

Need support for GhostBSD. Ask here if your question does not fit elsewhere.
WytWun
Posts: 13
Joined: Sat Aug 12, 2017 8:54 am

How/where to set global environment variables?

Post 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
NeverSimple
Posts: 40
Joined: Sun Aug 20, 2017 10:08 am

Re: How/where to set global environment variables?

Post 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
WytWun
Posts: 13
Joined: Sat Aug 12, 2017 8:54 am

Re: How/where to set global environment variables?

Post 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 :(
ASX
Posts: 988
Joined: Wed May 06, 2015 12:46 pm

Re: How/where to set global environment variables?

Post 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).
WytWun
Posts: 13
Joined: Sat Aug 12, 2017 8:54 am

Re: How/where to set global environment variables?

Post by WytWun »

I get the same behaviour with /bin/sh :(
ASX
Posts: 988
Joined: Wed May 06, 2015 12:46 pm

Re: How/where to set global environment variables?

Post by ASX »

WytWun wrote:I get the same behaviour with /bin/sh :(
can you copy &paste here your /etc/profile ?
WytWun
Posts: 13
Joined: Sat Aug 12, 2017 8:54 am

Re: How/where to set global environment variables?

Post 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...
kraileth
Posts: 312
Joined: Sun Sep 04, 2016 12:30 pm

Re: How/where to set global environment variables?

Post 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?
WytWun
Posts: 13
Joined: Sat Aug 12, 2017 8:54 am

Re: How/where to set global environment variables?

Post 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.
ASX
Posts: 988
Joined: Wed May 06, 2015 12:46 pm

Re: How/where to set global environment variables?

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