3

I'm working on an RPM package that deploys files to /opt and /etc.

In most of the cases it works perfectly, excepted that for a given environment, writing to /etc is not allowed ....

So I used Relocations in order to deploy the /etc files in some other location :

Relocations : /opt /etc

By specifying --relocate option I can deploy the /etc files into another location :

rpm -ivh --relocate /etc=/my/path/to/etc mypackage.rpm

Now the issue is that in the postinstall script, there are some hard coded references to /etc that don't get replaced when the package is deployed :

echo `hostname --fqdn` > /etc/myapp/host.conf

I hope that there is a way (macro, keyword, ... ) to use instead of hard coded paths in order to perform the substitutions during rpm execution.

If you have any information on this I'd really appreciate some help.

Thanks per advance

PS : Please note that this is NOT a duplicate of the previously asked (and answered) questions related to the root path re-locations as we're dealing with several relocation paths and the fact that we need to handle each of them separately during rpm scriptlets

devlearn
  • 1,725
  • 2
  • 17
  • 30
  • 1
    Possible duplicate of [building RPM package: force to install in path of a dependent relocated package](http://stackoverflow.com/questions/28348561/building-rpm-package-force-to-install-in-path-of-a-dependent-relocated-package) – Etan Reisner Jan 07 '16 at 17:28
  • But see also y answer here](http://stackoverflow.com/a/25386412/258523) about how relocatable packages don't work with `yum` and are often non-trivial to get right. It sounds to me like you might want to just always use the `/opt` location for your package and be done with it. – Etan Reisner Jan 07 '16 at 17:29
  • Hi, thanks for the suggestion, the issue is that the package deploys to both /opt and /etc so I need to get the relocations inside the %post. The post that you mentioned uses only a single relocation ... – devlearn Jan 11 '16 at 12:38
  • The question I linked to as a possible dup mentions more than one relocation prefix (albeit subtly). – Etan Reisner Jan 11 '16 at 15:42

1 Answers1

5

Many thanks to Panu Matilainen from the RPM mailing list who answered the question. I'll re-produce his mail literally in order to share the knowledge :

I assume you mean (the above is how rpm -qi shows it though):

Prefixes: /opt /etc

The prefixes are passed to scriptlets via $RPM_INSTALL_PREFIX<n> environment variables, <n> is the index of supported prefixes starting from zero. So in the above,

/opt is $RPM_INSTALL_PREFIX0 /etc is $RPM_INSTALL_PREFIX1

So the scriptlet example becomes:

echo `hostname --fqdn` > $RPM_INSTALL_PREFIX1/myapp/host.conf

Works like a charm, thank you very much Panu !

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
devlearn
  • 1,725
  • 2
  • 17
  • 30