#
# spec file for package fcoe-utils
#
# Copyright (c) 2013 SUSE LINUX Products GmbH, Nuernberg, Germany.
#
# 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/
#


Name:           fcoe-utils
Url:            http://www.open-fcoe.org
BuildRequires:  autoconf
BuildRequires:  automake
BuildRequires:  libHBAAPI2-devel
BuildRequires:  libhbalinux2-devel
BuildRequires:  libtool
BuildRequires:  open-lldp-devel
Requires:       device-mapper-multipath
Requires:       iproute
BuildRequires:  systemd
%systemd_requires
Version:        1.0.29
Release:        0
Summary:        FCoE userspace management tools
License:        GPL-2.0
Group:          System/Daemons
# git://open-fcoe.org/fcoe/fcoe-utils.git
Source0:        %{name}-%{version}.tar.xz
Source1:        fcoe.service
Source2:        fcoe.config
Source20:       mkinitrd-boot.sh
Source22:       mkinitrd-setup.sh
# Patches from Fedora
Patch1:         fcoe-utils-1.0.29-make.patch
Patch2:         fcoe-utils-1.0.18-help.patch
Patch3:         fcoe-utils-1.0.28-format-strings.patch
Patch4:         fcoe-utils-1.0.28-systemd-doc.patch
Patch5:         fcoe-utils-1.0.29-no-as-needed.patch
BuildRoot:      %{_tmppath}/%{name}-%{version}-build

%description
Userspace tools to manage FibreChannel over Ethernet (FCoE)
connections.


%prep
%setup -q
%patch1 -p1 -b .make
%patch2 -p1 -b .help
%patch3 -p1 -b .format-strings
%patch4 -p1 -b .systemd-doc
%patch5 -p1 -b .no-as-needed

%build
autoreconf -vi
%configure
make %{?_smp_mflags}

%install
%make_install
# old init script
rm -rf %{buildroot}/etc/init.d

# mkinitrd script
install -d ${RPM_BUILD_ROOT}/lib/mkinitrd/scripts/
install -m 755 %{S:20} ${RPM_BUILD_ROOT}/lib/mkinitrd/scripts/boot-fcoe.sh
install -m 755 %{S:22} ${RPM_BUILD_ROOT}/lib/mkinitrd/scripts/setup-fcoe.sh

# unitfile
mkdir -p %{buildroot}%{_unitdir}
install -p -m 644 %{SOURCE1} %{buildroot}%{_unitdir}
ln -s %{_sbindir}/service %{buildroot}%{_sbindir}/rcfcoe

# config
mkdir -p %{buildroot}/var/adm/fillup-templates
install -m 644 %{SOURCE2} %{buildroot}/var/adm/fillup-templates/sysconfig.fcoe

# contrib files
mkdir -p %{buildroot}%{_libexecdir}/fcoe
for file in \
	contrib/*.sh \
	debug/*sh
	do install -m 755 ${file} %{buildroot}%{_libexecdir}/fcoe/
done

%pre
%service_add_pre fcoe.service
exit 0

%post
[ -x /sbin/mkinitrd_setup ] && mkinitrd_setup
%service_add_post fcoe.service
%fillup_only -n fcoe
exit 0

%preun
%service_del_preun fcoe.service
exit 0

%postun
[ -x /sbin/mkinitrd_setup ] && mkinitrd_setup
%service_del_preun fcoe.service
exit 0

%files
%defattr(-,root,root,-)
%doc README COPYING QUICKSTART
%{_sbindir}/*
%{_mandir}/man8/*
%{_unitdir}/fcoe.service
%{_sysconfdir}/fcoe/
%config(noreplace) %{_sysconfdir}/fcoe/config
%config(noreplace) %{_sysconfdir}/fcoe/cfg-ethx
%{_sysconfdir}/bash_completion.d/
/var/adm/fillup-templates/sysconfig.fcoe
%{_libexecdir}/fcoe/
/lib/mkinitrd

%changelog