需求:最近要制作一个rpm包,通过源码(python)
方案:利用rpmbuild实现,编写 相应spec脚本
首先下载源码文件python
然后打成tar包,放到新建的用户目录下 /user/lib
我们这里需要利用rpmbuild来建立,在此之前需要安装sudo yum install rpm-build
用下面的命令创建必要的文件夹,其中BUILD是用来保存打包过程中生成的临时文件用的;RPMS用来保存生成的二进制RPM包;SOURCES用来保存打包用的源文件(包括压缩文件);SPECS用来保存.spec脚本;SRPMS用来保存生成的源代码rpm包。
mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
将打好的tar包放到SOURCES目录下
开始编写spec脚本
1、创建一个相关包的python.spec脚本,会生成相关的模板配置
2、具体脚本内容如下:
Name: AB Version: 1.0.0 Release: 1%{?dist} Summary: Design firstly Group: Applications/Internet License: GPL URL: www.first.com Source0: AB.tar BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root BuildRequires: gcc,gcc-c++,openssl-devel %define python_path /tmp/python/ %define etc_path /tmp/etc/ %define config_file c.cont %description Design firstly #在执行rpm时完成相关文件资源的预处理 %prep tar -cvf ../SOURCES/%{Source0} ../SOURCES/*.txt if [ ! -d "%{path_path}"]; then mkdir "%{path_path}" fi if [ ! -d "%{etc_path}"]; then mkdir "%{etc_path}" fi tar -xvf ../SOURCES/%{Source0} -C %{python_path} %build cp ../SOURCES/%{config_file} %{etc_path} chmod 755 /tmp/etc/%{config_file}
./configure
make %install make install
%clean rm -rf %{buildroot} %files %doc #在执行rpm -e AB时卸载文件 %postun if [ "$1" = "0" ]; then echo 'uninstall start...' rm -rf %{python_path} %{etc_path} echo 'uninstall done!' fi %changelog