0

I'm trying to build an RPM for our program and running into some issues. I'm trying to run the sed and ln commands as a script in the postinstall/preremove and they don't seem to be making any changes. We are using the maven rpm plugin to build the RPM. I read somewhere that turning selinux off might help but it still doesn't work. We are using CentOS 7.

from the pom.xml:

  <postinstallScriptlet>
    <script>sed -i 's/foo/bar/g' /path/to/file</script>
  </postinstallScriptlet>
  <preremoveScriptlet>
    <script>sed -i 's/bar/foo/g' /path/to/file</script>
  </preremoveScriptlet>

This works when I run it by hand but not as part of the rpm

1 Answers1

0

That should work with fresh install. However it will not work when you are upgrading packages. Because of the ordering. See https://fedoraproject.org/wiki/Packaging:Scriptlets#Scriptlet_Ordering

Rpm first call postinstallScriptlet of new package, install it, and then call preremoveScriptlet of old version of package and then remove the old version. So you basically call sed -i 's/foo/bar/g' /path/to/file immediatelly followed by sed -i 's/bar/foo/g' /path/to/file.

You likely want something like:

<preremoveScriptlet>
    <script>
if [ 0$1 -eq 0 ] ; then
  sed -i 's/bar/foo/g' /path/to/file
fi
</script>
  </preremoveScriptlet>

which will call the sed only if you are really uninstalling the package. And not during upgrades. Similary for post install scriptlet. See https://fedoraproject.org/wiki/Packaging:Scriptlets#Syntax

msuchy
  • 5,162
  • 1
  • 14
  • 26