File atop.spec of Package atop

#
# spec file for package atop
#
# Copyright (c) 2017 SUSE LINUX GmbH, Nuernberg, Germany.
# Copyright (c) 2012 Pascal Bleser <pascal.bleser@opensuse.org>
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via http://bugs.opensuse.org/
#


%define pkg_version 2.2-3
Name:           atop
Version:        2.2
Release:        0
Summary:        Monitor for System Resources and Process Activity
License:        GPL-2.0
Group:          System/Monitoring
Url:            http://www.atoptool.nl/
Source:         http://www.atoptool.nl/download/%{name}-%{pkg_version}.tar.gz
Source1:        atop.desktop
Source2:        atop.init.suse
Source3:        atopacct.service
Source4:        atopacct.init.suse
Source99:       atop-rpmlintrc
# PATCH-FIX-SUSE -- fix Makefile
Patch1:         atop-makefile.patch
BuildRequires:  gcc
BuildRequires:  glibc-devel
BuildRequires:  make
BuildRequires:  ncurses-devel
BuildRequires:  update-desktop-files
BuildRequires:  zlib-devel
BuildRoot:      %{_tmppath}/%{name}-%{version}-build

%if 0%{?suse_version} >= 1210
# not really, just for directory ownership:
BuildRequires:  systemd
%else
# just for directory ownership:
BuildRequires:  pm-utils
Requires(pre):  %insserv_prereq
%endif

%description
Atop is an ASCII full-screen performance monitor, similar to the top
command. At regular intervals, it shows system-level activity related to
the CPU, memory, swap, disks and network layers, and it shows for every
active process the CPU utilization in system and user mode, the virtual
and resident memory growth, priority, username, state, and exit code. The
process level activity is also shown for processes which finished during
the last interval, to get a complete overview about the consumers of things
such as CPU time. Atop only shows the active system-resources and processes,
and only shows the deviations since the previous interval.

%package daemon
Summary:        System Resource and Process Monitoring History Daemon
Group:          System/Monitoring
Requires:       %{name} = %{version}-%{release}
Recommends:     cron
Recommends:     logrotate
Recommends:     pm-utils

%description daemon
Atop is an ASCII full-screen performance monitor, similar to the top
command. At regular intervals, it shows system-level activity related to
the CPU, memory, swap, disks and network layers, and it shows for every
active process the CPU utilization in system and user mode, the virtual
and resident memory growth, priority, username, state, and exit code. The
process level activity is also shown for processes which finished during
the last interval, to get a complete overview about the consumers of things
such as CPU time. Atop only shows the active system-resources and processes,
and only shows the deviations since the previous interval.

This subpackage contains the permanent monitoring daemon, to store history
information about processes and system resources.

%prep
%setup -q -n %{name}-%{pkg_version}
%patch1 -p1

%build
make %{?_smp_mflags} \
    OPTFLAGS="%{optflags} -fstack-protector" \
    CC="gcc"

%install
install -d "%{buildroot}%{_sbindir}"
%if 0%{?suse_version} >= 1210
make systemdinstall DESTDIR="%{buildroot}"
%else
install -d "%{buildroot}%{_usr}/lib/pm-utils/sleep.d"
make sysvinstall DESTDIR="%{buildroot}"
%endif

rm -f "%{buildroot}%{_localstatedir}/log/atop"/*

%if 0%{?suse_version} >= 1210
install -D -m0644 "atop.service" "%{buildroot}%{_usr}/lib/systemd/system/%{name}.service"
ln -s "%{_sbindir}/service" "%{buildroot}%{_sbindir}/rc%{name}"

install -D -m0644 "%{SOURCE3}" "%{buildroot}%{_usr}/lib/systemd/system/atopacct.service"
ln -s "%{_sbindir}/service" "%{buildroot}%{_sbindir}/rcatopacct"

install -D -m 0644 atop.cronsystemd "%{buildroot}%{_sysconfdir}/cron.d/%{name}"
%else
rm "%{buildroot}%{_initddir}/atop"
install -m 0755 "%{SOURCE2}" "%{buildroot}%{_initddir}/%{name}"
install -d "%{buildroot}%{_prefix}/sbin"
ln -s "../..%{_initddir}/%{name}" "%{buildroot}%{_sbindir}/rc%{name}"

rm "%{buildroot}%{_initddir}/atopacct"
install -m 0755 "%{SOURCE4}" "%{buildroot}%{_initddir}/atopacct"
ln -s "../..%{_initddir}/atopacct" "%{buildroot}%{_sbindir}/rcatopacct"

install -D -m 0644 atop.cronsysv "%{buildroot}%{_sysconfdir}/cron.d/%{name}"
%endif

install -D -m 0644 "%{SOURCE1}" "%{buildroot}%{_datadir}/applications/%{name}.desktop"
%if 0%{?suse_update_desktop_file:1}
%suse_update_desktop_file -r "%{name}" System Monitor
%endif

%if 0%{?suse_version} >= 1210
%pre daemon
%service_add_pre atop.service atopacct.service

%post daemon
%service_add_post atop.service atopacct.service
%endif

%postun daemon
%restart_on_update "%{name}"
%if 0%{?suse_version} >= 1210
%service_del_postun atop.service atopacct.service
%else
%insserv_cleanup
%endif

%preun daemon
%stop_on_removal "%{name}"
%if 0%{?suse_version} >= 1210
%service_del_preun atop.service atopacct.service
%endif

%files
%defattr(-,root,root)
%doc COPYING README
%attr(0755,root,root) %{_bindir}/atop
%{_bindir}/atopsar
%{_bindir}/atop-%{pkg_version}
%{_bindir}/atopsar-%{pkg_version}
%{_mandir}/man1/atop.1*
%{_mandir}/man1/atopsar.1*
%{_mandir}/man5/atoprc.5*
%{_datadir}/applications/%{name}.desktop

%files daemon
%defattr(-,root,root)
%doc COPYING README
%attr(0700,root,root) %dir %{_sysconfdir}/atop
%attr(0700,root,root) %{_sysconfdir}/atop/atop.daily
%config(noreplace) %{_sysconfdir}/logrotate.d/psaccs_atop
%config(noreplace) %{_sysconfdir}/logrotate.d/psaccu_atop
%config(noreplace) %{_sysconfdir}/cron.d/%{name}
%{_localstatedir}/log/atop
%{_sbindir}/rc%{name}
%if 0%{?suse_version} >= 1210
%{_usr}/lib/systemd/system/%{name}.service
%{_usr}/lib/systemd/system/atopacct.service
%{_usr}/lib/systemd/system-sleep/%{name}-pm.sh
%else
%{_initddir}/%{name}
%{_initddir}/atopacct
%{_usr}/lib/pm-utils/sleep.d/45%{name}pm
%endif
%{_sbindir}/atopacctd
%{_mandir}/man8/atopacctd.8*
%{_sbindir}/rcatopacct

%changelog