%global srcname virtualbmc

Name: python-%{srcname}
Version: 1.5.0
Release: 1%{?dist}
Summary: A virtual BMC for controlling virtual machines using IPMI commands
License: ASL 2.0
URL: https://github.com/openstack/virtualbmc
Source0: %{srcname}-%{version}.tar.gz
Source1: 60-vbmcd.rules
Source2: vbmcd.service
BuildArch: noarch
BuildRequires: python3-devel
BuildRequires: python3-pbr
BuildRequires: python3-setuptools
BuildRequires: systemd-rpm-macros


%description
A virtual BMC for controlling virtual machines using IPMI commands.


%package -n python3-%{srcname}
Summary: A virtual BMC for controlling virtual machines using IPMI commands
#Suggests: python3-%{srcname}-doc
Requires(pre): shadow-utils
%{?python_provide:%python_provide python3-%{srcname}}
%description -n python3-%{srcname}
A virtual BMC for controlling virtual machines using IPMI commands.


%prep
%autosetup -n %{srcname}-%{version}


%build
%{__python3} setup.py build


%install
%{__python3} setup.py install --optimize 2 --root %{buildroot}
install -D -m 0644 %{SOURCE1} %{buildroot}%{_sysconfdir}/polkit-1/rules.d/60-vbmcd.rules
install -D -m 0644 %{SOURCE2} %{buildroot}%{_unitdir}/vbmcd.service
install -d -m 750 %{buildroot}%{_sharedstatedir}/vbmcd


%pre -n python3-%{srcname}
getent group vbmcd >/dev/null || groupadd -r vbmcd
getent passwd vbmcd >/dev/null || \
    useradd -r -g vbmcd -d %{_sharedstatedir}/vbmcd -s /sbin/nologin \
    -c "VirtualBMC daemon" vbmcd
exit 0

%post -n python3-%{srcname}
%systemd_post vbmcd.service

%preun -n python3-%{srcname}
%systemd_preun vbmcd.service

%postun -n python3-%{srcname}
%systemd_postun_with_restart vbmcd.service


%files -n python3-%{srcname}
%license LICENSE
%{_bindir}/vbmcd
%{_bindir}/vbmc
%{python3_sitelib}/%{srcname}
%{python3_sitelib}/%{srcname}-*.egg-info
%exclude %{python3_sitelib}/%{srcname}/tests
%config(noreplace) %{_sysconfdir}/polkit-1/rules.d/60-vbmcd.rules
%{_unitdir}/vbmcd.service
%dir %attr(750, vbmcd, vbmcd) %{_sharedstatedir}/vbmcd

%changelog
