How to set system envvar

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
krivine
Level 1
Level 1
Posts: 15
Joined: Mon Jul 16, 2012 5:28 pm

How to set system envvar

Post by krivine »

I want to set a couple of system-wide environment variables, for use by GUI programs, not the terminal. Exporting in ~/.bashrc or ~/.profile doesn't work. Neither does the following entry in ~/.pam_environment:

OPENAUDIBLE_PROFILE DEFAULT=/home/ralph/somedir/
QT_SCALE_FACTOR DEFAULT=1.2

If I source the pam file, I get the following:

$ source .pam_environment
OPENAUDIBLE_PROFILE: command not found
QT_SCALE_FACTOR: command not found

After logging out and logging in again, the ~/.pam_environment entries are ignored

I'm running Mint 20.1 Mate.

Why are exports in .profile ignored? Is ~/.pam_environment the correct location? If it is, what do I need to do to additionally?

Thanks in advance.
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
tuxoneseven
Level 2
Level 2
Posts: 89
Joined: Mon Dec 14, 2020 8:08 am

Re: How to set system envvar

Post by tuxoneseven »

Not sure about the specifics with pam, but for environment variables you can use the export command to set environment variables. To list all your environment variables, type env. You can set them in .bashrc and you need to to restart the bash shell for it to work.
Active Python user - PyQt
1000
Level 5
Level 5
Posts: 999
Joined: Wed Jul 29, 2020 2:14 am

Re: How to set system envvar

Post by 1000 »

Some programs have their own configuration files.
General this is a bad section on the forum. The packaging section would be better.

QT_SCALE_FACTOR

Code: Select all

$ echo $QT_SCALE_FACTOR
1
So it has value.
But I can not find this variable, probably is set from binary file.
~/.pam_environment is the user specific equivalent of /etc/security/pam_env.conf
https://wiki.archlinux.org/index.php/En ... _variables
https://en.wikipedia.org/wiki/Linux_PAM

So you do it wrong.
Read more about environmental variables.
krivine
Level 1
Level 1
Posts: 15
Joined: Mon Jul 16, 2012 5:28 pm

Re: How to set system envvar

Post by krivine »

Thanks for the replies. The problems are on a new laptop, with Mint installed by the vendor. (I've got lazy in my old age.) .bashrc works correctly on my desktop, where I installed Mint myself. Maybe the vendor didn't do a standard installation - they normally just install plain Ubuntu. I'll check there first.
1000
Level 5
Level 5
Posts: 999
Joined: Wed Jul 29, 2020 2:14 am

Re: How to set system envvar

Post by 1000 »

Best way is ask developer, because this may not be easy.

If you want try alone.
- You must be sure that if you change the variable manually it affects the applications you want.
- You cannot export a variable to a file.
To file you can save variable, then system can read this file and load to RAM as environmental variables
- I doubt you can set more than one value. So or default or something, never together.
- You need to know which application sets the variable.
You can check all source codes of all packages which you have installed (I guess it's too hard for you)
This is important.
Because when you boot up, one file can set your variable and another application can change your variable.
- Here you have example which you can edit and test https://github.com/mate-desktop/mate-se ... -383850896
- You can also ask there on github "mate-desktop" developers. But write them clearly, what works, how it works and how did you check it.

Edit.
If another application will change your value,
then you can write your own script that will run on system startup, sleep a few seconds and then sets the appropriate variables.
But I'm not sure if it will have the effect you want to achieve.
because I don't know with which applications you want this worked.
Last edited by 1000 on Sun Mar 14, 2021 6:29 pm, edited 1 time in total.
krivine
Level 1
Level 1
Posts: 15
Joined: Mon Jul 16, 2012 5:28 pm

Re: How to set system envvar

Post by krivine »

1000 wrote: Sun Mar 14, 2021 6:24 am Some programs have their own configuration files.
General this is a bad section on the forum. The packaging section would be better.
<snip>
I want to configure my own system - personalise and customise it. That's why I came here. I do not understand why you're directing me to the packaging section.

And I'm aware I'm doing something wrong; that's why I came here.

Thanks anyway.
ajgringo619

Re: How to set system envvar

Post by ajgringo619 »

I would take a look at /etc/environment or /etc/profile.
1000
Level 5
Level 5
Posts: 999
Joined: Wed Jul 29, 2020 2:14 am

Re: How to set system envvar

Post by 1000 »

Because that is beyond the knowledge of writing bash scripts.
Only what someone can, this is write a script to download and search for a variable in all source codes.
Maybe there is no proper section here,
but please read what I wrote above again. Maybe the mate-desktop developer knows where to look for the variable.
Maybe he can write applications for you and others.
Maybe such an application already exists, but you need to find or install something.
However, these are QT settings, mate desktop uses GTK settings.

Edit.
Applications written in GTK use their own settings, and applications written in QT use their own settings.
1000
Level 5
Level 5
Posts: 999
Joined: Wed Jul 29, 2020 2:14 am

Re: How to set system envvar

Post by 1000 »

ajgringo619 wrote:I would take a look at /etc/environment or /etc/profile.
You can check all files

Code: Select all

sudo grep -rin QT_SCALE_FACTOR /etc/

Code: Select all

grep -rin QT_SCALE_FACTOR
ajgringo and krivine
In my case, nothing interesting was found.
You cannot check binary files this way.
Checking the source code is the surest way.
Or don't check anything. Just save the variable to the right place or make a script that will set the variable a few seconds after the system boots up.
We can only say if you are doing it correctly.
We cannot check if it works for you.

krivine
There are many guides, show that you can :mrgreen:

Edit
This is only example

Code: Select all

$ strings /usr/sbin/lightdm | grep [A-Z]=
Starting Light Display Manager %s, UID=%i PID=%i
DISPLAY_MANAGER=lightdm
PATH=/usr/local/bin:/usr/bin:/bin
USER=%s
LOGNAME=%s
HOME=%s
SHELL=%s
XDG_SESSION_COOKIE=%s
XDG_RUNTIME_DIR=%s
XAUTHORITY=%s
You will find an explanation on the internet.
I did not mention about this method
because
can be more unreliable than looking inside source code.
You can try to connect with the command "find" "xargs" and " | grep QT"
Last edited by 1000 on Sun Mar 14, 2021 7:27 pm, edited 1 time in total.
krivine
Level 1
Level 1
Posts: 15
Joined: Mon Jul 16, 2012 5:28 pm

Re: How to set system envvar

Post by krivine »

Thanks. I do appreciate your time and suggestions.

I created file qt-style.sh in the right location, and rebooted, but the values hadn't changed from the default. The conditions were met (DESKTOP_SESSION=mate). To get a usable KeePassXC, I've written a two-line shell script that sets the variable and launches the program, with a launcher on the desktop. It's getting late here, and I'll try your other suggestions tomorrow.

If it were just that, I'd probably leave it. The problems aren't just confined to GTK / QT though - I can't seem to set any environment variables that persist. I'm going to contact the vendor tomorrow.

Thanks again.
1000
Level 5
Level 5
Posts: 999
Joined: Wed Jul 29, 2020 2:14 am

Re: How to set system envvar

Post by 1000 »

Tomorrow, write what you tested
and what exactly doesn't work for you.


For example:

1. From terminal

Code: Select all

$ echo $QT_SCALE_FACTOR
1
$ export QT_SCALE_FACTOR=1.2
$ echo $QT_SCALE_FACTOR
1.2
Show how it works for you.

2. "Exporting in ~/.bashrc or ~/.profile doesn't work."
What exactly did you paste there? At the end of the file in a new line?
Did you reset the system?
krivine
Level 1
Level 1
Posts: 15
Joined: Mon Jul 16, 2012 5:28 pm

Re: How to set system envvar

Post by krivine »

Summary: Problem is with QT5, which ignores environment variables set in ~/.bashrc, unless you call the program from the command line, not the menu.

Solution: change font through program qt5ct, which is in the repo and was already installed on my system. I'd never heard of it. KeePassXC now displays text at a size I can read comfortably (15pt). The solution should work for other programs that call QT5. There is no need to export QT_SCALE_FACTOR.

~/.bashrc: Entry to export the variable was on a new line, and I ran source ~/.bashrc before attempting to use it. As explained above, it works only when the program is called from a terminal.

qt-style.sh: This also set the variables, but was likewise ignored when starting KeePassXC from the menu.

qt5 and qt5ct: From https://www.pcsuggest.com/qt5ct-change- ... ion-style/:
It's easy to manage Qt5 application style in Qt integrated desktop like KDE, LXQt or Razor-Qt. But a little harder in other desktop like GNOME, Cinnamon, MATE, XFCE or LXDE.
s/a little/much/

Conclusion: I should have explained the problem in more detail at the outset. Thank you for your help.

Edit: the doc for KeePassXC mentions QT_SCALE_FACTOR, but not qt5ct. I've suggested to the development team that they mention it.
1000
Level 5
Level 5
Posts: 999
Joined: Wed Jul 29, 2020 2:14 am

Re: How to set system envvar

Post by 1000 »

It's great that your problem is solved :D
Problem is with QT5, which ignores environment variables set in ~/.bashrc,
- Environment variables can be loaded from configuration files and programs.
And there may be conditions, what and when will launched and when changed or replaced.
For example variable from user and root may have a different value.


I tried search with "strings" command

Code: Select all

#!/bin/bash

# Destiny: To find string from installed packages inside system based on Ubuntu.

LIST_PACKAGES=$(dpkg -l | grep ^ii |  awk  '{print $2}')

while read PACKAGE_NAME ; do
    LIST_FILES=$(dpkg -L "$PACKAGE_NAME")
    while read FILE ; do
        STRING=$(strings "$FILE" 2>/dev/null | grep -n QT_SCALE_FACTOR )
        [ -z "$STRING" ] || echo "${PACKAGE_NAME}:${FILE}:${STRING}"
    done <<< "$LIST_FILES"
done <<< "$LIST_PACKAGES"
Output: PACKAGE_NAME : FILE : number of line : STRING
# bash find.string.sh
libqt5gui5:amd64:/usr/lib/x86_64-linux-gnu/libQt5Gui.so.5.12.8:50045:QT_SCALE_FACTOR
libqt5gui5:amd64:/usr/lib/x86_64-linux-gnu/libQt5Gui.so.5:50045:QT_SCALE_FACTOR
libqt5gui5:amd64:/usr/lib/x86_64-linux-gnu/libQt5Gui.so.5.12:50045:QT_SCALE_FACTOR
mate-settings-daemon:/usr/lib/x86_64-linux-gnu/mate-settings-daemon/libxsettings.so:339:QT_SCALE_FACTOR
431:There was a problem when setting QT_SCALE_FACTOR=%d: %s
Last line is also from /usr/lib/x86_64-linux-gnu/mate-settings-daemon/libxsettings.so

Which binary is loading it? I don't know.
Maybe something from mate-settings-daemon package or this is dependence of another package.
I can not find this variable. Maybe it's easier to check from the source code or ask the "mate" developer .

Description mate-settings-daemon :
daemon handling the MATE session settings
This package contains the daemon which is responsible for setting the
various parameters of a MATE session and the applications that run
under it. It handles the following kinds of settings:
.
* Keyboard: layout, accessibility options, shortcuts, media keys
* Clipboard management
* Theming: background, icons, GTK+ applications
* Cleanup of unused files
* Mouse: cursors, speed, accessibility options
* Startup of other daemons: screensaver, sound daemon
* Typing break
.
It also sets various application settings through X resources and
freedesktop.org XSETTINGS.
krivine
Level 1
Level 1
Posts: 15
Joined: Mon Jul 16, 2012 5:28 pm

Re: How to set system envvar

Post by krivine »

Once again, thank you. That's useful information, and I will take a look. It will take me out of my comfort zone. It won't be right away; I have a lot going on at the moment.

I send you my very best wishes.
Locked

Return to “Scripts & Bash”