【问题标题】:.spec file is creating an empty .rpm.spec 文件正在创建一个空的 .rpm
【发布时间】:2017-03-28 00:53:17
【问题描述】:

我正在尝试创建一个 RPM 来解压缩 tar,更改一些权限,然后根据进程回显某些内容。这是有问题的.spec 文件。

Summary: Linux agent V.1
Name: Agent
Version: 1.0
Release: 1
License: GPL
Source: Agent.tar.gz
Vendor: test
Packager: test


%description
Test Linux agent

%prep
if ps aux | grep "[u]cx"; then
  pkill -f ucx
else
  echo "Current agent is not running."
fi
%setup -n Agent
%install
cp -r /root/rpmbuild/BUILD/Agent /local/0/opt
cd /local/0/opt/Agent
chown -R root.root *
cd bin/
chown root.root test1 test2
chmod 775 test1 test2
chmod +s  test1 test2
if ps aux | grep "[u]cy"; then
  echo "managerup"
else
  echo "manager down"
fi
%files
%clean
rm -rf /root/rpmbuild/BUILD/Agent

在构建时,.spec 文件会干净地构建并创建一个 rpm。它还运行命令,我在/local/0/opt 中获得相关文件。有问题的构建命令是rpmbuild -ba agent.spec。我已经尝试在详细模式下执行此操作,它也没有真正给我一个错误。

但是,生成的.rpm 文件是空的,实际上并没有做任何事情。我认为这是.spec 文件的问题。但是,由于输出根本没有给我一个错误,我不确定问题是什么。

我一直关注http://www.rpm.org/max-rpm/s1-rpm-build-creating-spec-file.html

我认为问题出在%files 部分。我希望它只是将 tar 部署到 local/0/opt,但我对在哪里声明安装目录以及在哪里声明我想要的包中的内容感到困惑。

【问题讨论】:

    标签: rpm rpm-spec


    【解决方案1】:

    您需要将/local/0/opt 添加到您的%files 部分

    %files
    /local/0/opt
    

    这指示 rpm 构建过程在哪里找到它应该在最后打包的文件。

    您还需要在%install 中安装和操作相对于您的 rpm buildroot 的文件

    %install
    mkdir -p %{buildroot}/local/0
    cp -r /root/rpmbuild/BUILD/Agent %{buildroot}/local/0/opt
    cd %{buildroot}/local/0/opt/Agent
    

    因为 rpm 构建过程会在其中查找要打包的文件。

    您可能想要清理该规范文件一些内容,包括将%clean 放在%files 上方并将%install 操作移动到%build 中。

    【讨论】:

    • 嗨,马特。我实际上在发布之前尝试过。这是它给我的错误。 RPM build errors: Directory not found: /root/rpmbuild/BUILDROOT/AutomicAgent-1.0-1.x86_64/local/0/opt
    • 感谢您的帮助。不幸的是,我仍然收到错误+ cp -r /root/rpmbuild/BUILD/Agent /root/rpmbuild/BUILDROOT/Agent-1.0-1.x86_64/local/0/opt cp: cannot create directory '/root/rpmbuild/BUILDROOT/Agent-1.0-1.x86_64/local/0/opt': No such file or directory 我将尝试将 buildroot 设置在规范文件的顶部。只是为了确保 /root/rpmbuild/BUILD/{name} 是默认的 buildroot?
    • @Pudding 您必须按照错误消息并在 buildroot 中创建该目录才能成功复制。使用mkdir 再次更新答案。
    • 这让我有点困惑。就 rpm 而言,buildroot 是安装目录还是别的什么?我认为/root/rpmbuild/BUILD/Agent 是buildroot,local/0/opt 是我想要的安装目录。
    • 从我收集的信息来看,我认为 buildroot 只是一个用于解包的临时区域。我很困惑为什么我需要在那里创建一个文件。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-07
    • 1970-01-01
    • 2017-11-28
    • 1970-01-01
    • 2021-10-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多