DrStrangepork
DrStrangepork

Reputation: 3134

How to install a symlink within an rpm spec file

I've read through several other questions related to this issue, and I can't find a direct answer to my issue. I have to install several symlinks to /etc that point to files I am installing in /opt/myapp, so I need my files to look like this:

/etc/sysconfig/myapp -> /opt/myapp/etc/sysconfig/myapp

Right now my spec file looks like this:

%install
ln -sf %{buildroot}/etc/sysconfig/myapp /opt/myapp/etc/sysconfig/myapp

%files
%attr(0644, root, root) "/etc/sysconfig/myapp"
%dir %attr(0755, root, root) "/opt/myapp/etc/sysconfig"
%config(noreplace) %attr(0644, root, root) "/opt/myapp/etc/sysconfig/myapp"

When I run rpmbuild, I get this:

ln: failed to create symbolic link '/opt/myapp/etc/sysconfig/myapp': No such file or directory

I know this directory does not exist. It gets installed by the %files section, so how do I avoid this error here?

Upvotes: 0

Views: 1189

Answers (1)

Aaron D. Marasco
Aaron D. Marasco

Reputation: 6748

ln takes the target first, so it should be ln -sf /opt/myapp/etc/sysconfig/myapp %{buildroot}/etc/sysconfig/myapp

  • -s to make it a symlink
  • -f because /opt/myapp/etc/sysconfig/myapp doesn't need to exist on the build system

Upvotes: 1

Related Questions