[rpm] Correct way of writing spec file when packaging symlinks

Panu Matilainen pmatilai at laiskiainen.org
Mon Oct 20 07:31:13 UTC 2014


On 10/19/2014 01:16 AM, Domen Vrankar wrote:
> I also have one further question.
>
> I was reading this stack overflow thread
> (http://stackoverflow.com/questions/7521980/packaging-symlinks-via-rpmbuild)
> and began to wonder if it is better to write spec file this way:
>
> |%install
> rm -rf %{buildroot}
> mkdir %{buildroot}
> ln -sf /foo/bin %{buildroot}/bar/newbin
>
> %files
> /newbin
> |
>
> Or is it better to put symlink creation in %post section:
>
> %post|
> ln -sf /foo/bin /bar/newbin|

As a rule of thumb, when possible its always better to package than do 
things in install scriptlets.

>
> The problem that I'm having is that I can not create a relocatable rpm
> with either of the above options. If I use --prefix= during installation
> then the first option points to an invalid location and the second
> option fails with an error during installation but the rpm still gets
> installed so both cases fail but make some changes to file system.

...but relocation eliminates the "when possible" out of the picture.

> Can either of these options be made relocatable?
> For e.g. is there a variable that can be used in second case (something
> like |ln -sf %{foo_prefix}||/bin |||%{bar_prefix}|/newbin so
> %{foo_prefix} and %{bar_prefix} get changed during rpm installation
> depending on specified prefixes?

Those macros are expanded at the time of package build, whereas 
relocation is done at install-time. Relocations are passed to scriplets 
via RPM_INSTALL_PREFIX[n] environment variables (where n >= 0).

	- Panu -

> 2014-10-18 23:34 GMT+02:00 Domen Vrankar <domen.vrankar at gmail.com
> <mailto:domen.vrankar at gmail.com>>:
>
>     Hi,
>
>     I was searching the web and couldn't find an answer on how to
>     correctly write a spec file when packaging symlinks.
>
>     One option that I found was
>
>     %config /path/symlink
>
>     and the other was simply
>
>     /path/symlink
>
>     Based on Documentation
>     http://www.rpm.org/max-rpm/s1-rpm-inside-files-list-directives.html
>     am I correct in assuming that the second version (without any %
>     prefix) is the correct format?

Well that depends on what you want. Symlinks can be marked %config, but 
%config files have different semantics. If you have a symlink that is 
created or altered in install-time scriptlets, its probably best to 
package it as a %ghost (so it doesn't actually get packaged at all, but 
is considered owned and will be removed with the package):

%ghost /path/symlink

or at least tell rpm not to verify the link target, eg

%verify(not link) /path/symlink

>     Is there any difference in prefix if symlink points to directory or
>     file?

Yes there is, because those target are entirely different beasts. 
Symlinks to directories are generally considered equal to the target 
directory by rpm, rather than the symlink (known as "fingerprinting" in 
rpm jargon). These constructs are not problematic in itself, but they 
are hard to change on package upgrades and because of that, often best 
avoided. Symlinks to files are not special in rpm though.

	- Panu -


More information about the Rpm-list mailing list