Programming
linux bash rpm rpm-spec
Updated Fri, 05 Aug 2022 12:29:57 GMT

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.





Comments (2)

  • +0 – Thanks for the comments and answer. So, Etan, what you are suggesting is I try to modify the .bashrc or similar file / remove changes in it that were done during install. — Jan 17, 2015 at 16:11  
  • +0 – If your RPM made any such $PATH modifications during install then yes, removing them would be potentially appropriate. Though, as I just said in a comment on the OP, an RPM that modifies $PATH is a bad idea as far as I'm concerned. — Jan 18, 2015 at 13:40