RPM 包初窺

Ankur Sinha發表於2019-10-13

也許,Fedora 社群追求其促進自由和開源的軟體及內容的使命的最著名的方式就是開發 Fedora 軟體發行版了。因此,我們將很大一部分的社群資源用於此任務也就不足為奇了。這篇文章總結了這些軟體是如何“打包”的,以及使之成為可能的基礎工具,如 rpm 之類。

RPM:最小的軟體單元

可供使用者選擇的“版本”和“風味版”(spins / labs / silverblue)其實非常相似。它們都是由各種軟體組成的,這些軟體經過混合和搭配,可以很好地協同工作。它們之間的不同之處在於放入其中的具體工具不同。這種選擇取決於它們所針對的用例。所有這些的“版本”和“風味版”基本組成單位都是 RPM 軟體包檔案。

RPM 檔案是類似於 ZIP 檔案或 tarball 的存檔檔案。實際上,它們使用了壓縮來減小存檔檔案的大小。但是,除了檔案之外,RPM 存檔中還包含有關軟體包的後設資料。可以使用 rpm 工具查詢:

$ rpm -q fpaste
fpaste-0.3.9.2-2.fc30.noarch

$ rpm -qi fpaste
Name        : fpaste
Version     : 0.3.9.2
Release     : 2.fc30
Architecture: noarch
Install Date: Tue 26 Mar 2019 08:49:10 GMT
Group       : Unspecified
Size        : 64144
License     : GPLv3+
Signature   : RSA/SHA256, Thu 07 Feb 2019 15:46:11 GMT, Key ID ef3c111fcfc659b9
Source RPM  : fpaste-0.3.9.2-2.fc30.src.rpm
Build Date  : Thu 31 Jan 2019 20:06:01 GMT
Build Host  : buildhw-07.phx2.fedoraproject.org
Relocations : (not relocatable)
Packager    : Fedora Project
Vendor      : Fedora Project
URL         : https://pagure.io/fpaste
Bug URL     : https://bugz.fedoraproject.org/fpaste
Summary     : A simple tool for pasting info onto sticky notes instances
Description :
It is often useful to be able to easily paste text to the Fedora
Pastebin at http://paste.fedoraproject.org and this simple script
will do that and return the resulting URL so that people may
examine the output. This can hopefully help folks who are for
some reason stuck without X, working remotely, or any other
reason they may be unable to paste something into the pastebin

$ rpm -ql fpaste
/usr/bin/fpaste
/usr/share/doc/fpaste
/usr/share/doc/fpaste/README.rst
/usr/share/doc/fpaste/TODO
/usr/share/licenses/fpaste
/usr/share/licenses/fpaste/COPYING
/usr/share/man/man1/fpaste.1.gz

安裝 RPM 軟體包後,rpm 工具可以知道具體哪些檔案被新增到了系統中。因此,刪除該軟體包也會刪除這些檔案,並使系統保持一致狀態。這就是為什麼要儘可能地使用 rpm 安裝軟體,而不是從原始碼安裝軟體的原因。

依賴關係

如今,完全獨立的軟體已經非常罕見。甚至 fpaste,連這樣一個簡單的單個檔案的 Python 指令碼,都需要安裝 Python 直譯器。因此,如果系統未安裝 Python(幾乎不可能,但有可能),則無法使用 fpaste。用打包者的術語來說,“Python 是 fpaste執行時依賴項。”

構建 RPM 軟體包時(本文不討論構建 RPM 的過程),生成的歸檔檔案中包括了所有這些後設資料。這樣,與 RPM 軟體包歸檔檔案互動的工具就知道必須要安裝其它的什麼東西,以便 fpaste 可以正常工作:

$ rpm -q --requires fpaste
/usr/bin/python3
python3
rpmlib(CompressedFileNames) <= 3.0.4-1
rpmlib(FileDigests) <= 4.6.0-1
rpmlib(PayloadFilesHavePrefix) <= 4.0-1
rpmlib(PayloadIsXz) <= 5.2-1

$ rpm -q --provides fpaste
fpaste = 0.3.9.2-2.fc30

$ rpm -qi python3
Name        : python3
Version     : 3.7.3
Release     : 3.fc30
Architecture: x86_64
Install Date: Thu 16 May 2019 18:51:41 BST
Group       : Unspecified
Size        : 46139
License     : Python
Signature   : RSA/SHA256, Sat 11 May 2019 17:02:44 BST, Key ID ef3c111fcfc659b9
Source RPM  : python3-3.7.3-3.fc30.src.rpm
Build Date  : Sat 11 May 2019 01:47:35 BST
Build Host  : buildhw-05.phx2.fedoraproject.org
Relocations : (not relocatable)
Packager    : Fedora Project
Vendor      : Fedora Project
URL         : https://www.python.org/
Bug URL     : https://bugz.fedoraproject.org/python3
Summary     : Interpreter of the Python programming language
Description :
Python is an accessible, high-level, dynamically typed, interpreted programming
language, designed with an emphasis on code readability.
It includes an extensive standard library, and has a vast ecosystem of
third-party libraries.

