rpm 安装包制作

rpm 安装包制作

思路 参照系统自带 etcd 解压-》替换掉执行文件-》打包

1 预备安装工具

下载工具 yumloader
#yum install -y yum-utils

解压工具 rmp
打包工具 fpm
yum -y install ruby rubygems ruby-devel
安装fpm
gem install fpm

2 下载

yumdownloader etcd
etcd-2.3.7-4.el7.x86_64.rpm

3 解压

3.1 抽取脚本
rpm -qp --scripts etcd-2.3.7-4.el7.x86_64.rpm

preinstall scriptlet (using /bin/sh):
getent group etcd >/dev/null || groupadd -r etcd
getent passwd etcd >/dev/null || useradd -r -g etcd -d /var/lib/etcd 
-s /sbin/nologin -c "etcd user" etcd
postinstall scriptlet (using /bin/sh):

if [ $1 -eq 1 ] ; then 
# Initial installation 
systemctl preset etcd.service >/dev/null 2>&1 || : 
fi
preuninstall scriptlet (using /bin/sh):

if [ $1 -eq 0 ] ; then 
# Package removal, not upgrade 
systemctl --no-reload disable etcd.service > /dev/null 2>&1 || : 
systemctl stop etcd.service > /dev/null 2>&1 || : 
fi
postuninstall scriptlet (using /bin/sh):

systemctl daemon-reload >/dev/null 2>&1 || :


#define license tag if not already defined

分别对应生成4个shell文件

postinstall.sh postuninstall.sh preinstall.sh preuninstall.sh

3.2 解压 rpm

mkdir rpmfiles
cp etcd-2.3.7-4.el7.x86_64.rpm rpmfiles
cd rpmfiles
rpm2cpio etcd-2.3.7-4.el7.x86_64.rpm | cpio -idmv

4 替换可执行文件

5 打包

fpm -s dir -t rpm -n "etcd" -v $version --pre-install preinstall.sh --post-install postinstall.sh --pre-uninstall preuninstall.sh --post-uninstall postuninstall.sh etc usr var

原文地址:https://www.cnblogs.com/zhangeamon/p/6144935.html