当前位置:网站首页>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
-bbuild-aboth 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里,安装可以使用--nodepsoption 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.
边栏推荐
- Introduction to JVM class loading
- ORA-00257
- 面试汇总:为何大厂面试官总问 Framework 的底层原理?
- 多线程涉及的其它知识(死锁(等待唤醒机制),内存可见性问题以及定时器)
- If capturable=False, state_steps should not be CUDA tensors
- C语言基础知识 -- 指针
- 刷爆朋友圈,Alibaba出品亿级并发设计速成笔记太香了
- Residential water problems
- If capturable=False, state_steps should not be CUDA tensors
- Creative code confession
猜你喜欢
](/img/4d/2d81dc75433c23c5ba6b31453396f0.png)
二叉树[全解](C语言)

第十一章 开关级建模

Exploding the circle of friends, Alibaba produced billion-level concurrent design quick notes are too fragrant

多线程涉及的其它知识(死锁(等待唤醒机制),内存可见性问题以及定时器)

行业现状?互联网公司为什么宁愿花20k招人,也不愿涨薪留住老员工~

测试工作这么难找吗?今年32,失业2个月,大龄测试工程师接下来该拿什么养家?

软件测试技术之最有效的七大性能测试技术

Getting Started with Kubernetes Networking

B站7月榜单丨飞瓜数据B站UP主排行榜发布!

4. PCIe 接口时序
随机推荐
ORA-00257
Opencv - video frame skipping processing
[How to smash wool according to the music the couple listens to during the Qixi Festival] Does the background music affect the couple's choice of wine?
张驰咨询:揭晓六西格玛管理(6 Sigma)长盛不衰的秘密
手把手基于YOLOv5定制实现FacePose之《YOLO结构解读、YOLO数据格式转换、YOLO过程修改》
深度学习原理学习小结 - Self-Attention/Transformer
原生js实现多选框全部选中和取消效果
10年测试经验,在35岁的生理年龄面前,一文不值
IJCAI2022 | DictBert:采用对比学习的字典描述知识增强的预训练语言模型
Log an error encountered when compiling google gn "I could not find a ".gn" file ..."
为什么他们选择和AI恋爱?
【PyQT5 绑定函数的传参】
汇编语言之源程序
配置类总结
AI+小核酸药物|Eleven完成2200万美元种子轮融资
Three handshake and four wave in tcp
JVM类加载简介
工具类总结
If capturable=False, state_steps should not be CUDA tensors
Object.defineProperty实时监听数据变化并更新页面