centos6 centos7 linux 制作rpm包教程(研发成果一键部署)

centos7制作wavepoint rpm包方法

更换国内镜像

# 更新国内镜像源
# 备份yum原文件
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

# 下载yum文件
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

# 清除缓存
yum clean all

# 加载缓存
yum makecache

软件准备

# 下载编译需要的包
yum install rpm-build make rsync

spec文件准备

Name:aaa
Version:1.0
Release:5%{?dist}
Summary:recursive analysis for yamu

AutoReqProv:no
#BuildArch:  noarch
Group:application program/Base		
License:CPL
URL:www.yamu.com		
Source:%{name}-%{version}.tar.gz	
BuildRoot:%{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)

Requires: aaa-depend >= %{version}

%description
yamu aaa

%{!?python_sitelib: %define python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")}
%{!?python_sitearch: %define python_sitearch %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib(1)
")}


%package depend
Summary:  aaa need depend package (rpms and whls)
Group:    Applications/Base
#BuildArch:      noarch

%description depend
aaa need depend package (rpms and whls)

%prep
rm -rf ${RPM_BUILD_ROOT}
#%setup -c
%setup -q

%build
make

%install
rm -rf %{buildroot}
install -p -d -m 0755 %{buildroot}/usr/local/aaa
install -p -d -m 0755 %{buildroot}/etc/aaa
install -p -d -m 0755 %{buildroot}/etc/init.d
install -p -d -m 0755 %{buildroot}/etc/logrotate.d
install -p -d -m 0755 %{buildroot}/var/log/aaa

cp -a  bin                                          %{buildroot}/usr/local/aaa
cp -a  depend                                       %{buildroot}/usr/local/aaa
cp -a  README                                       %{buildroot}/usr/local/aaa
cp -a  config/aaa.ini                        %{buildroot}/etc/aaa
cp -a  config/aaad                    		%{buildroot}/etc/init.d
cp -a  config/aaa.logrotate                  %{buildroot}/etc/logrotate.d

cp -a  depend                                       %{buildroot}/usr/local/aaa
    

#make DESTDIR=$RPM_BUILD_ROOT install

%post
if test $1 = 1 ; then
    ln -snf /usr/local/aaa/bin/aaa.py  /usr/bin/aaa.py
    chkconfig aaad on
fi

%post depend
rm -rf /var/lib/rpm/.rpm.lock

%if 0%{?fedora} >= 15 || 0%{?rhel} >= 7
    echo '..........Install rh-pyhton36 for centos7...........'
    rpm -Uvh /usr/local/aaa/depend/rpm/centos7/python36/*.rpm  --force
%else
    echo '..........Install rh-pyhton36 for centos6...........'
    rpm -Uvh /usr/local/aaa/depend/rpm/centos6/python36/*.rpm  --force
%endif

echo 'Install aaa python depends...........'
/opt/rh/rh-python36/root/usr/bin/pip  install -r /usr/local/aaa/depend/requirements.txt -i -e /usr/local/aaa/depend/whl/*.whl

echo 'end...........'

%preun
if test $1 = 0 ; then
    /etc/init.d/aaad stop
    chkconfig  aaad off
    rm -rf  /usr/bin/aaa.py
fi

%clean

%files
%dir /usr/local/aaa
/usr/local/aaa/bin
/usr/local/aaa/README

%dir /etc/aaa
%config /etc/aaa/aaa.ini
/etc/init.d/aaad
/etc/logrotate.d/aaa.logrotate
%dir /var/log/aaa

%files depend
/usr/local/aaa/depend

Makefile文件准备

PROCESS=aaa

SRCDIR=./bin

RPM_TOP_DIR=$(shell rpm -E %{_topdir})

name_str=$(shell sed -ne '1p' spec/$(PROCESS).spec)
name=$(shell echo ${name_str} | awk -F ":" '{print $$2}')

version_str=$(shell sed -ne '2p' spec/$(PROCESS).spec)
version=$(shell echo ${version_str} | awk -F ":" '{print $$2}')

release_str=$(shell sed -ne '3p' spec/$(PROCESS).spec)
release_str1=$(shell echo ${release_str} | awk -F ":" '{print $$2}')
release=$(shell echo ${release_str1} | awk -F "%" '{print $$1}')

all:build

build:

install:

uninstall:

clean:
	rm -rf bin/__pycache__
	rm -rf 	*~ *.swp *.pyc 
	find . -name *~		|xargs rm -rf 
	find . -name *.swp	|xargs rm -rf 
	find . -name *.pyc	|xargs rm -rf 

rpm:
	echo VERSION=\'${version}.${release}\' > $(SRCDIR)/version.py
	rm -rf /tmp/${name}-${version}
	\cp -a  spec/$(PROCESS).spec ${RPM_TOP_DIR}/SPECS
	make clean
	rsync -av --exclude test --exclude .git --exclude .gitignore  ./   /tmp/${name}-${version}
	rm -rf ${RPM_TOP_DIR}/SOURCES/${name}-${version}.tar.gz
	cd /tmp ; tar cvzf ${RPM_TOP_DIR}/SOURCES/${name}-${version}.tar.gz  ${name}-${version}
	rpmbuild -ba ${RPM_TOP_DIR}/SPECS/$(PROCESS).spec


打rpm包

# 开始编译
cd /usr/local/share/codes
make rpm

包信息

打包完成后,包放在了~/rpmbuild下,目录内容如下:

BUILD 	    编译rpm包的临时目录 	
BUILDROOT   编译后生成的软件临时安装目录
RPMS 	    最终生成的可安装rpm包的所在目录
SOURCES     所有源代码和补丁文件的存放目录
SPECS 	    存放SPEC文件的目录(重要)
SRPMS 	    软件最终的rpm源码格式存放路径
已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 设计师:巨魔战将-深度大数据 返回首页
实付 39.90元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值