Reputation: 1312
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/}
Upvotes: 1
Views: 405
Reputation: 6758
The proper way of adding to a PATH
(and subsequently, removing it later), would be to drop a file yourpackage.sh
and yourpackage.csh
in /etc/profile.d
.
I also agree with others that it's probably a bad idea, but if you need to do it, that's how I would.
Upvotes: 1
Reputation: 81052
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.
Upvotes: 3