RPM Packager Skill
Transform source code into installable RPM packages for CentOS/RHEL systems.
Quick Start
CODEBLOCK0
Workflow
1. Prepare Source Code
Ensure source code is ready:
- - Has a build system (Makefile, CMakeLists.txt, setup.py, etc.)
- Clean directory structure
- No build artifacts
2. Check Prerequisites
Required tools on CentOS/RHEL (requires sudo privileges):
CODEBLOCK1
Note: Installing system packages requires sudo privileges. The build process itself runs as your user account.
3. Run Build Script
CODEBLOCK2
4. Verify Output
Build produces:
- - Binary RPM: INLINECODE1
- Source RPM: INLINECODE2
5. Install & Test
CODEBLOCK3
SPEC File Customization
For complex packages, customize the SPEC file:
- 1. Review template: See references/spec-template.md
- Edit generated SPEC: Modify INLINECODE3
- Rebuild: INLINECODE4
Common Customizations
Add dependencies:
CODEBLOCK4
Custom install paths:
CODEBLOCK5
Include documentation:
CODEBLOCK6
Build for Different CentOS Versions
Use mock for clean builds targeting specific versions:
CODEBLOCK7
Environment Variables
| Variable | Default | Description |
|---|
| INLINECODE5 | INLINECODE6 | Builder name in changelog |
| INLINECODE7 |
~/rpmbuild | Custom build directory |
Troubleshooting
Build fails with "No such file or directory"
- - Check
BuildRequires for missing tools - Verify source tarball extracts correctly
RPM installs but command not found
- - Ensure
%files section includes correct paths - Check executable permissions in INLINECODE11
Dependency errors during install
- - Add missing
Requires entries to SPEC file - Use
yum localinstall instead of rpm -i for auto-dependency resolution
Output Locations
After successful build:
- - Binary RPMs: INLINECODE15
- Source RPM: INLINECODE16
- Build logs: INLINECODE17
- SPEC files: INLINECODE18
Security Notes
- - Build directory defaults to
~/rpmbuild to avoid conflicts with system-wide builds - Builder identity is anonymized by default (uses
OpenClaw Builder) - No personal information is embedded in generated RPMs unless explicitly configured
RPM打包技能
将源代码转换为适用于CentOS/RHEL系统的可安装RPM包。
快速开始
bash
基本用法
./scripts/build-rpm.sh <源代码目录> <包名称> <版本号> <发布号>
示例
./scripts/build-rpm.sh ./myapp myapp 1.0.0 1
工作流程
1. 准备源代码
确保源代码已就绪:
- - 包含构建系统(Makefile、CMakeLists.txt、setup.py等)
- 目录结构清晰
- 无构建产物
2. 检查前置条件
CentOS/RHEL系统上所需的工具(需要sudo权限):
bash
sudo yum install rpm-build mock gcc make
注意: 安装系统包需要sudo权限。构建过程本身将以您的用户账户运行。
3. 运行构建脚本
bash
cd ~/.openclaw/workspace/skills/rpm-packager
chmod +x scripts/build-rpm.sh
./scripts/build-rpm.sh /path/to/source package-name 1.0.0 1
4. 验证输出
构建生成:
- - 二进制RPM:~/rpmbuild/RPMS/x8664/package-name-1.0.0-1.el8.x8664.rpm
- 源码RPM:~/rpmbuild/SRPMS/package-name-1.0.0-1.el8.src.rpm
5. 安装与测试
bash
安装RPM
sudo rpm -ivh ~/rpmbuild/RPMS/x86
64/package-name-1.0.0-1.el8.x8664.rpm
或使用yum/dnf进行依赖解析
sudo yum localinstall ~/rpmbuild/RPMS/x86
64/package-name-1.0.0-1.el8.x8664.rpm
验证安装
rpm -q package-name
SPEC文件定制
对于复杂包,可自定义SPEC文件:
- 1. 审查模板:参见references/spec-template.md
- 编辑生成的SPEC:修改~/rpmbuild/SPECS/package-name.spec
- 重新构建:rpmbuild -ba ~/rpmbuild/SPECS/package-name.spec
常见定制
添加依赖:
spec
BuildRequires: python3-devel openssl-devel
Requires: python3 openssl-libs
自定义安装路径:
spec
%install
mkdir -p %{buildroot}%{_bindir}
mkdir -p %{buildroot}%{_sysconfdir}/package-name
install -m 755 myapp %{buildroot}%{_bindir}/
install -m 644 config.conf %{buildroot}%{_sysconfdir}/package-name/
包含文档:
spec
%files
%doc README.md LICENSE CHANGELOG.md
%{_bindir}/myapp
为不同CentOS版本构建
使用mock进行针对特定版本的干净构建:
bash
CentOS 7
mock -r centos-7-x86_64 package-name.spec
CentOS 8
mock -r centos-8-x86_64 package-name.spec
CentOS 9
mock -r centos-9-x86_64 package-name.spec
环境变量
| 变量 | 默认值 | 描述 |
|---|
| RPMBUILDERNAME | OpenClaw Builder | 变更日志中的构建者名称 |
| RPMBUILDDIR |
~/rpmbuild | 自定义构建目录 |
故障排除
构建失败,提示没有那个文件或目录
- - 检查BuildRequires中是否缺少工具
- 验证源代码压缩包是否正确解压
RPM安装成功但命令找不到
- - 确保%files部分包含正确的路径
- 检查%install中的可执行权限
安装时出现依赖错误
- - 在SPEC文件中添加缺失的Requires条目
- 使用yum localinstall代替rpm -i以自动解析依赖
输出位置
成功构建后:
- - 二进制RPM:~/rpmbuild/RPMS/<架构>/
- 源码RPM:~/rpmbuild/SRPMS/
- 构建日志:~/rpmbuild/BUILDLOGS/
- SPEC文件:~/rpmbuild/SPECS/
安全说明
- - 构建目录默认为~/rpmbuild,以避免与系统级构建冲突
- 构建者身份默认匿名化(使用OpenClaw Builder)
- 除非显式配置,否则生成的RPM中不会嵌入个人信息