用fpm制作RPM包

生成自己的RPM包太麻烦了,使用FPM可以很轻松地生成RPM包,在此记录一下centos7的安装过程。

安装

1
2
3
4
5
6
7
8
9
10
11
12
13
#yum install gcc gcc-c++ make autoconf libevent libevent-devel
[root@k8s-master etcd]# yum -y install ruby rubygems ruby-devel gcc rpm-build
[root@k8s-master etcd]# gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/

[root@k8s-master etcd]# gem sources -l
*** CURRENT SOURCES ***

https://gems.ruby-china.org/

[root@k8s-master etcd]# gem install fpm

[root@k8s-master rpmfiles]# fpm -v
1.7.0

基于已存在rpm包制作

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
[root@k8s-master rpmfiles]# mkdir rpmfiles
[root@k8s-master rpmfiles]# cp etcd-3.0.15-1.x86_64.rpm ./rpmfiles/
[root@k8s-master rpmfiles]# cd rpmfiles/

#查看script:
[root@k8s-master rpmfiles]# rpm -qp --scripts etcd-3.0.15-1.x86_64.rpm
warning: etcd-3.0.15-1.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID c33abc74: NOKEY
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
chown -R etcd.etcd /var/lib/etcd
preuninstall scriptlet (using /bin/sh):
if [ $1 -eq 0 ] ; then
# Package removal, not upgrade
systemctl --no-reload disable etcd.service || :
systemctl stop etcd.service || :
fi
postuninstall scriptlet (using /bin/sh):
systemctl daemon-reload >/dev/null 2>&1 || :

#将以上内容生成为以下文件:
postinstall.sh
postuninstall.sh
preinstall.sh
preuninstall.sh

#解压文件:
[root@k8s-master rpmfiles]# rpm2cpio etcd-3.0.15-1.x86_64.rpm | cpio -idmv

#制作:
fpm -s dir -t rpm -n "etcd" -v 3.x-1.x86_64 --pre-install preinstall.sh --post-install postinstall.sh --pre-uninstall preuninstall.sh --post-uninstall postuninstall.sh etc usr var

参考

https://mritd.me/2016/08/02/yum-%E7%AC%94%E8%AE%B0/
https://mritd.me/2016/09/13/%E5%9F%BA%E4%BA%8E%E5%AE%98%E6%96%B9-rpm-%E5%BF%AB%E9%80%9F%E5%88%9B%E5%BB%BA%E8%87%AA%E5%AE%9A%E4%B9%89-rpm/