如何在RPM spec文件中执行shell脚本?

时间:2016-06-03 13:41:26

标签: rpm rpmbuild rpm-spec

我有一个RPM,包括将文件放在目标计算机上。如何编写shell脚本,如果文件已经存在,则不要复制它。

说明

当RPM安装时,如果该文件已存在于该位置,则不应替换该文件。目前,它正在更换配置。我打算在%install脚本部分写一个条件。我尝试过它不起作用,抛出“else”/“fi”之类的错误。

1 个答案:

答案 0 :(得分:3)

在spec文件的%files部分;您可以使用%config(noreplace)标记文件。这样,如果文件已存在于目标机器上;它不会被覆盖(除非它没有被触及...查看更多细节here)。

如果您想保留现有文件,无论如何;然后你可以在%pre和%post部分乱七八糟,但如果你能......那就避免这样:

%pre
# gets executed before installation of the files: 
if [ -e /path/to/file]
then
    cp /path/to/file /path/to/backup
fi

%post
# gets executed after installatin of the files
if [ -e /path/to/file]
then
    cp /path/to/backup /path/to/file
fi
相关问题