Home > Enterprise >  setting environmental variables system wide from /etc/profile.d from postinstall script of Cpack deb
setting environmental variables system wide from /etc/profile.d from postinstall script of Cpack deb

Time:07-28

currently i have a deb installer, built with Cmake->Cpack, that runs a postinst script, which calls another script to in /etc/profile.d that sets a few environmental variables to allow our application to run.

the issue is after installing, it requires the user to reboot/logout-login their system to run the application (whether from the terminal or Applications page).

i'd like it so that it isn't necessary to reboot/logout-login their current session after an initial install and that from the current instance, be able to launch their application

postinst script in my Cpack/Cmake project

#!/bin/bash
source /etc/profile.d/configset.sh
desktop-file-install /usr/share/applications/myApp.desktop
udevadm control --reload-rules && udevadm trigger

configset.sh script

#!/bin/sh
MYAPP_BIN_PATH="/opt/myApp/bin"
MYAPP_LIB_PATH="/opt/myApp/lib"
MYAPP_DIR="/opt/myApp"

export PATH="$PATH":${MYAPP_BIN_PATH}
export MYAPP_DIR
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH":${MYAPP_LIB_PATH}

The issue here is that after installing the application, several shared libraries that contain dependencies that need to be met (hence the need to reboot/logout-login the computer to run the configset.sh script to link the deps)

Is there a way to get the configset.sh script to run across the system without a reboot after a deb install?

I am aware that running source /etc/profile.d/configset.sh from the current bash terminal instance and then launching the application from there is one way, but this isn't a feasible solution for a user that just wants to install the .deb and immediately launch it from Ubuntu's Applications page.

So not only do I want my environmental variables to be set immediately, system wide, on the post deb install, but also have it persist after reboot.

I would like to keep my solution contained within the following toolset : CMake, CPack, shell and bash scripts. No python.

CodePudding user response:

Remove your modifications of /etc/profile.d . Create a script:

#!/bin/sh
MYAPP_BIN_PATH="/opt/myApp/bin"
MYAPP_LIB_PATH="/opt/myApp/lib"
MYAPP_DIR="/opt/myApp"

export PATH="$PATH":${MYAPP_BIN_PATH}
export MYAPP_DIR
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH":${MYAPP_LIB_PATH}

"$MYAPP_BIN_PATH"/your_app "$@"

And install the script as executable to /usr/bin/your_app. Now you don't have to set anything anywhere - your application will get all the variables it needs. You may want to read https://stackoverflow.com/a/28085062/9072753 . You may want to research like other applications that do similar - like steam.

Is there a way to get the configset.sh script to run across the system without a reboot after a deb install?

I want my environmental variables to be set immediately, system wide

That is not possible - Linux OS (and any good OS) is designed with process isolation in mind. Processes are isolated, it's not possible to affect running processes, by design.

  • Related