Skip to content

antony@notes:~/suse$ cat "Software-Management.md"

Software Management

2023-04-07· suse ·SUSE Linux Enterprise Server

Software Management

Preface

本篇文章主要分為 3 大部分 :

  1. 了解將源程式碼編譯成二進位碼的基本步驟及編譯後的缺點
  2. 了解什麼是 RPM Package,它的組成是什麼,我們如何管理它,包含安裝、解安裝、更新、查詢和確認。
  3. 如何透過 Libzypp 管理軟體

:::warning

:::spoiler 文章目錄

[TOC]

:::

Understand Compiling Software from Source

Compile From Source Code

  • Linux Source Code Build Tools
  • Works well for a single box
  • Many Linux open source projects utilize
  • Common GNU build tools
  • Two common GNU build tools
    • Automake
    • Autoconf
  • Developers use Automake and Autoconf with…
    • makefile.am
    • configure.in
  • To create the automatic configuration file
    • configure

Compiling Process

  • The general process for building source code
    • ./configure
    • make
    • make install
  • Make supports combining last two steps
    • ./configure
    • make install
  • Performs a make and then a make install automatically

Build Process Step-By-Step

  • Specific actions for building source code
  • Download tarball from source code download page
    • .tar.gz .tgz .tar.bz2
  • Extract contents in safe location
    • tar -zxvf sourcecode-1.0.tar.bz2
  • Change to extracted directory
    • cd sourcecode-1.0/
  • Read the included Documentation
  • Autoconfigure
    • ./configure
  • Compile and install
    • make install

Understand Makefile Targets

  • The make command uses what are called “targets”
  • Target Actions:
    • clean
      • Clean up: remove compiled binaries and objects
    • distclean
      • clean + remove files that ./configure created
    • make
      • Actually compile the source code
    • install
      • Copy binaries and shared objects to filesystem
  • uninstall
    • Uninstall the components created during install
    • Does not always remove all components
    • Only as good as creator of the Automake components
    • Not always provided as target in Makefile
    • May abandon software throughout filesystem

Use make to Compile the Source Code

Disadvantages Of Unpackaged Software

  • Software dependencies are not readily apparent
  • Hard to duplicate effort across enterprises (難以跨企業重複工作)
  • Upgrading very difficult
  • Updating nearly(幾乎) impossible
  • Slow security responses (安全問題的回應速度緩慢)
  • Duplication of effort(工作重複)
  • Uneven results(結果可能會不一樣)
  • Support and troubleshooting problems
    • Tarball management is fine for a single computer
    • Unmanageable across hundreds or thousands of computers
  • Difficult to track installed files without work
    • Manual tracking after each install
    • Linux command line tools
      • find
      • tar
      • md5sum
      • vimdiff
  • Uses some disk space for tracking
  • Non-filesystem tracking requires reading install control files(非檔案系統的追蹤需要讀取安裝控制的文件)
    • configure
    • Makefile

Understand Management of RPM Packages

RPM Basics

RPM 是一個在 Linux 上用來管理軟體的工具,主要由以下三個部分組成:

  • RPM Package Manager:用來安裝和卸載 RPM 套件。
  • RPM Database:這個資料庫在 Package Manager 的背後運作,裡面包含所有已安裝的 RPM 套件的相關資訊。
    • 這個資料庫追蹤所有在使用者安裝程式時建立或修改的檔案,這有助於 Package Manager 在需要時輕鬆地移除原本安裝的檔案。
  • RPM Package:將軟體原始程式碼打包成二進位的程式碼供使用者安裝,稱為 RPM packages 或 RPM archives,中文翻為 “RPM 套件”。

使用 RPM Package Manager 和 RPM Package 的好處有:

  • Root 在 Linux 上有一致的安裝程式方法。
  • 方便的卸載功能(因為有 RPM 資料庫)。
  • 原始碼存檔案(例如 .tar.gz 或 .tar.bz2)會依需求被包含進來,也很容易驗證。
  • RPM 工具可以用來啟用非互動式腳本來安裝軟體。
  • RPM 工具可以用來確認軟體是否正確安裝。
  • RPM 追蹤套件的相依檔,防止刪除其他套件所需的套件。它還會在安裝套件時告知管理員所需的軟體是否缺失。
  • 支援數位簽章,可驗證 RPM 套件的完整性。

