rpm 子包创建学习
rpm 在打包的时候,可以创建子包,这样可以清晰的进行软件包的拆分,以下是结合官方文档学习
的一个实践
预备条件
需要安装rpmdevtools
spec 文件
- 内容
Name: foo
Version: 2.7
Release: 1
License: apache
Summary: dalong demo rpm subpacakge
Group: dalong/dalong
%description
This is the long description of the foo app, and the baz library needed to
build it
%package server
Summary: The foo server
Group: dalong/dalong
%description server
This is the long description for the foo server
%package client
Summary: The foo client
Group: dalong/dalong
%description client
This is the long description for the foo client
%package -n bazlib
Version: 5.6
Summary: The baz library
Group: dalong/dalong
%description -n bazlib
This is the long description for the bazlib
%pre
echo "This is the foo package preinstall script"
%build
cat > main.sh <<EOF
#!/bin/sh
echo "main"
EOF
cat > server.sh <<EOF
#!/bin/sh
echo "server"
EOF
cat > client.sh <<EOF
#!/bin/sh
echo "client"
EOF
cat > bazlib.sh <<EOF
#!/bin/sh
echo "bazlib"
EOF
%install
mkdir -p %{buildroot}/usr/local/
install -m 755 main.sh %{buildroot}/usr/local/main.sh
install -m 755 server.sh %{buildroot}/usr/local/server.sh
install -m 755 client.sh %{buildroot}/usr/local/client.sh
install -m 755 bazlib.sh %{buildroot}/usr/local/bazlib.sh
%pre server
echo "This is the foo-server subpackage preinstall script"
%pre client
echo "This is the foo-client subpackage preinstall script"
%pre -n bazlib
echo "This is the bazlib subpackage preinstall script"
%files
/usr/local/main.sh
%files server
/usr/local/server.sh
%files client
/usr/local/client.sh
%files -n bazlib
/usr/local/bazlib.sh
- 简单说明
子包通过%package <name>
格式声明,默认生成的名称为父-子
名称 我们可以通过-n
声明自己的
对于pre、post 阶段, 我们可以定义自己的script,比如以上的pre 阶段
构建&&效果
- 构建
rpmbuild -ba foo-2.7.spec
效果
正在执行(%build):/bin/sh -e /usr/local/var/tmp/rpm-tmp.j3G7re
+ umask 022
+ cd /Users/dalong/rpmbuild/BUILD
+ cat
+ cat
+ cat
+ cat
+ exit 0
正在执行(%install):/bin/sh -e /usr/local/var/tmp/rpm-tmp.Maa2R7
+ umask 022
+ cd /Users/dalong/rpmbuild/BUILD
+ mkdir -p /Users/dalong/rpmbuild/BUILDROOT/foo-2.7-1.x86_64/usr/local/
+ install -m 755 main.sh /Users/dalong/rpmbuild/BUILDROOT/foo-2.7-1.x86_64/usr/local/main.sh
+ install -m 755 server.sh /Users/dalong/rpmbuild/BUILDROOT/foo-2.7-1.x86_64/usr/local/server.sh
+ install -m 755 client.sh /Users/dalong/rpmbuild/BUILDROOT/foo-2.7-1.x86_64/usr/local/client.sh
+ install -m 755 bazlib.sh /Users/dalong/rpmbuild/BUILDROOT/foo-2.7-1.x86_64/usr/local/bazlib.sh
+ /usr/local/Cellar/rpm/4.14.1/lib/rpm/brp-compress
+ /usr/local/Cellar/rpm/4.14.1/lib/rpm/brp-strip /usr/bin/strip
+ /usr/local/Cellar/rpm/4.14.1/lib/rpm/brp-strip-static-archive /usr/bin/strip
+ /usr/local/Cellar/rpm/4.14.1/lib/rpm/brp-strip-comment-note /usr/bin/strip /usr/bin/objdump
处理文件:foo-2.7-1.x86_64
Provides: foo = 2.7-1 foo(x86-64) = 2.7-1
Requires(interp): /bin/sh
Requires(rpmlib): rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(FileDigests) <= 4.6.0-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1
Requires(pre): /bin/sh
Requires: /bin/sh
处理文件:foo-server-2.7-1.x86_64
Provides: foo-server = 2.7-1 foo-server(x86-64) = 2.7-1
Requires(interp): /bin/sh
Requires(rpmlib): rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(FileDigests) <= 4.6.0-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1
Requires(pre): /bin/sh
Requires: /bin/sh
处理文件:foo-client-2.7-1.x86_64
Provides: foo-client = 2.7-1 foo-client(x86-64) = 2.7-1
Requires(interp): /bin/sh
Requires(rpmlib): rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(FileDigests) <= 4.6.0-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1
Requires(pre): /bin/sh
Requires: /bin/sh
处理文件:bazlib-5.6-1.x86_64
Provides: bazlib = 5.6-1 bazlib(x86-64) = 5.6-1
Requires(interp): /bin/sh
Requires(rpmlib): rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(FileDigests) <= 4.6.0-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1
Requires(pre): /bin/sh
Requires: /bin/sh
检查未打包文件:/usr/local/Cellar/rpm/4.14.1/lib/rpm/check-files /Users/dalong/rpmbuild/BUILDROOT/foo-2.7-1.x86_64
已写至:/Users/dalong/rpmbuild/SRPMS/foo-2.7-1.src.rpm
已写至:/Users/dalong/rpmbuild/RPMS/x86_64/foo-2.7-1.x86_64.rpm
已写至:/Users/dalong/rpmbuild/RPMS/x86_64/foo-server-2.7-1.x86_64.rpm
已写至:/Users/dalong/rpmbuild/RPMS/x86_64/foo-client-2.7-1.x86_64.rpm
已写至:/Users/dalong/rpmbuild/RPMS/x86_64/bazlib-5.6-1.x86_64.rpm
正在执行(%clean):/bin/sh -e /usr/local/var/tmp/rpm-tmp.wO2CmJ
+ umask 022
+ cd /Users/dalong/rpmbuild/BUILD
+ /bin/rm -rf /Users/dalong/rpmbuild/BUILDROOT/foo-2.7-1.x86_64
+ exit 0
- 查看rpm 包信息
默认生成的文件存储路径~/rpmbuild/RPMS/x86_64
生成的内容
├── bazlib-5.6-1.x86_64.rpm
├── foo-2.7-1.x86_64.rpm
├── foo-client-2.7-1.x86_64.rpm
└── foo-server-2.7-1.x86_64.rpm
查看一个包的信息
rpm -qip foo-client-2.7-1.x86_64.rpm
Name : foo-client
Version : 2.7
Release : 1
Architecture: x86_64
Install Date: (not installed)
Group : dalong/dalong
Size : 24
License : apache
Signature : (none)
Source RPM : foo-2.7-1.src.rpm
Build Date : 日 11/ 3 09:39:07 2019
Build Host : dalongrong.local
Relocations : (not relocatable)
Summary : The foo client
Description :
This is the long description for the foo client
说明
以上是一个简单的学习,实际中我们需要结合实际项目添加更多的配置,同时还需要考虑分发。。。。好多事情
参考资料
https://docs.fedoraproject.org/en-US/Fedora_Draft_Documentation/0.1/html/RPM_Guide/ch10s04s02.html
http://ftp.rpm.org/max-rpm/s1-rpm-subpack-spec-file-changes.html
https://github.com/rongfengliang/rpm-subpackage-learning