%define majver 2.0
%define subver 870.3

Summary: iSCSI daemon and utility programs
Summary(ja): iSCSI デーモンおよびユーティリティプログラム
#Name: iscsi-initiator-utils
Name: open-iscsi
Version: %{majver}.%{subver}
Release: 3%{?_dist_release}
Source0: http://www.open-iscsi.org/bits/open-iscsi-%{majver}-%{subver}.tar.gz
Source1: iscsid.init
Source2: iscsidevs.init
Patch0: iscsi-initiator-utils-update-initscripts-and-docs.patch
Patch1: iscsi-initiator-utils-use-var-for-config.patch

Group: System Environment/Daemons
License: GPL
URL: http://www.open-iscsi.org/
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildRequires: openssl-devel
BuildRequires: glibc-static
PreReq: chkconfig initscripts
ExcludeArch: s390 s390x

# to avoid conflicts with Fedora's iscsi-initiator-utils package
Obsoletes: iscsi-initiator-utils
Conflicts: iscsi-initiator-utils


%description
The iscsi package provides the server daemon for the iSCSI protocol,
as well as the utility programs used to manage it. iSCSI is a protocol
for distributed disk access using SCSI commands sent over Internet
Protocol networks.


%prep
%setup -q -n %{name}-%{majver}-%{subver}
%patch0 -p1 -b .update-initscripts-and-docs
%patch1 -p1 -b .use-var-for-config


%build
make OPTFLAGS="%{optflags}" -C utils/fwparam_ibft
make OPTFLAGS="%{optflags}" -C usr
make OPTFLAGS="%{optflags}" -C utils


%install
rm -rf $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT/sbin
mkdir -p $RPM_BUILD_ROOT%{_mandir}/man8
mkdir -p $RPM_BUILD_ROOT%{_initrddir}
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/iscsi
mkdir -p $RPM_BUILD_ROOT%{_var}/lib/iscsi
mkdir -p $RPM_BUILD_ROOT%{_var}/lib/iscsi/nodes
mkdir -p $RPM_BUILD_ROOT%{_var}/lib/iscsi/send_targets
mkdir -p $RPM_BUILD_ROOT%{_var}/lock/iscsi

install -p -m 755 usr/iscsid usr/iscsiadm utils/iscsi-iname usr/iscsistart $RPM_BUILD_ROOT/sbin
install -p -m 644 doc/iscsiadm.8 $RPM_BUILD_ROOT/%{_mandir}/man8
install -p -m 644 doc/iscsid.8 $RPM_BUILD_ROOT/%{_mandir}/man8
install -p -m 644 etc/iscsid.conf $RPM_BUILD_ROOT%{_sysconfdir}/iscsi

install -p -m 755 %{SOURCE1} $RPM_BUILD_ROOT%{_initrddir}/iscsid
install -p -m 755 %{SOURCE2} $RPM_BUILD_ROOT%{_initrddir}/iscsi


%clean
rm -rf $RPM_BUILD_ROOT


%post
if [ "$1" -eq "1" ]; then
	if [ ! -f %{_sysconfdir}/iscsi/initiatorname.iscsi ]; then
		echo "InitiatorName=`/sbin/iscsi-iname`" > %{_sysconfdir}/iscsi/initiatorname.iscsi
	fi
	/sbin/chkconfig --add iscsid
	/sbin/chkconfig --add iscsi
fi


%preun
if [ "$1" = "0" ]; then
	# stop iscsi
	/sbin/service iscsi stop > /dev/null 2>&1
	# delete service
	/sbin/chkconfig --del iscsi
	# stop iscsid
	/sbin/service iscsid stop > /dev/null 2>&1
	# delete service
	/sbin/chkconfig --del iscsid
fi


