Search code examples
shellrhelrpm-spec

RHEL RPM spec post installation %post not sourcing shell script


I am trying to source a shell script in the root environment (as I am doing installation as root) after successful installation of a rpm in RHEL7.4 box

The rpm spec %post section is as follows:

%post
source /etc/profile.d/env.sh

script env.sh is available after installation in the mentioned path and it is used to set PYTHONPATH environment variable like this:

pypath="/opt/lib"
if [ "$(echo $PYTHONPATH | grep $pypath)" == "" ]; then
        export PYTHONPATH="$PYTHONPATH:$pypath"
fi

However, it is not happening after successful rpm installation even if I change the "source" command to "." script

When I source the script env.sh manually then the variable is set


Solution

  • probably the command is running correctly, but you expect the PYTHONPATH to be changed for everybody; which is not the case: the PYTHONPATH is only changed for the shell session of the %post section.

    Each time you start a new shell (or bash) session, your environment variables are reset. You can take a look to related questions for information on how to change environment variables permanently; then you can choose which strategy to use for your rpm package, for example:

    https://unix.stackexchange.com/questions/117467/how-to-permanently-set-environmental-variables