1

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/}
Community
  • 1
  • 1
Ravindra Mijar
  • 1,282
  • 2
  • 9
  • 17
  • Better to use: `PATH=$(echo $PATH | sed -e 's;/home/user/bin;;' -e 's;::;:;')` – Paul Evans Jan 16 '15 at 12:33
  • 2
    There is usually no reson for an RPM package to install binaries outside the standard system PATH in the first place. – tripleee Jan 16 '15 at 15:33
  • 2
    Certainly not binaries that a normal user needs to run on their own such that modifying `$PATH` is a good idea. In fact, modifying the system or a user's `$PATH` via an RPM is almost always the wrong thing to do (except in very specific/controlled deployment scenarios). – Etan Reisner Jan 18 '15 at 13:39

2 Answers2

3

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.

Etan Reisner
  • 77,877
  • 8
  • 106
  • 148
  • 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. – Ravindra Mijar Jan 17 '15 at 16:11
  • 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. – Etan Reisner Jan 18 '15 at 13:40
1

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.

Aaron D. Marasco
  • 6,506
  • 3
  • 26
  • 39