The python3 package provides the "python3" executable: the reference
interpreter for the Python language, version 3.
The majority of its standard library is provided in the python3-libs package,
which should be installed automatically along with python3.
The remaining parts of the Python standard library are broken out into the
python3-tkinter and python3-test packages, which may need to be installed
separately.

Documentation for Python is provided in the python3-docs package.

Packages containing additional libraries for Python are generally named with
the "python3-" prefix.

$ rpm -q --provides python3
python(abi) = 3.7
python3 = 3.7.3-3.fc30
python3(x86-64) = 3.7.3-3.fc30
python3.7 = 3.7.3-3.fc30
python37 = 3.7.3-3.fc30

解決 RPM 依賴關係

雖然 rpm 知道每個歸檔檔案所需的依賴關係,但不知道在哪裡找到它們。這是設計使然:rpm 僅適用於本地檔案,必須具體告知它們的位置。因此,如果你嘗試安裝單個 RPM 軟體包,則 rpm 找不到該軟體包的執行時依賴項時就會出錯。本示例嘗試安裝從 Fedora 軟體包集中下載的軟體包:

$ ls
python3-elephant-0.6.2-3.fc30.noarch.rpm

$ rpm -qpi python3-elephant-0.6.2-3.fc30.noarch.rpm
Name        : python3-elephant
Version     : 0.6.2
Release     : 3.fc30
Architecture: noarch
Install Date: (not installed)
Group       : Unspecified
Size        : 2574456
License     : BSD
Signature   : (none)
Source RPM  : python-elephant-0.6.2-3.fc30.src.rpm
Build Date  : Fri 14 Jun 2019 17:23:48 BST
Build Host  : buildhw-02.phx2.fedoraproject.org
Relocations : (not relocatable)
Packager    : Fedora Project
Vendor      : Fedora Project
URL         : http://neuralensemble.org/elephant
Bug URL     : https://bugz.fedoraproject.org/python-elephant
Summary     : Elephant is a package for analysis of electrophysiology data in Python
Description :
Elephant - Electrophysiology Analysis Toolkit Elephant is a package for the
analysis of neurophysiology data, based on Neo.

$ rpm -qp --requires python3-elephant-0.6.2-3.fc30.noarch.rpm
python(abi) = 3.7
python3.7dist(neo) >= 0.7.1
python3.7dist(numpy) >= 1.8.2
python3.7dist(quantities) >= 0.10.1
python3.7dist(scipy) >= 0.14.0
python3.7dist(six) >= 1.10.0
rpmlib(CompressedFileNames) <= 3.0.4-1
rpmlib(FileDigests) <= 4.6.0-1
rpmlib(PartialHardlinkSets) <= 4.0.4-1
rpmlib(PayloadFilesHavePrefix) <= 4.0-1
rpmlib(PayloadIsXz) <= 5.2-1

$ sudo rpm -i ./python3-elephant-0.6.2-3.fc30.noarch.rpm
error: Failed dependencies:
        python3.7dist(neo) >= 0.7.1 is needed by python3-elephant-0.6.2-3.fc30.noarch
        python3.7dist(quantities) >= 0.10.1 is needed by python3-elephant-0.6.2-3.fc30.noarch

理論上,你可以下載 python3-elephant 所需的所有軟體包,並告訴 rpm 它們都在哪裡,但這並不方便。如果 python3-neopython3-quantities 還有其它的執行時要求怎麼辦?很快,這種“依賴鏈”就會變得相當複雜。

儲存庫

幸運的是,有了 dnf 和它的朋友們,可以幫助解決此問題。與 rpm 不同,dnf 能感知到儲存庫。儲存庫是程式包的集合,帶有告訴 dnf 這些儲存庫包含什麼內容的後設資料。所有 Fedora 系統都帶有預設啟用的預設 Fedora 儲存庫:

$ sudo dnf repolist
repo id              repo name                             status
fedora               Fedora 30 - x86_64                    56,582
fedora-modular       Fedora Modular 30 - x86_64               135
updates              Fedora 30 - x86_64 - Updates           8,573
updates-modular      Fedora Modular 30 - x86_64 - Updates     138
updates-testing      Fedora 30 - x86_64 - Test Updates      8,458

在 Fedora 快速文件中有這些儲存庫以及如何管理它們的更多資訊。

dnf 可用於查詢儲存庫以獲取有關它們包含的軟體包資訊。它還可以在這些儲存庫中搜尋軟體,或從中安裝/解除安裝/升級軟體包:

$ sudo dnf search elephant
Last metadata expiration check: 0:05:21 ago on Sun 23 Jun 2019 14:33:38 BST.
============================================================================== Name & Summary Matched: elephant ==============================================================================
python3-elephant.noarch : Elephant is a package for analysis of electrophysiology data in Python
python3-elephant.noarch : Elephant is a package for analysis of electrophysiology data in Python

