当前位置:网站首页>How to create an rpm package
How to create an rpm package
2022-08-05 01:30:00 【oneslide】
This article shows how to package scripts into rpm格式的文件
什么是RPM包?
RPM是Red Hat Package Manager的简称,rpm包可以在redhatSeries systems are easy to install,更新,卸载.包括Fedora, CentOS, RHEL, etc.
RPM包使用.rpm
扩展名,是一个压缩包,包含
- 二进制文件(nmap, stat, xattr, ssh, sshd, and so on)
- 配置文件 (sshd.conf, updatedb.conf, logrotate.conf, etc.)
- 文档 (README, TODO, AUTHOR, etc)
rpmThe general format of the package name:
<name>-<version>-<release>.<arch>.rpm
例如:
bdsync-0.11.1-1.x86_64.rpm
Some packages also containrpmapplicable platform:
bdsync-0.11.1-1.el8.x86_64.rpm
如何创建rpm包
1. 安装rpm开发工具
yum install -y rpmdevtools rpmlint
2. 创建rpmPackage development directory
创建rpmThe development directory for the package,位置一般在$HOME/rpmbuild
:
$ rpmdev-setuptree
The development directory structure and function are as follows:
rpmbuild/
├── BUILD
├── RPMS
├── SOURCES
├── SPECS
└── SRPMS
- BUILD 目录用于存放rpmTemporary files generated during the build process
- RPMS Directory to store resultsrpm包
- SOURCES 目录存放源码. Can be a simple script,Complex that needs to be compiledC项目.The format of the source code is usually
.tar.gz
或者.tgz
- SPEC 目录存放.spec文件, .specfile is used to define how to packagerpm
- SPRPMS 存放.src.rpm包,The source package does not belong to any architecture eitherLinux发行版. 实际的.rpm包是基于.src.rpm包构建的.
创建一个简单的rpm包
- 创建一个简单的脚本
$ cat << EOF >> hello.sh #!/bin/sh echo "Hello world" EOF
- 创建源码包
mkdir hello-0.0.1
mv hello.sh hello-0.0.1
tar --create --file hello-0.0.1.tar.gz hello-0.0.1
mv hello-0.0.1.tar.gz $HOME/rpmbuild/SOURCES
- 创建spec文件
The following command generates the templatespec
rpmdev-newspec hello
The current directory structure is shown below:
/root/rpmbuild/
├── BUILD
├── BUILDROOT
├── RPMS
├── SOURCES
│ └── hello-0.0.1.tar.gz
├── SPECS
│ └── hello.spec
└── SRPMS
- hello.spec
Name: hello
Version: 0.0.1
Release: 1%{
?dist}
Summary: A simple hello world script
BuildArch: noarch # noarchIt means that any chip architecture or distribution can be installed
License: GPL
Source0: %{
name}-%{
version}.tar.gz # 源码包名字,此处为hello-0.0.1.tar.gz
Requires: bash # The prerequisite for this software installation is requiredbash,多个的话用","分隔,比如gcc,gcc-c++
%description
A demo RPM build
%prep
%setup -q # This step is decompressionSOURCESDirectory of source packages
%install
rm -rf $RPM_BUILD_ROOT # RPM_BUILD_ROOTis the build current directory,宏常量
mkdir -p $RPM_BUILD_ROOT/%{
_bindir}
cp %{
name}.sh $RPM_BUILD_ROOT/%{
_bindir} # 拷贝到rpm包的%{_bindir}的目录下,%{_bindir}is a macro constant,通常为/usr/bin
%clean
rm -rf $RPM_BUILD_ROOT
%files
%{
_bindir}/%{
name}.sh # /usr/bin/hello.sh 相当于把rpm包里的hello.sh放到/usr/bin下
%changelog
* Sun Nov 18 2020 Valentin Bajrami <[email protected]> - 0.0.1
- First version being packaged
How to view macro constants
$ rpm --eval '%{_bindir}'
/usr/bin
Other useful macros:
Other commonly used macro constants:
- %{name} name of the package (as defined in the Name: field)
- %{version} version of the package (as defined in the Version: field)
- %{_datadir} shared data (/usr/sbin by default)
- %{_sysconfdir} configuration directory (/etc by default)
- 检测spec文件有效性
$ rpmlint ~/rpmbuild/SPECS/hello.spec
SPECS/hello.spec: W: no-%build-section
SPECS/hello.spec: W: invalid-url Source0: hello-0.0.1.tar.gz
0 packages and 1 specfiles checked; 0 errors, 2 warnings.
- 构建rpm包
rpmbuild -ba hello.spec
-b
build-a
both source and binary packages
- 测试安装包
cd ~/rpmbuild/RPMS
rpm -ivh hello-0.0.1.rpm
检测rpm是否成功:
rpm -qi hello
Troubleshoting
- 缺少so文件
在一些场景下,.so
文件包含于rpm包中,但是运行rpm -ivh
时出现,如下报错:
$ rpm -ivh hello.rpm
error: Failed dependencies:
lib3ds-2.so()(64bit) is needed by cips-22.05.06-1.el7.x86_64
libAltova.so()(64bit) is needed by cips-22.05.06-1.el7.x86_64
libAltovaXML.so()(64bit) is needed by cips-22.05.06-1.el7.x86_64
libGLEW.so.2.1()(64bit) is needed by cips-22.05.06-1.el7.x86_64
这是因为rpmbuildThe process will automatically detect the software required.so
依赖,But only the test passedrpm方式安装的.假如.so
文件在rpm里,安装可以使用--nodeps
option to skip detection, This does not affect the normal operation of the software.
rpm -ivh --nodeps *.rpm
Reference List
- https://www.cnblogs.com/dissipate/p/13050646.html
- https://www.thegeekstuff.com/2015/02/rpm-build-package-example/#:~:text=To%20build%20an%20rpm%20file%20based%20on%20the,rpm-build%20package.%20Install%20it%20as%20shown%20show%20below.
边栏推荐
猜你喜欢
随机推荐
一文看懂推荐系统:召回06:双塔模型——模型结构、训练方法,召回模型是后期融合特征,排序模型是前期融合特征
跨域解决方案
Theory of Software Fundamentals
Object.defineProperty实时监听数据变化并更新页面
1349. 参加考试的最大学生数 状态压缩
Lattice PCIe 学习 1
C# const readonly static 关键字区别
MySQL3
第09章 性能分析工具的使用【2.索引及调优篇】【MySQL高级】
JWT简单介绍
GCC: Shield dependencies between dynamic libraries
活动推荐 | 快手StreamLake品牌发布会,8月10日一起见证!
If capturable=False, state_steps should not be CUDA tensors
为什么他们选择和AI恋爱?
[Machine Learning] 21-day Challenge Study Notes (2)
硬实力和软实力,哪个对测试人来说更重要?
FSAWS 的全球基础设施和网络
刷爆朋友圈,Alibaba出品亿级并发设计速成笔记太香了
ExcelPatternTool: Excel table-database mutual import tool
AI+PROTAC|dx/tx完成500万美元种子轮融资