File targetcli-fb.spec of Package targetcli-fb

%define realname targetcli-fb
%define srcext   tar.bz2

%if 0%{?suse_version} >= 1230 || 0%{?rhel} >= 7
%bcond_without systemd
%else
%bcond_with systemd
%endif

%if ! 0%{?py_ver:1}
%define py_ver %(python -c "import sys; v=sys.version_info[:2]; print '%%d.%%d'%%v" 2>/dev/null || echo PYTHON-NOT-FOUND)
%endif

# Common info
Name:          %{realname}
Version:       2.1.43
Release:       wiz%{?extraver:0.}1%{?dist}
License:       Apache-2.0
Group:         System/Management
URL:           https://github.com/open-iscsi/targetcli-fb
Summary:       A command shell for managing the Linux LIO kernel target

# Install-time parameters
Provides:      targetcli
Provides:      python-targetcli    = %{version}-%{release}
Provides:      python-targetcli-fb = %{version}-%{release}
Provides:      python-targetcli_fb = %{version}-%{release}
Obsoletes:     python-targetcli    < %{version}-%{release}
Obsoletes:     python-targetcli-fb < %{version}-%{release}
Obsoletes:     python-targetcli_fb < %{version}-%{release}
Requires:      python(abi) = %{py_ver}
Requires:      python-configshell-fb
Requires:      python-rtslib-fb
Requires:      python-dbus
Requires:      python-six
# Optional
Requires:      python-ethtool

# Build-time parameters
%if ! 0%{?sles_version}
BuildArch:     noarch
%endif
BuildRequires: python-setuptools
%if 0%{?suse_version}
BuildRequires: fdupes
%endif
BuildRoot:     %{_tmppath}/%{name}-root
Source:        %{realname}-%{version}%{?extraver}.%{srcext}
Source11:      targetcli.init

%description
targetcli-fb is a command-line interface for configuring the LIO generic
SCSI target, present in 3.x Linux kernel versions.

targetcli-fb is a fork of the "targetcli" code written by RisingTide Systems.
The "-fb" differentiates between the original and this version. Please ensure
to use either all "fb" versions of the targetcli components -- targetcli,
rtslib, and configshell, or stick with all non-fb versions, since they are
no longer strictly compatible.

# Preparation step (unpackung and patching if necessary)
%prep
%setup -q -n %{realname}-%{version}%{?extraver}

%build
python setup.py build

%install
python setup.py install --prefix=%{_prefix} --root=%{buildroot} -O2
%{__install} -d -m0755 %{buildroot}%{_sysconfdir}/target
%{__install} -D -m0644 targetcli.8  %{buildroot}%{_mandir}/man8/targetcli.8
%{__install} -D -m0644 targetclid.8 %{buildroot}%{_mandir}/man8/targetclid.8
[ "%{buildroot}" != "/" ] && find %{buildroot}%{python_sitelib}/ -name "*.pyo" -delete
%if %{with systemd}
%{__install} -D -m0644 systemd/targetclid.service %{buildroot}%{_unitdir}/targetclid.service
%{__install} -D -m0644 systemd/targetclid.socket  %{buildroot}%{_unitdir}/targetclid.socket
%else
%{__install} -D -m0755 %{S:11} %{buildroot}%{_initrddir}/targetcli
%endif
%if 0%{?suse_version}
%if %{without systemd}
%{__install} -d -m0755 %{buildroot}%{_sbindir}
%{__ln_s} -f %{_initrddir}/targetcli %{buildroot}%{_sbindir}/rctargetcli
%endif
%fdupes %{buildroot}%{python_sitelib}
%endif

%clean
[ "%{buildroot}" != "/" ] && %{__rm} -rf %{buildroot}

%files
%defattr(-,root,root)
%doc COPYING README.md THANKS
%dir %{_sysconfdir}/target
%{_bindir}/targetcli
%{_bindir}/targetclid
%if %{with systemd}
%{_unitdir}/targetclid.service
%{_unitdir}/targetclid.socket
%else
%{_initrddir}/targetcli
%{?suse_version:%{_sbindir}/rctargetcli}
%endif
%{python_sitelib}/targetcli/
%{python_sitelib}/targetcli_fb-%{version}-py%{py_ver}.egg-info/
%doc %{_mandir}/man8/targetcli.8*
%doc %{_mandir}/man8/targetclid.8*

%if 0%{?suse_version}

%if %{with systemd}
%pre
%{service_add_pre targetclid.service}
%{service_add_pre targetclid.socket}
%endif

%post
%if %{with systemd}
%{fillup_only -n targetcli}
%{service_add_post targetclid.service}
%{service_add_post targetclid.socket}
%else
%{fillup_and_insserv -n targetcli}
%endif

%preun
%if %{with systemd}
%{service_del_preun targetclid.service}
%{service_del_preun targetclid.socket}
%else
%{stop_on_removal targetcli}
%endif

%postun
%if %{with systemd}
%{service_del_postun targetclid.service}
%{service_del_postun targetclid.socket}
%else
%{restart_on_update targetcli}
%{insserv_cleanup}
%endif

%endif

%changelog
openSUSE Build Service is sponsored by