- 建立相關的目錄結構 rpmbuild/BUILD rpmbuild/BUILDROOT rpmbuild/RPMS rpmbuild/SOURCES rpmbuild/SPECS rpmbuild/SRPMS
- 將資料擺進 rpmbuild/SOURCES 位置
- 撰寫 rpmbuild/SPECS/example.spec
- 切換進 rpmbuild/SPECS 執行 rpmbuild -bb example.spec
這邊要筆記的是 example.spec 這個檔案格式:
- % 開頭的是 spec 的保留指令(Macro),例如 %define 是定義變數,而 %description, %prep, %setup, %build, %install, %files, %changelog, %clean 則是對應的狀態
- %prep 下方的位置代表預備動作
- %setup 代表進行 Source 解壓縮
- %build 例如執行 make 指令
- %install 開始執行建立 RPM 的動作,可把所需檔案進行搬移
- %files 成列出真正要打包的檔案列表,若沒列的話,RPM 會產生不了
- %clean 打包完 rpm 後的動作,例如清掉資料等
- 其他資訊
- Summary:
- Name:
- Version: 1.0
- Release: 1
- Vendor: vendor
- Packager: packager
- License: BSD
- Group: Applications/File
- SOURCE: your_source_be_extraced_at_setup_macro.tar.gz
- BuildArch: noarch
- BuildRoot: %BuildRoot
%define Name test-repo
%define Source test-repo.tar.gz
%define Version 1.0
%define Release 1
%define RPM_ARCH x64_86
%define OWNER root
%define Vendor no
%define Packager no
%define License MIT
%define Group Applications/File
%define INSTALL_DIR /opt/%NAME
%define _topdir /tmp/rpm-build
%define RPM_BUILD_ROOT _topdir
%define BuildRoot /tmp/rpm-build/BUILDROOT/%Name-%Version-%Release.%RPM_ARCH
Summary: %Name
Name: %Name
Version: %Version
Release: %Release
Vendor: %Vendor
Packager: %Packager
License: %License
Group: %Group
SOURCE: %Source
%description
%prep
%setup -q
%build
%install
install -d %BuildRoot/%INSTALL_DIR
cp -r $PACKAGE_DIR/*.* %BuildRoot/%INSTALL_DIR
%files
%INSTALL_DIR
%defattr(-,%OWNER,%OWNER,-)
%changelog
最後,我打包成一個 bash script 來筆記 :p 有需要可以試試看,但要留意 bash script 有刪檔的動作,若擔心可以先把刪檔的動作註解起來:
$ git clone https://github.com/changyy/rpm-builder
$ cd rpm-builder
$ bash rpm_build_for_files_archive.sh
Usage> bash rpm_build_for_files_archive.sh SOURCE_DIR RPM_OUTPUT_DIR RPM_PACKAGE_NAME RPM_PACKAGE_VERSION RPM_PACKAGE_VERSION RPM_PACKAGE_INSTALL_DIR
$ bash rpm_build_for_files_archive.sh /etc/yum.repos.d/ /tmp test-yum 1.0 1 /opt
產出 /tmp/test-yum-repos-1.0-1.noarch.rpm ,會安裝在 /opt/test-yum 目錄
最後提一下 rpm 相關指令,方便 debug 用途:
- 安裝
- $ rpm -ivh your.rpm
- 解除安裝
- $ rpm -e your_package_name
- 查詢描述資料
- $ rpm -qi your_package_name
- 列出 rpm 所安裝的檔案清單
- $ rpm -q --filesbypkg your_package_name
- 查詢檔案是屬於哪個 rpm
- $ rpm -qf /opt/path/filename
- 列出所有已安裝的 rpm 清單,可搭配 grep 挑選關鍵字出來
- $ rpm -qa
沒有留言:
張貼留言