%files
%defattr(-,root,root)
%doc README
%dir %{_var}/lib/iscsi
%dir %{_var}/lib/iscsi/nodes
%dir %{_var}/lib/iscsi/send_targets
%dir %{_var}/lock/iscsi
%{_initrddir}/iscsi
%{_initrddir}/iscsid
%attr(0600,root,root) %config(noreplace) %{_sysconfdir}/iscsi/iscsid.conf
/sbin/*
%{_mandir}/man8/*


%changelog
* Mon Apr 18 2011 Shu KONNO <owa@bg.wakwak.com> 2.0.870.3-3
- added BR: glibc-static

* Sun Apr 17 2011 Shu KONNO <owa@bg.wakwak.com> 2.0.870.3-2
- rebuilt with rpm-4.8.1-3

* Sat Jun 13 2009 Daisuke SUZUKI <daisuke@linux.or.jp> 2.0.870.3-1
- new upstream release
- new versioning policy

* Wed Dec 05 2007 MATSUBAYASHI Kohji <shaolin@vinelinux.org> - 2.0.865.15-0vl1
- initial package for VineSeed
- derived from Fedora8 6.2.0.865-0.2
- package name changed to open-iscsi
- updated to 2.0-865.15

* Fri Oct 5 2007 Mike Christie <mchristie@redhat.com> - 6.2.0.865-0.2
- Rebase to upstream's bug fix release.
- Revert init script startup changes from 225915 which reviewers did
 not like.

* Mon Jun 20 2007 Mike Christie <mchristie@redhat.com> - 6.2.0.754-0.1
- 225915 From Adrian Reber - Fix up spec and init files for rpmlint.

* Tue Feb 6 2007 Mike Christie <mchristie@redhat.com> - 6.2.0.754-0.0
- Rebase to upstream.
- Add back --map functionality but in session mode to match RHEL5 fixes
- Break up iscsi init script into two, so iscsid can be started early for root

* Tue Nov 28 2006 Mike Christie <mchristie@redhat.com> - 6.2.0.747-0.0
- Fix several bugs in actor.c (iscsi scheduling). This should result
- in better dm-multipath intergation and fix bugs where time outs
- or requests were missed or dropped.
- Set default noop timeout correctly.

* Sat Nov 25 2006 Mike Christie <mchristie@redhat.com> - 6.2.0.742-0.0
- Don't flood targets with nop-outs.

* Fri Nov 24 2006 Mike Christie <mchristie@redhat.com> - 6.2.0.737-0.0
- Add commands missing from RHEL4/RHEL3 and document iscsid.conf.
- Fixup README.

* Mon Nov 7 2006 Mike Christie <mchristie@redhat.com> - 6.2.0.695-0.8
- Rebase to upstream open-iscsi-2.0-730.

* Tue Oct 17 2006 Mike Christie <mchristie@redhat.com> - 6.2.0.695-0.7
- Change period to colon in default name

* Thu Oct 5 2006 Mike Christie <mchristie@redhat.com> - 6.2.0.695-0.6
- BZ 209523 make sure the network is not going to get shutdown so
iscsi devices (include iscsi root and dm/md over iscsi) get syncd.
- BZ 209415 have package create iscsi var dirs

* Tue Oct 3 2006 Mike Christie <mchristie@redhat.com> - 6.2.0.695-0.5
- BZ 208864 move /etc/iscsi/nodes and send_targets to /var/lib/iscsi

* Mon Oct 1 2006 Mike Christie <mchristie@redhat.com> - 6.2.0.695-0.4
- BZ 208548 move /etc/iscsi/lock to /var/lock/iscsi/lock

* Wed Sep 27 2006 Jeremy Katz <katzj@redhat.com> - 6.2.0.695-0.3
- Add fix for initscript with pid file moved

* Tue Sep 26 2006 Mike Christie <mchristie@redhat.com> - 6.2.0.695-0.2
- BZ 208050 - change default initiator name to reflect redhat
- Move pid from /etc/iscsi to /var/run/iscsid.pid

* Fri Sep 15 2006 Mike Christie <mchristie@redhat.com> - 6.2.0.695-0.1
- Add compat with FC kernel so iscsid will pass startup checks and run.
- Fix bug when using hw iscsi and software iscsi and iscsid is restarted.
- Fix session matching bug when hw and software iscsi is both running

* Tue Sep  5 2006 Jeremy Katz <katzj@redhat.com> - 6.1.1.685-0.1
- Fix service startup
- Fix another case where cflags weren't being used

* Mon Aug 28 2006 Mike Christie <mchristie@redhat.com> - 6.1.1.685
- Rebase to upstream to bring in many bug fixes and rm db.
- iscsi uses /etc/iscsi instead of just etc now

* Fri Jul 21 2006 Jeremy Katz <katzj@redhat.com> - 6.1.1.645-1
- fix shutdown with root on iscsi

* Thu Jul 13 2006 Mike Christie <mchristie@redhat.com> - 6.1.1.645
- update to upstream 1.1.645
- Note DB and interface changed so you must update kernel, tools and DB

* Wed Jul 12 2006 Jesse Keating <jkeating@redhat.com> - 6.0.5.595-2.1.1
- rebuild

* Wed Jul 12 2006 Jesse Keating <jkeating@redhat.com> - 6.0.5.595-2.1
- rebuild

* Wed Jun 21 2006 Mike Christie <mchristi@redhat.com> - 6.0.5.595-2
- add PatM's statics.c file. This is needed for boot since 
  there is no getpwuid static available at that time.
* Tue Jun 20 2006 Jeremy Katz <katzj@redhat.com> - 6.0.5.595-1
- ensure that we respect %%{optflags}
- cleaned up initscript to make use of standard functions, return right 
  values and start by default
- build iscsistart as a static binary for use in initrds

* Tue May 30 2006 Mike Christie <mchristi@redhat.com>
- rebase package to svn rev 595 to fix several bugs
  NOTE!!!!!!!! This is not compatible with the older open-iscsi modules
  and tools. You must upgrade.

* Thu May 18 2006 Mike Christie <mchristi@redhat.com>
- update package to open-iscsi svn rev 571
  NOTE!!!!!!!! This is not compatible with the older open-iscsi modules
  and tools. You must upgrade.

* Fri Apr 7 2006 Mike Christie <mchristi@redhat.com>
- From Andy Henson <andy@zexia.co.uk>:
  Autogenerate /etc/initiatorname.iscsi during install if not already present
- Remove code to autogenerate /etc/initiatorname.iscsi from initscript
- From dan.y.roche@gmail.com:
  add touch and rm lock code
- update README
- update default iscsid.conf. "cnx" was not supported. The correct
  id was "conn".

* Fri Feb 10 2006 Jesse Keating <jkeating@redhat.com> - 5.0.5.476-0.1
- bump again for double-long bug on ppc(64)

* Mon Jan 23 2006 Mike Christie <mchristi@redhat.com>
- rebase package to bring in ppc64 unsigned long vs unsigned
  long long fix and iscsadm return value fix. Also drop rdma patch
  becuase it is now upstream.
* Wed Dec 14 2005 Mike Christie <mchristi@redhat.com>
- initial packaging

