#
# cgmanager: cgroup manager daemon
#
# Copyright (C) 2013 Oracle
#
# Authors:
# Dwight Engen <dwight.engen@oracle.com>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

Name: cgmanager
Version: 0.41
Release: 1%{?_dist_release}
URL: http://cgmanager.linuxcontainers.org
Source: http://cgmanager.linuxcontainers.org/downloads/%{name}-%{version}.tar.gz
Summary: Linux cgroup manager
Group: Applications/System
License: LGPLv2+
BuildRoot: %{_tmppath}/%{name}-%{version}-build
Requires: dbus libnih
BuildRequires: libnih-devel dbus-devel pam-devel help2man

%description
CGManager is a central privileged daemon that manages all your cgroups for
you through a simple DBus API.  It's designed to work with nested LXC
containers as well as accepting unprivileged requests including resolving
user namespaces UIDs/GIDs.

%package	libs
Summary:	Shared library files for %{name}
Group:		System Environment/Libraries
%description	libs
The %{name}-libs package contains libraries for running %{name} applications.

%package	devel
Summary:	Development library for %{name}
Group:		Development/Libraries
Requires:	%{name} = %{version}-%{release}, pkgconfig
%description	devel
The %{name}-devel package contains header files and library needed for
development with %{name}.

%prep
%setup -q -n %{name}-%{version}

%build
%configure --with-init-script=upstart

make %{?_smp_mflags}

perl -pi -e 's|/sbin/cgmanager|/usr/sbin/cgmanager|' config/init/upstart/cgmanager.conf
perl -pi -e 's|^start on.*$|start on runlevel [345]|' config/init/upstart/cgmanager.conf

perl -pi -e 's|/sbin/cgproxy|/usr/sbin/cgproxy|' config/init/upstart/cgproxy.conf

%install
rm -rf %{buildroot}
make install DESTDIR=%{buildroot}
find %{buildroot} -type f -name '*.la' -exec rm -f {} ';'

rm -f %{buildroot}/%{_libdir}/*.a

#mkdir -p %{buildroot}/%{_sysconfdir}/init
#mkdir -p %{buildroot}/%{_datadir}/upstart/sessions

#install -m 644 config/init/upstart/cgmanager.conf %{buildroot}/%{_sysconfdir}/init/cgmanager.conf
#install -m 644 config/init/upstart/cgproxy.conf %{buildroot}/%{_sysconfdir}/init/cgproxy.conf
#install -m 644 config/init/upstart/sessions/cgmanager.conf %{buildroot}/%{_datadir}/upstart/sessions/cgmanager.conf


%check
make check

%clean
rm -rf %{buildroot}

%preun
if [ $1 -eq 0 ]; then
  /sbin/stop cgproxy >/dev/null 2>&1 ||:
  /sbin/stop cgmanager >/dev/null 2>&1 ||:
else
  /sbin/restart cgproxy >/dev/null 2>&1 ||:
  /sbin/restart cgmanager >/dev/null 2>&1 ||:
fi

%post   libs -p /sbin/ldconfig
%postun libs -p /sbin/ldconfig

%files
%defattr(-,root,root)
%doc AUTHORS COPYING ChangeLog INSTALL NEWS README TODO
%config(noreplace) %{_sysconfdir}/init/*.conf
%config(noreplace) %{_datadir}/upstart/sessions/*.conf
%{_mandir}/man1/cgm.1*
%{_bindir}/*
%{_sbindir}/*
%{_libexecdir}/%{name}
/%{_lib}/security/pam_cgm.so
%{_mandir}/man8/*
%{_datadir}/%{name}

%files libs
%defattr(-,root,root)
%{_libdir}/*.so.*

%files devel
%defattr(-,root,root)
%{_includedir}/%{name}/*
%{_libdir}/*.so
%{_libdir}/pkgconfig/*

%changelog
* Mon Sep 04 2017 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 0.41-1
- initial build for Vine Linux.

* Mon Mar 24 2014 Dwight Engen <dwight.engen@oracle.com> - 0.23
remove libnih-dbus Requires since there is no such package, libnih is sufficient

* Mon Mar 24 2014 Dwight Engen <dwight.engen@oracle.com> - 0.22
add cgm script

* Tue Feb 04 2014 Dwight Engen <dwight.engen@oracle.com> - 0.19
- created
