]> arthur.barton.de Git - netdata.git/commitdiff
spec: reduce conditionals in body
authorAlon Bar-Lev <alon.barlev@gmail.com>
Sun, 19 Feb 2017 19:34:10 +0000 (14:34 -0500)
committerAlon Bar-Lev <alon.barlev@gmail.com>
Sun, 26 Feb 2017 19:38:21 +0000 (21:38 +0200)
Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com>
netdata.spec.in

index 85e05ba7eff3d0b13dc3f2b19e7257842049b91a..00c35aefec090d707bc11c51d2fe78a39de9986a 100644 (file)
@@ -1,15 +1,4 @@
 %global contentdir %{_datadir}/netdata
-%if 0%{?suse_version}
-%global distro_post %service_add_post netdata.service
-%global distro_preun %service_del_preun netdata.service
-%global distro_postun %service_del_postun netdata.service
-%global distro_buildrequires BuildRequires:\ systemd-rpm-macros
-%else
-%global distro_post %systemd_post netdata.service
-%global distro_preun %systemd_preun netdata.service
-%global distro_postun %systemd_postun_with_restart netdata.service
-%global distro_buildrequires %{nil}
-%endif
 
 # This is temporary and should eventually be resolved. This bypasses
 # the default rhel __os_install_post which throws a python compile
 %undefine      with_systemd
 %endif
 
-%if 0%{?fedora}
+%if %{with systemd}
+%if 0%{?suse_version}
+%global netdata_initd_buildrequires \
+BuildRequires: systemd-rpm-macros \
+%{nil}
+%global netdata_initd_requires \
+%{?systemd_requires} \
+%{nil}
+%global netdata_init_post %service_add_post netdata.service
+%global netdata_init_preun %service_del_preun netdata.service
+%global netdata_init_postun %service_del_postun netdata.service
+%else
+%global netdata_initd_buildrequires %{nil}
+%global netdata_initd_requires \
+Requires(preun):  systemd-units \
+Requires(postun): systemd-units \
+Requires(post):   systemd-units \
+%{nil}
+%global netdata_init_post %systemd_post netdata.service
+%global netdata_init_preun %systemd_preun netdata.service
+%global netdata_init_postun %systemd_postun_with_restart netdata.service
+%endif
+%else
+%global netdata_initd_buildrequires %{nil}
+%global netdata_initd_requires \
+Requires(post):   chkconfig \
+%{nil}
+%global netdata_init_post \
+/sbin/chkconfig --add netdata \
+%{nil}
+%global netdata_init_preun %{nil} \
+if [ $1 = 0 ]; then \
+        /sbin/service netdata stop > /dev/null 2>&1 \
+        /sbin/chkconfig --del netdata \
+fi \
+%{nil}
+%global netdata_init_postun %{nil} \
+if [ $1 != 0 ]; then \
+        /sbin/service netdata condrestart 2>&1 > /dev/null \
+fi \
+%{nil}
+%endif
+
+%if 0%{?_fedora}
 %global netdata_recommends \
 Recommends:    curl \
 Recommends:    iproute-tc \
@@ -50,7 +82,6 @@ License:      GPL v3+
 Group:         Applications/System
 Source0:       http://firehol.org/download/netdata/releases/v@PACKAGE_VERSION@/%{name}-@PACKAGE_VERSION@.tar.xz
 URL:           http://my-netdata.io/
-%distro_buildrequires
 BuildRequires: pkgconfig
 BuildRequires: xz
 BuildRequires: zlib-devel
@@ -58,7 +89,6 @@ BuildRequires:        libuuid-devel
 Requires:      zlib
 Requires:      libuuid
 Requires(post): libcap
-%{netdata_recommends}
 
 # Packages can be found in the EPEL repo
 %if %{with nfacct}
@@ -70,18 +100,11 @@ Requires: libnetfilter_acct
 
 Requires(pre): /usr/sbin/groupadd
 Requires(pre): /usr/sbin/useradd
+Requires(post): libcap
 
-%if %{with systemd}
-%if 0%{?suse_version}
-%{?systemd_requires}
-%else
-Requires(preun):  systemd-units
-Requires(postun): systemd-units
-Requires(post):   systemd-units
-%endif
-%else
-Requires(post):   chkconfig
-%endif
+%{netdata_initd_buildrequires}
+%{netdata_recommends}
+%{netdata_initd_requires}
 
 %description
 netdata is the fastest way to visualize metrics. It is a resource
@@ -124,56 +147,21 @@ install -m 755 system/netdata-init-d \
         "${RPM_BUILD_ROOT}/etc/rc.d/init.d/netdata"
 %endif
 
-%if %{with systemd}
-%pre
-# Add the "netdata" user
-/usr/sbin/groupadd -r netdata 2> /dev/null || :
-/usr/sbin/useradd -c "netdata" -g netdata \
-        -s /sbin/nologin -r -d %{contentdir} netdata 2> /dev/null || :
-
-%post
-%distro_post
-
-%preun
-%distro_preun
-
-%postun
-%distro_postun
-%else
 %pre
-# Add the "netdata" user
 getent group netdata >/dev/null || groupadd -r netdata
 getent group docker >/dev/null || groupadd -r docker
 getent passwd netdata >/dev/null || \
   useradd -r -g netdata -G docker -s /sbin/nologin \
     -d %{contentdir} -c "netdata" netdata
-exit 0
 
 %post
-# Register the netdata service
-/sbin/chkconfig --add netdata
-# Only gets run on initial install (not upgrades or uninstalls)
-if [ $1 = 1 ]; then
-        # Start the netdata service
-        /sbin/service netdata start
-fi
-exit 0
+%{netdata_init_post}
 
 %preun
-# Only gets run on uninstall (not upgrades)
-if [ $1 = 0 ]; then
-        /sbin/service netdata stop > /dev/null 2>&1
-        /sbin/chkconfig --del netdata
-fi
-exit 0
+%{netdata_init_preun}
 
 %postun
-# Only gets run on upgrade (not uninstalls)
-if [ $1 != 0 ]; then
-        /sbin/service netdata condrestart 2>&1 > /dev/null
-fi
-exit 0
-%endif
+%{netdata_init_postun}
 
 %clean
 rm -rf "${RPM_BUILD_ROOT}"