RPM Package Components

The RPM package includes the following parts:

  • Information Header
    • 每個 RPM 套件有一個標籤,裡面包含 Software Name、Version 和 Release Number (發行編號) …等資訊。
  • CPIO Archive
    • 套件的所有檔案都存放在 CPIO archive 中。
  • Installation Scripts
    • 有時在安裝軟體之前或之後需要對系統進行修改,這可以通過預安裝和後安裝腳本來實現。
  • GPG Signature
    • 這個簽名可以檢查軟體包的完整性。

Install RPM Packages

  • Command: rpm -i <package>.rpm
    • 當您安裝一個 RPM 軟體包時,執行檔DOC 文件設定檔以及啟動腳本會被複製到檔案系統中適當的目錄下。
  • Additional Options:
    • -v ,(verbose) for more information ,顯示更多資訊
    • -h ,(hash) for a progress bar,在軟體包安裝期間產生一個由#符號組成的進度條。
  • In case of dependency conflicts or file problems:
    • --nodeps ,to ignore dependencies ,忽略相依檔產生的問題
    • --force ,to overwrite existing files,覆蓋已存在的檔案
    • 如果強制安裝而沒有滿足相依性要求,安裝的軟體很可能無法正常運作

在安裝期間,RPM 資料庫確保沒有發生衝突(例如一個檔案屬於多個軟體包)。只有在其相依性得到滿足且沒有與其他軟體包發生衝突時,才會安裝該軟體包。

如果相依性沒有被滿足,RPM 會列出 :

  • 需要安裝軟體包的相依檔。
  • 與要安裝的軟體包發生衝突的軟體包。

Update RPM Packages

  • Update: rpm -U <package>.rpm
    • Works even if no previous version is installed
    • 即使未安裝以前的版本 也會安裝新版本
  • Freshen: rpm -F <package>.rpm
    • Work only if a previous version is installed
    • 僅在安裝了早期版本時才有效 (如果沒有安裝過先前的版本,則不會安裝新的軟體包。)
    • 會刪除舊版本的文件,並立即安裝新的文件。
  • 注意 ! -U 選項並不等同於使用 -e 選項進行卸載並使用 -i 選項進行安裝。更新軟體包時,盡可能使用 -U 選項

RPM 會使用以下指南小心地更新設定檔:

  1. 如果系統管理員未更改設定檔,RPM 會安裝適當檔案的新版本。系統管理員不需要進行任何操作。
  2. 如果在更新之前系統管理員更改了設定檔,RPM 會將更改後的檔案保存為 .rpmorig.rpmsave (備份檔案),然後安裝新包的版本,但只有當原安裝的檔案和新版本不同時才進行安裝。
    • 如果是這種情況,請將備份檔案(.rpmorig.rpmsave)與新安裝的檔案進行比較,再次在新檔案中進行更改。
    • 確保之後刪除所有的 .rpmorig.rpmsave 檔案,以避免未來更新的問題。
    • 如果檔案以前尚未被 RPM 資料庫識別,則會分配 .rpmorig 擴展名;否則,使用 .rpmsave 擴展名。
    • 換句話說,.rpmorig 是從非 RPM 格式升級到 RPM,而 .rpmsave 則是從舊版 RPM 升級到新版 RPM。
  3. 如果設定檔已經存在且在控制軟體包創建的檔案 (所謂的 .spec 檔案) 中指定了 noreplace 標籤,則會建立一組 .rpmnew 檔案。這用於不覆蓋某些設定檔 (例如 /etc/apache2/httpd.conf),以確保繼續運作。
    • .rpmnew 不會透露系統管理員是否對設定檔進行了任何更改。

Uninstall RPM Packages

  • Command: rpm -e <package>
  • Additional Options:
    • --nodeps to ignore dependencies

