1、安装RPM制作软件
sudo yum install rpmdevtools
2、初始化
rpmdev-setuptree
执行成功后,在当前用户目录下创建了rpmbuild
目录
3、把要打包的文件复制到BUILD目录下
4、编写构建指令文件
在SPECS
下创建名为oss.specs
文本文件
touch ~/rpmbuild/SPECS/oss.specs
编辑此文件内容:
Name: oss
Version: 1.0
Release: 1%{?dist}
Summary: oss rpm build
License: free
AutoReqProv: no
%description
oss rpm package
%install
mkdir -p ${RPM_BUILD_ROOT}/usr/local/oss/
mkdir -p ${RPM_BUILD_ROOT}/usr/lib/systemd/system/
cp -rf oss/* ${RPM_BUILD_ROOT}/usr/local/oss/
cp -f odmain.service ${RPM_BUILD_ROOT}/usr/lib/systemd/system/
cp -f udprcv.service ${RPM_BUILD_ROOT}/usr/lib/systemd/system/
%post
systemctl daemon-reload
systemctl enable odmain
systemctl enable udprcv
%postun
systemctl disable odmain
systemctl disable udprcv
rm -rf /usr/local/oss
rm -rf /usr/lib/systemd/system/odmain.service
rm -rf /usr/lib/systemd/system/udprcv.service
systemctl daemon-reload
%files
/usr/local/oss
/usr/lib/systemd/system/odmain.service
/usr/lib/systemd/system/udprcv.service
5、打包
rpmbuild -bb ~/rpmbuild/SPECS/oss.specs
6、安装
sudo rpm -ivh ~/rpmbuild/RPMS/x86_64/oss-1.0-1.el7.x86_64.rpm
7、卸载
sudo rpm -e oss-1.0-1.el7.x86_64