$ sudo dnf list \*elephant\*
Last metadata expiration check: 0:05:26 ago on Sun 23 Jun 2019 14:33:38 BST.
Available Packages
python3-elephant.noarch      0.6.2-3.fc30      updates-testing
python3-elephant.noarch      0.6.2-3.fc30              updates

安裝依賴項

現在使用 dnf 安裝軟體包時,它將解決所有必需的依賴項,然後呼叫 rpm 執行該事務操作:

$ sudo dnf install python3-elephant
Last metadata expiration check: 0:06:17 ago on Sun 23 Jun 2019 14:33:38 BST.
Dependencies resolved.
==============================================================================================================================================================================================
 Package                                      Architecture                     Version                                                        Repository                                 Size
==============================================================================================================================================================================================
Installing:
 python3-elephant                             noarch                           0.6.2-3.fc30                                                   updates-testing                           456 k
Installing dependencies:
 python3-neo                                  noarch                           0.8.0-0.1.20190215git49b6041.fc30                              fedora                                    753 k
 python3-quantities                           noarch                           0.12.2-4.fc30                                                  fedora                                    163 k
Installing weak dependencies:
 python3-igor                                 noarch                           0.3-5.20150408git2c2a79d.fc30                                  fedora                                     63 k

Transaction Summary
==============================================================================================================================================================================================
Install  4 Packages

Total download size: 1.4 M
Installed size: 7.0 M
Is this ok [y/N]: y
Downloading Packages:
(1/4): python3-igor-0.3-5.20150408git2c2a79d.fc30.noarch.rpm                                                                                                  222 kB/s |  63 kB     00:00
(2/4): python3-elephant-0.6.2-3.fc30.noarch.rpm                                                                                                               681 kB/s | 456 kB     00:00
(3/4): python3-quantities-0.12.2-4.fc30.noarch.rpm                                                                                                            421 kB/s | 163 kB     00:00
(4/4): python3-neo-0.8.0-0.1.20190215git49b6041.fc30.noarch.rpm                                                                                               840 kB/s | 753 kB     00:00
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                         884 kB/s | 1.4 MB     00:01
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                                      1/1
  Installing       : python3-quantities-0.12.2-4.fc30.noarch                                                                                                                              1/4
  Installing       : python3-igor-0.3-5.20150408git2c2a79d.fc30.noarch                                                                                                                    2/4
  Installing       : python3-neo-0.8.0-0.1.20190215git49b6041.fc30.noarch                                                                                                                 3/4
  Installing       : python3-elephant-0.6.2-3.fc30.noarch                                                                                                                                 4/4
  Running scriptlet: python3-elephant-0.6.2-3.fc30.noarch                                                                                                                                 4/4
  Verifying        : python3-elephant-0.6.2-3.fc30.noarch                                                                                                                                 1/4
  Verifying        : python3-igor-0.3-5.20150408git2c2a79d.fc30.noarch                                                                                                                    2/4
  Verifying        : python3-neo-0.8.0-0.1.20190215git49b6041.fc30.noarch                                                                                                                 3/4
  Verifying        : python3-quantities-0.12.2-4.fc30.noarch                                                                                                                              4/4

Installed:
  python3-elephant-0.6.2-3.fc30.noarch   python3-igor-0.3-5.20150408git2c2a79d.fc30.noarch   python3-neo-0.8.0-0.1.20190215git49b6041.fc30.noarch   python3-quantities-0.12.2-4.fc30.noarch

Complete!

請注意,dnf 甚至還安裝了python3-igor,而它不是 python3-elephant 的直接依賴項。

DnfDragora:DNF 的一個圖形介面

儘管技術使用者可能會發現 dnf 易於使用,但並非所有人都這樣認為。Dnfdragora 透過為 dnf 提供圖形化前端來解決此問題。

dnfdragora (version 1.1.1-2 on Fedora 30) listing all the packages installed on a system.

從上面可以看到,dnfdragora 似乎提供了 dnf 的所有主要功能。

Fedora 中還有其他工具也可以管理軟體包,GNOME 的“軟體Software”和“發現Discover”就是其中兩個。GNOME “軟體”僅專注於圖形應用程式。你無法使用這個圖形化前端來安裝命令列或終端工具,例如 htopweechat。但是,GNOME “軟體”支援安裝 dnf 所不支援的 Flatpak 和 Snap 應用程式。它們是針對不同目標受眾的不同工具,因此提供了不同的功能。

這篇文章僅觸及到了 Fedora 軟體的生命週期的冰山一角。本文介紹了什麼是 RPM 軟體包,以及使用 rpmdnf 的主要區別。

在以後的文章中,我們將詳細介紹:

  • 建立這些程式包所需的過程
  • 社群如何測試它們以確保它們正確構建
  • 社群用來將其給到社群使用者的基礎設施

via: https://fedoramagazine.org/rpm-packages-explained/

作者:Ankur Sinha FranciscoD 選題:lujun9972 譯者:wxy 校對:wxy

本文由 LCTT 原創編譯,Linux中國 榮譽推出

相關文章