當移除一個套件時,RPM 資料庫會協助將所有檔案除了已修改的設定檔都從系統中刪除,確保移除的乾淨無痕。

RPM 只會在不影響相依套件的情況下刪除套件。若有其他套件相依於欲刪除的套件,錯誤訊息中會列出這些相依套件。

使用 --nodeps 參數強制刪除套件,但這不是建議的方式,因為有使用同樣相依檔的其他套件可能會無法正常運作。

Query RPM Database and Packages

  • -q,Query RPM database
  • Common query options:
    • -a,List all installed packages
    • -i,List package information
    • -l,Display file list
      • --dump,Display a file list with complete details Used with -l, -c or -d
    • -f <file>,找出檔案屬於哪個包,在查詢的時候,必須指定完整路徑
    • -d,List only documentation files (implies -l)
    • -c,List only configuration files (implies -l)
  • -p ,Inspect not installed RPM archives
  • --provides,List features of the package that another package can request with –requires
    • 列出一個套件可以透過 --requires 的方式要求另一個套件提供哪些功能特色。
  • --requires, -R,List capabilities the package requires
  • --scripts,List installation scripts Pre-install, post-install and un-install
  • --changelog,Display detailed list of information about a specific package Updates, configuration, modifications, etc.

RPM Package Verification

  • Verify that the package has not changed since it was created:
    • rpm --checksig <package>.rpm
  • Verify integrity (完整性) of files installed by an RPM package:
    • rpm -V <package>
  • Character,Description
    • S,List package information
    • M,Mode has change
    • 5,Size is different
    • D,Device major/minor numbers are different
    • L,Readlink (symbolic link) path mismatch
    • U,User ownership differs
    • G,Group ownership differs
    • T,mtime differs
    • P,Capabilities differ

Understand Software Management with Libzypp

Libzypp

