首頁 > 軟體

rpm 子包建立實踐

2020-06-16 16:29:35

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 


IT145.com E-mail:sddin#qq.com