@cryptotaxi247 / netdata-1 / commits / cf51cef88

spec: reduce conditionals in body

Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com>

Alon Bar-Lev committed Feb 19, 2017 at 14:34 UTC cf51cef889d0af8eee3700c154e9395a3d24dee9
1 file changed +51 -63
netdata.spec.in
+51 -63
@@ -1,15 +1,4 @@
1 %global contentdir %{_datadir}/netdata
2 -%if 0%{?suse_version}
3 -%global distro_post %service_add_post netdata.service
4 -%global distro_preun %service_del_preun netdata.service
5 -%global distro_postun %service_del_postun netdata.service
6 -%global distro_buildrequires BuildRequires:\ systemd-rpm-macros
7 -%else
8 -%global distro_post %systemd_post netdata.service
9 -%global distro_preun %systemd_preun netdata.service
10 -%global distro_postun %systemd_postun_with_restart netdata.service
11 -%global distro_buildrequires %{nil}
12 -%endif
2
3 # This is temporary and should eventually be resolved. This bypasses
4 # the default rhel __os_install_post which throws a python compile
@@ -26,7 +15,50 @@
15 %undefine with_systemd
16 %endif
17
29 -%if 0%{?fedora}
18 +%if %{with systemd}
19 +%if 0%{?suse_version}
20 +%global netdata_initd_buildrequires \
21 +BuildRequires: systemd-rpm-macros \
22 +%{nil}
23 +%global netdata_initd_requires \
24 +%{?systemd_requires} \
25 +%{nil}
26 +%global netdata_init_post %service_add_post netdata.service
27 +%global netdata_init_preun %service_del_preun netdata.service
28 +%global netdata_init_postun %service_del_postun netdata.service
29 +%else
30 +%global netdata_initd_buildrequires %{nil}
31 +%global netdata_initd_requires \
32 +Requires(preun): systemd-units \
33 +Requires(postun): systemd-units \
34 +Requires(post): systemd-units \
35 +%{nil}
36 +%global netdata_init_post %systemd_post netdata.service
37 +%global netdata_init_preun %systemd_preun netdata.service
38 +%global netdata_init_postun %systemd_postun_with_restart netdata.service
39 +%endif
40 +%else
41 +%global netdata_initd_buildrequires %{nil}
42 +%global netdata_initd_requires \
43 +Requires(post): chkconfig \
44 +%{nil}
45 +%global netdata_init_post \
46 +/sbin/chkconfig --add netdata \
47 +%{nil}
48 +%global netdata_init_preun %{nil} \
49 +if [ $1 = 0 ]; then \
50 + /sbin/service netdata stop > /dev/null 2>&1 \
51 + /sbin/chkconfig --del netdata \
52 +fi \
53 +%{nil}
54 +%global netdata_init_postun %{nil} \
55 +if [ $1 != 0 ]; then \
56 + /sbin/service netdata condrestart 2>&1 > /dev/null \
57 +fi \
58 +%{nil}
59 +%endif
60 +
61 +%if 0%{?_fedora}
62 %global netdata_recommends \
63 Recommends: curl \
64 Recommends: iproute-tc \
@@ -50,7 +82,6 @@ License: GPL v3+
82 Group: Applications/System
83 Source0: http://firehol.org/download/netdata/releases/v@PACKAGE_VERSION@/%{name}-@PACKAGE_VERSION@.tar.xz
84 URL: http://my-netdata.io/
53 -%distro_buildrequires
85 BuildRequires: pkgconfig
86 BuildRequires: xz
87 BuildRequires: zlib-devel
@@ -58,7 +89,6 @@ BuildRequires: libuuid-devel
89 Requires: zlib
90 Requires: libuuid
91 Requires(post): libcap
61 -%{netdata_recommends}
92
93 # Packages can be found in the EPEL repo
94 %if %{with nfacct}
@@ -70,18 +100,11 @@ Requires: libnetfilter_acct
100
101 Requires(pre): /usr/sbin/groupadd
102 Requires(pre): /usr/sbin/useradd
103 +Requires(post): libcap
104
74 -%if %{with systemd}
75 -%if 0%{?suse_version}
76 -%{?systemd_requires}
77 -%else
78 -Requires(preun): systemd-units
79 -Requires(postun): systemd-units
80 -Requires(post): systemd-units
81 -%endif
82 -%else
83 -Requires(post): chkconfig
84 -%endif
105 +%{netdata_initd_buildrequires}
106 +%{netdata_recommends}
107 +%{netdata_initd_requires}
108
109 %description
110 netdata is the fastest way to visualize metrics. It is a resource
@@ -124,56 +147,21 @@ install -m 755 system/netdata-init-d \
147 "${RPM_BUILD_ROOT}/etc/rc.d/init.d/netdata"
148 %endif
149
127 -%if %{with systemd}
128 -%pre
129 -# Add the "netdata" user
130 -/usr/sbin/groupadd -r netdata 2> /dev/null || :
131 -/usr/sbin/useradd -c "netdata" -g netdata \
132 - -s /sbin/nologin -r -d %{contentdir} netdata 2> /dev/null || :
133 -
134 -%post
135 -%distro_post
136 -
137 -%preun
138 -%distro_preun
139 -
140 -%postun
141 -%distro_postun
142 -%else
150 %pre
144 -# Add the "netdata" user
151 getent group netdata >/dev/null || groupadd -r netdata
152 getent group docker >/dev/null || groupadd -r docker
153 getent passwd netdata >/dev/null || \
154 useradd -r -g netdata -G docker -s /sbin/nologin \
155 -d %{contentdir} -c "netdata" netdata
150 -exit 0
156
157 %post
153 -# Register the netdata service
154 -/sbin/chkconfig --add netdata
155 -# Only gets run on initial install (not upgrades or uninstalls)
156 -if [ $1 = 1 ]; then
157 - # Start the netdata service
158 - /sbin/service netdata start
159 -fi
160 -exit 0
158 +%{netdata_init_post}
159
160 %preun
163 -# Only gets run on uninstall (not upgrades)
164 -if [ $1 = 0 ]; then
165 - /sbin/service netdata stop > /dev/null 2>&1
166 - /sbin/chkconfig --del netdata
167 -fi
168 -exit 0
161 +%{netdata_init_preun}
162
163 %postun
171 -# Only gets run on upgrade (not uninstalls)
172 -if [ $1 != 0 ]; then
173 - /sbin/service netdata condrestart 2>&1 > /dev/null
174 -fi
175 -exit 0
176 -%endif
164 +%{netdata_init_postun}
165
166 %clean
167 rm -rf "${RPM_BUILD_ROOT}"