![](https://i.imgur.com/5g14Iuq.png =80%x)

Libzypp is the software management engine for SUSE Linux. It wraps around (環繞) the RPM package management system.

What Are Software Repositories?

Software repositories (often called catalogs)

  • Directories that contain RPM software packages and meta-data files that describe the packages.
  • Can be accessed by RPM meta-managers
  • Can be accessed from different media and local file systems
    • different media such as the network (HTTP, FTP, NFS, SMB, etc.), DROM/DVD disks

Software repositories provide many benefits such as:

  • They provide catalogs(目錄) for RPM Meta-managers to use when doing RPM dependency resolution
  • They provide centrally(集中的) managed and accessible sources(可存取的來源) for installing software and updates
  • They provide a framework for tracking and finding different versions of software

Libzypp and Software Repositories

![](https://i.imgur.com/kKNBnF7.png =80%x)

The 4 “P"s of Libzypp

  • Packages
    • RPM packages (including patch/delta RPMS)
    • Contain files to be installed in file system
  • Patterns
    • Reference 1 or more packages
    • Typically install all packages needed for a certain sever “role”
  • Products
    • Contain 1 or more Patterns
    • Associated with a product with its own support and maintenance such
    • as an Extension/Add-on
  • Patches
    • Reference 1 or more update packages
    • (packages provided as both full and patch/delta RPMs)

Libzypp Utilities

![](https://i.imgur.com/FHppQTm.png =90%x)

你會使用幾種不同的工具來實際進行套件管理,這些工具在背後使用了 libzypp 提供的服務。這些工具可以是圖形介面的,像是 YaST 和 PackageKit,也可以是命令列工具,像是 zypper 和 YaST ncurses 的畫面。

Definition of Terms

Repository

一個包含 packages 的本地或遠程目錄,以及關於這些 packages 的 metadata。

Product

代表一個完整的產品,例如 SUSE Linux Enterprise Server。

Pattern

一個可安裝的軟體套件組合,專門用於特定的目的。 例如,Laptop pattern,這個 pattern 包含所有行動運算環境所需的套件。

Pattern 定義了 package 之間的相依性(例如必須或建議安裝的套件),並且預先選擇了一些套件標記為安裝,這確保在安裝 Pattern 後,系統上可用於特定目的的最重要 package 都已經安裝。但是,並不一定所有的 Pattern 中的 package 都會被預先選擇安裝,你可以根據自己的需求手動選擇或取消選擇 Pattern 內的 package。

Package

一個壓縮的 RPM 格式檔案,包含了特定程式的檔案。

Patch

由一個或多個軟體包組成,可以透過 Delta RPMs 方式應用。它也可能會引入尚未安裝的軟體包相依性。

Resolvable

產品、模式、軟體包或補丁的通用詞彙。最常用的 Resolvable 為軟體包或補丁。

Delta RPM

由兩個已定義版本之間的二進位差異組成,因此具有最小的下載大小。在安裝前,完整的 RPM 軟體包會在本地機器上重建。

Package Dependencies

有些套件需要其他套件才能運作,例如共用程式庫。換句話說,某些套件可能需要其他套件才能被安裝。如果所需的套件沒有安裝,該套件就無法被安裝,除了必須滿足的相依性需求外,有些套件還會建議安裝其他套件。如果這些推薦的套件實際上可用,那麼它們就會被安裝,否則就會被忽略,而推薦它們的套件則仍會被安裝。

Manage Repositories with zypper

  • List software repositories:
    • zypper lr
  • Add repositories:
    • zypper ar <uri> <alias>
  • Remove repositories:
    • zypper rr <alias|#|uri>
  • Modify repositories:
    • zypper mr [options] <alias|#|uri>

zypper relies on a list of repositories for its installation and update commands. To list all repositories known to the system, enter zypper lr or zypper repos

範例 : 

~> zypper lr

螢幕輸出 :

# | Alias | Name | Enabled | Refresh
--+-------------+-------------+---------+--------
1 | SLES15-15-0 | SLES15-15-0 | Yes | No

The most important options for this command are

  • -p,show the priority(優先等級) for each repository
  • -d,show more details for each repository

範例 : 

~> zypper lr -d

螢幕輸出 :

# | Alias | Name | Enabled | Refresh | Priority | Type | URI
 | Service
--+-------------+-------------+---------+---------+----------+-------
+----------------------------------------------------------------------------------------+--------
1 | SLES15-15-0 | SLES12-15-0 | Yes | No | 99 | yast2 | cd:///?devices=/dev/disk/by-id/ataVMware_Virtual_IDE_CDROM_Drive_10000000000000000001 |

To add a new repository, use the command

~> zypper ar [options] <uri> <alias>

or

~> zypper addrepo [options] <uri> <alias>

範例 :

~> zypper addrepo http://172.17.8.100/sles15/CD1 sles12
  • The URI identifies the location of the repository
  • the alias sets a name which can be used to access the repository

Important options for this command are:

  • -d,add the repository as disabled. Repositories are added as enabled by default.
  • -k,Enable RPM files caching for the repository (i.e., RPM packages are kept in a local directory after being installed).
  • -K,Disable RPM files caching.

NOTE: When a repository is added, the existence(已存在的) and accessibility(可訪問的) of the repository is not checked. If there are any errors in the URI these will show up when trying to access the repository later

In order to remove a repository from the list, use the command

zypper rr <alias|#|uri>

or

zypper removerepo <alias|#|uri>

To specify the repository, you can use the alias, the sequence number or the whole URI of the repository.

Existing repositories can be modified by using

zypper mr [options] <alias|#|uri>

or

zypper modifyrepo [options] <alias|#|uri>

The following are the most important options for this command:

  • -e,Enable the repository.
  • -d,Disable the repository.
  • -p,Set priority of the repository.

A priority of 1 is the highest prioritythe higher the number the lower the priority. The default priority is 99. Packages from repositories with higher priority will be preferred even in case there is an installable higher version available in the repository with a lower priority.

These commands create .repo files in the /etc/zypp/repos.d/ directory.

Note: These .repo files can be edited directly if desired.

Manage Packages with zypper

Manage Patterns with zypper

Manage Patches with zypper

Manage Updates with zypper

Network ManagementStorage Management