-1

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.

  • `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 wa` Soooo just write a script that does exactly that and expose that script to the user? But that brings the quesiton why to affect the environment variables at all, just write the script that sets the variables for your application. I wouldn't want all applications to be polluting my env with some defaults, keep them to yourself. – KamilCuk Jul 26 '22 at 14:57
  • 1
    You, apparently, have no idea now environment variables work. Just as you can't arbitrarily change the CWD (current working directory) of an arbitrary process you can't arbitrarily change the env vars of an arbitrary process. Think about what being able to do so would mean from a security perspective. Environment variables are inherited (like the CWD and many other aspects of a process such as its resource limits). Once a process is running you can't change those characteristics without its active involvement. – Kurtis Rader Jul 27 '22 at 03:18

1 Answers1

2

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.

KamilCuk
  • 120,984
  • 8
  • 59
  • 111