源码制作RPM包步骤

1. 搭建编译环境

yum install -y rpm-build
yum install rpmdevtools  

2. 生成目录结构

rpmdev-setuptree   
生成目录如下:
$ tree rpmbuild
rpmbuild
├── BUILD
├── RPMS
├── SOURCES
├── SPECS
└── SRPMS

3. 打包过程

  1. 上传源码至SOURCES目录下
$ cd ~/rpmbuild/SOURCES
$ 上传tar.gz文件
  1. 创建.spec文件
$ cd ~/rpmbuild/SPECS
$ rpmdev-newspec filename
$ vi filename.spec

spec文件示例

%global _python_bytecompile_errors_terminate_build 0
Name:           coco
Version:        1.0
Release:        1%{?dist}
Summary:        The coco is a sub app of Jumpserver.

License:        GPL v2.0
URL:            http://gitlab.tyun.cn/tyun/coco.git
Source0:        %{name}.tar.gz      #SOURCES中源码包名


Requires:       libffi-devel     #所依赖的包
Requires:       sshpass

%description
It's implement a ssh server and a web terminal server, user can connect them except jumpserver openssh server and connect.py pre version.

%define    userpath /opt/%{name}   #定义安装路径

%prep
%setup -q -n coco

%install
rm -rf $RPM_BUILD_ROOT%{userpath}
mkdir -p $RPM_BUILD_ROOT%{userpath}
cp -r * $RPM_BUILD_ROOT%{userpath}
chmod a+x $RPM_BUILD_ROOT%{userpath}

%clean
rm -rf $RPM_BUILD_ROOT%{userpath}

%files                    #定义软件包所包含的文件
%defattr(-,root,root,-)  #指定包装文件的属性,分别是(mode,owner,group)
%{userpath}              #相对于$RPM_BUILD_ROOT的虚拟相对路径


%changelog

  1. 打包
$ rpmbuild -ba xxxx.spec
  1. 检验安装
$ cd ~/rpmbuild/RPMS/x86_64
$ rpm -ivh xxx.rpm

4. 问题与解决方案

  1. 执行rpmbuild -ba xxxx.spec install过程报错
$ SyntaxError: invalid syntax

$ error: Bad exit status from /var/tmp/rpm-tmp.MqlNF5 (%install)

sol:spec文件开头加 %global _python_bytecompile_errors_terminate_build 0
  1. 打包过程或安装过程中出现
$  error: Failed dependencies:...

sol: 安装所提示缺少的依赖包
  1. 打包过程报错
$ File not found by glob: /root/rpmbuild/BUILDROOT/jumpserver-1.4.0-1.el7.x86_64/usr/lib/*

原因为 %file 下指定路径错误,此处路径为相对$RPM_BUILD_ROOT的路径

你可能感兴趣的:(环境搭建)