Search code examples
linuxbashrpmrpm-spec

remove entries from PATH while uninstalling rpm


To leave the system in a cleaner state, I am trying to remove entries from the PATH in the %preun section of my rpm spec file.

I found couple of threads on stackoverflow that I tried

What is the most elegant way to remove a path from the $PATH variable in Bash? AND Linux: Remove path from $PATH variable

Answers in both these links work perfectly when I manually run them on a terminal. But, they don't work when I run the rpm -e xx command. If my PATH looked like this after successful installation:

    /usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/lpp/mmfs/bin

and I am trying to remove /usr/lpp/mmfs/bin,

After the rpm uninstall the PATH looks like:

    /sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin

Questions: 1) Do I need to do something different when the commands mentioned in the earlier links are run from the spec file?

2) What are some recommended ways to remove PATH entries during rpm uninstalls?

Note Commands I have tried in spec file are:

PATH=$(echo $PATH | sed -e 's;:\?/home/user/bin;;' -e 's;/home/user/bin:\?;;')

and

PATH=${PATH/:\/home\/user\/bin/}

Solution

  • The RPM %preun script cannot affect the PATH variable of any running shells. That isn't possible.

    It can't (directly) affect the PATH variable of any new shells either.

    The only thing it can do is remove whatever changes it made to the system (or user shudder) shell startup files that caused the PATH variable additions to be made.

    Removing those changes will cause any new shells not to have those changes made and therefore not to have those additional PATH entries in them.