简体   繁体   English

在RPM中创建符号链接

[英]Create symlink in RPM

I have a specific version of a software on Linux and I am packaging a .jar file (meant to upgrade the existing software) in an rpm and then trying to re-create a symlink to point to the latest version of the jar. 我在Linux上有一个特定版本的软件,我在rpm中打包.jar文件(用于升级现有软件),然后尝试重新创建一个符号链接以指向最新版本的jar。 I tried using %post and %postun to create and delete the symbolic link (in case it exists already), however this does not work. 我尝试使用%post%postun来创建和删除符号链接(如果它已经存在),但是这不起作用。 I have seen a few posts on the internet, but they did not work. 我在互联网上看到了一些帖子,但它们没有用。

As a workaround, I tried to create the symlink in puppet. 作为一种解决方法,我尝试在puppet中创建符号链接。 For this I used something like below: 为此,我使用了以下内容:

if $version == ‘1.1'  {
    file { '/usr/share/prog/software.jar':
    ensure  => 'symlink',
    target  => '/usr/share/prog/java/software-1.1-bin.jar',
}

But even here, the new version jar is getting created, but not the symlink. 但即使在这里,新版本的jar也会被创建,但不会创建符号链接。

Please let me know if anybody has solved this problem before. 如果有人以前解决了这个问题,请告诉我。

Below is the spec file that I had used: 下面是我使用的spec文件:

%define base_install_dir %{_datadir}/prog

Name:cdplayer
Version:1.1
Epoch:1
Release:2el6
Source:cdplayer-1.1-bin.jar
BuildArch:noarch
%description    
%prep
%install
%{__mkdir} -p %{buildroot}%{base_install_dir}
%{__install} -D -m 755 %{SOURCE0} %{buildroot}%{base_install_dir}

%post
ln -s -f /usr/share/prog/cdplayer-1.1-bin.jar /usr/share/prog/cdplayer.jar
%postun
%{__rm} -f /usr/share/prog/cdplayer.jar
%files
%defattr(-,root,root,-)
%dir %{base_install_dir}
%{base_install_dir}/*

%changelog

The given spec-file installs cdplayer-1.1-bin.jar , but links to cdplayer-1.1.jar . 给定的spec文件安装cdplayer-1.1-bin.jar ,但链接到cdplayer-1.1.jar Here is a diff showing changes I made to get it to work as intended: 这是一个差异显示我为使其按预期工作所做的更改:

--- foo.spec.orig   2015-11-16 20:34:48.000000000 -0500
+++ foo.spec        2015-11-16 20:44:08.017874483 -0500
@@ -1,21 +1,25 @@
 %define base_install_dir %{_datadir}/prog

+Summary: sample rpm spec-file
+License: unknown
 Name:cdplayer
 Version:1.1
 Epoch:1
 Release:2el6
-Source:cdplayer-1.1-bin.jar
+Source:%{name}-%{version}-bin.jar
 BuildArch:noarch
+%global actual %{name}-%{version}.jar
+%global linked %{name}.jar
 %description    
 %prep
 %install
 %{__mkdir} -p %{buildroot}%{base_install_dir}
-%{__install} -D -m 755 %{SOURCE0} %{buildroot}%{base_install_dir}
+%{__install} -D -m 755 %{SOURCE0} %{buildroot}%{base_install_dir}/%{actual}

 %post
-ln -s -f /usr/share/prog/cdplayer-1.1.jar /usr/share/prog/cdplayer.jar
+ln -s -f %{base_install_dir}/%{actual} %{base_install_dir}/%{linked}
 %postun
-%{__rm} -f /usr/share/prog/cdplayer.jar
+%{__rm} -f %{base_install_dir}/%{linked}
 %files
 %defattr(-,root,root,-)
 %dir %{base_install_dir}

There are a few problem areas in your spec-file to explore: 您的规范文件中有一些问题需要探索:

  • there is a flaw in the way upgrades are handled which would appear if you used yum (see Own RPM package: Make symlink survive update/freshen for example, which checks for the state before removing the link as a side-effect of package upgrade versus removal). 处理升级的方式有一个缺陷,如果你使用yum就会出现这种缺陷(参见自己的RPM包:例如, 使符号链接更新/清新 ,在删除链接之前检查状态,作为包升级的副作用去除)。
  • you are using the epoch tag which requires care, but the question gives no clue about the steps you use regarding it for upgrades. 您正在使用需要小心的epoch标签,但问题并未提供有关升级使用的步骤的线索。
  • if you install the package directly, for example, just changing the epoch value, you can end up with multiple copies of the same package. 如果直接安装软件包,例如,只更改epoch值,则最终可能会使用同一软件包的多个副本。

Adding a -v option to the rm and ln commands would show you more clearly what the package does when you install it. rmln命令中添加-v选项可以更清楚地显示安装程序包时的功能。

You should not create symlink in %post. 你不应该在%post中创建符号链接。 One of many reason is that this symlink is then not owned by rpm package. 其中一个原因是这个符号链接归rpm包所有。 If the symlink is owned by rpm package, then rpm handle it removal during upgrade itself. 如果符号链接由rpm包拥有,则rpm会在升级过程中处理它。

Please see: https://stackoverflow.com/a/32073947/3489429 请参阅: https//stackoverflow.com/a/32073947/3489429

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM