%bcond_with systemd
%define _udevrulesdir /lib/udev/rules.d

Summary:        Utilities for Linux md devices (software RAID arrays)
Summary(ja):    Linux の MD デバイス(ソフトウエアRAIDアレイ)用のユーティリティ
Name:           mdadm
Version:        4.2
Release:        1%{?_dist_release}%{?with_systemd:.systemd}
Group:          system
Vendor:         Project Vine
Distribution:   Vine Linux
BuildRoot:      %{_tmppath}/%{name}-%{version}-root

License:        GPL
URL:            https://www.kernel.org/pub/linux/utils/raid/mdadm/
Source:         https://www.kernel.org/pub/linux/utils/raid/mdadm/mdadm-%{version}.tar.xz
Source1:        mdmonitor.init
Source2:        raid-check
Source3:        mdadm.rules
Source4:        mdadm-raid-check-sysconfig
Source5:        mdadm-cron

Source103:      mdadm.rules.systemd
Source104:      mdmonitor.service
Source105:      mdadm.conf
Source106:      mdadm_event.conf
Source107:      raid-check.timer
Source108:      raid-check.service

Patch97:        mdadm-3.3-udev.patch
Patch98:        mdadm-2.5.2-static.patch

Obsoletes:      mdctl,raidtools
Requires:       postfix
BuildRequires:  glibc-static

%if %{with systemd}
BuildRequires: systemd-devel
Requires(post): systemd coreutils
Requires(preun): systemd
Requires(postun): systemd coreutils
%else
BuildRequires: eudev-libudev-devel
Requires(post): /sbin/chkconfig
Requires(preun): /sbin/chkconfig
Requires(preun): /sbin/service
Requires(postun): /sbin/service
%endif

%description 
mdadm is used to create, manage, and monitor Linux MD (software RAID)
devices.  As such, it provides similar functionality to the raidtools
package.  However, mdadm is a single program, and it can perform
almost all functions without a configuration file, though a configuration
file can be used to help with some common tasks.


%debug_package


%prep
%setup -q
%autopatch -p1

sed -i -e 's/ -Werror / /' Makefile

%build
make %{?_smp_mflags} CXFLAGS="$RPM_OPT_FLAGS" LDFLAGS="$RPM_LD_FLAGS" SYSCONFDIR="%{_sysconfdir}" mdadm mdmon


%install
rm -rf %{buildroot}

%if %{with systemd}
make DESTDIR=%{buildroot} MANDIR=%{_mandir} BINDIR=/sbin SYSTEMD_DIR=%{_unitdir} install install-systemd
%else
make DESTDIR=%{buildroot} MANDIR=%{_mandir} BINDIR=/sbin install
%endif
install -Dp -m 755 %{SOURCE2} %{buildroot}%{_sbindir}/raid-check
install -Dp -m 644 %{SOURCE4} %{buildroot}%{_sysconfdir}/sysconfig/raid-check

%if %{with systemd}
install -Dp -m 644 %{SOURCE103} %{buildroot}%{_udevrulesdir}/65-md-incremental.rules
# systemd
mkdir -p %{buildroot}%{_unitdir}
install -m644 %{SOURCE104} %{buildroot}%{_unitdir}
install -m644 %{SOURCE107} %{buildroot}%{_unitdir}
install -m644 %{SOURCE108} %{buildroot}%{_unitdir}

# tmpfile
mkdir -p %{buildroot}%{_tmpfilesdir}
install -m 0644 %{SOURCE105} %{buildroot}%{_tmpfilesdir}/%{name}.conf
install -d -m 0710 %{buildroot}/run/%{name}/

# abrt
#mkdir -p %{buildroot}/etc/libreport/events.d
#install -m644 %{SOURCE6} %{buildroot}/etc/libreport/events.d
%else
# initscript
mkdir -p %{buildroot}%{_initdir}
install -m755 %{SOURCE1} %{buildroot}%{_initdir}/mdmonitor
install -Dp -m 644 %{SOURCE5} %{buildroot}%{_sysconfdir}/cron.d/raid-check
install -Dp -m 644 %{SOURCE3} %{buildroot}%{_udevrulesdir}/65-md-incremental.rules
mkdir -p %{buildroot}%{_localstatedir}/run/mdadm
%endif


%clean
rm -rf %{buildroot}


%post
%if %{with systemd}
%systemd_post mdmonitor.service raid-check.{service,timer}
%else
/sbin/chkconfig --add mdmonitor
%endif

%preun
%if %{with systemd}
%systemd_preun mdmonitor.service raid-check.timer
%else
if [ "$1" = 0 -o -x /bin/systemctl ]; then
	service mdmonitor stop > /dev/null 2>&1 ||:
	/sbin/chkconfig --del mdmonitor
fi
if [ -e %{_initrddir}/mdmpd ]; then
	service mdmpd stop > /dev/null 2>&1 ||:
	/sbin/chkconfig --del mdmpd
fi
%endif

%postun
%if %{with systemd}
%systemd_postun_with_restart mdmonitor.service
%else
if [ "$1" -ge "1" ]; then
	service mdmonitor condrestart > /dev/null 2>&1
fi
%endif


%files
%defattr(-,root,root)
%license COPYING
%doc mdadm.conf-example misc/*
/sbin/*
%{_sbindir}/*
%if %{with systemd}
%{_unitdir}/*
/lib/systemd/system-shutdown/*
%config(noreplace) %{_tmpfilesdir}/%{name}.conf
%else
%{_initdir}/*
%config(noreplace) %{_sysconfdir}/cron.d/*
%dir %{_localstatedir}/run/%{name}/
%endif
%{_mandir}/man*/md*
%{_udevrulesdir}/*
%config(noreplace) %{_sysconfdir}/sysconfig/*


%changelog
* Mon Nov 14 2022 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 4.2-1
- new upstream release.

* Sun Apr 12 2020 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 4.1-1
- new upstream release.
- added systemd support (disabled as default).
- dropped Patch93-96.

* Sat Feb 24 2018 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 4.0-1
- new upstream release.

* Fri Jan 10 2014 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 3.3-1
- new upstream release.

* Sat Dec 28 2013 Yoji TOYODA <bsyamato@sea.plala.or.jp> 2.6.9-4
- rebuild with VineSeed environment

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

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

* Sun Apr 26 2009 Daisuke SUZUKI <daisuke@linux.or.jp> 2.6.9-1
- new upstream release

* Sat Oct 04 2008 Shu KONNO <owa@bg.wakwak.com> 2.5.5-1vl5
- applied new versioning policy, spec in utf-8

* Wed Oct 25 2006 Daisuke SUZUKI <daisuke@linux.or.jp> 2.5.5-0vl1
- new upstream release

* Wed Aug 30 2006 Daisuke SUZUKI <daisuke@linux.or.jp> 2.5.3-0vl1
- initial build for Vine Linux

* Mon Aug  7 2006 Doug Ledford <dledford@redhat.com> - 2.5.3-1
- Update to 2.5.3 which upstream calls a "bug fix" release

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

* Fri Jul  7 2006 Doug Ledford <dledford@redhat.com> - 2.5.2-1
- Update to 2.5.2
- Remove auto default patch as upstream now has a preferred default auto method

* Wed Mar  8 2006 Peter Jones <pjones@redhat.com> - 2.3.1-3
- fix build on ppc64

* Wed Mar  8 2006 Jeremy Katz <katzj@redhat.com> - 2.3.1-2
- fix build on ppc

* Wed Mar  8 2006 Jeremy Katz <katzj@redhat.com> - 2.3.1-1
- update to 2.3.1 to fix raid5 (#184284)

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

* Tue Feb 07 2006 Jesse Keating <jkeating@redhat.com> - 2.2-1.fc5.2
- rebuilt for new gcc4.1 snapshot and glibc changes

* Fri Dec 09 2005 Jesse Keating <jkeating@redhat.com>
- rebuilt

* Mon Dec 05 2005 Warren Togami <wtogami@redhat.com> 2.2-1
- 2.2 upgrade (#167897)
- disable diet because we don't ship it anymore
  and we don't actually use mdassemble now

* Mon May 16 2005 Doug Ledford <dledford@redhat.com> 1.11.0-4.fc4
- Make the mdmonitor init script use the pid-file option, major cleanup
  of the script now possible (#134459)

* Mon May 16 2005 Doug Ledford <dledford@redhat.com> 1.11.0-3.fc4
- Put back the obsoletes: raidtools that was present in 1.11.0-1.fc4

* Mon May 16 2005 Doug Ledford <dledford@redhat.com> 1.11.0-2.fc4
- Change the default auto= mode so it need not be on the command line to
  work with udev, however it is still supported on the command line (#132706)
- Add a man page (from Luca Berra) for mdassemble

* Wed May 11 2005 Doug Ledford <dledford@redhat.com> - 1.11.0-1.fc4
- Upgrade to 1.11.0

* Wed Apr 27 2005 Jeremy Katz <katzj@redhat.com> - 1.9.0-3.fc4
- fix mdmonitor initscript (#144717)

* Mon Mar 21 2005 Doug Ledford <dledford@redhat.com> 1.9.0-2
- Build mdadm.static and mdassemble (static as well) to be used in initrd
  images

* Wed Mar 09 2005 Doug Ledford <dledford@redhat.com> 1.9.0-1
- Initial upgrade to 1.9.0 and update of doc files
- Fix an s390 build error

* Mon Oct 04 2004 Doug Ledford <dledford@redhat.com> 1.6.0-2
- Remove /etc/mdadm.conf from the file list.  Anaconda will write one out
  if it's needed.

* Fri Oct 01 2004 Doug Ledford <dledford@redhat.com> 1.6.0-1
- Update to newer upstream version
- Make mdmpd work on kernels that don't have the event interface patch

* Fri Jul 30 2004 Dan Walsh <dwalsh@redhat.com> 1.5.0-11
- Create a directory /var/run/mdadm to contain mdadm.pid
- This cleans up SELinux problem

* Tue Jun 15 2004 Elliot Lee <sopwith@redhat.com>
- rebuilt

* Sat May 22 2004 Doug Ledford <dledford@redhat.com> - 1.5.0-9
- Fix Makefile and build method to satisfy bz #123769
- Add mdmpd man page, update mdmpd version to 0.3 - bz #117160
- Make sure mdadm --monitor closes all md device files so that md devices
  can be stopped while mdadm is still running - bz #119532

* Thu May 20 2004 Jeremy Katz <katzj@redhat.com> - 1.5.0-8
- remove unneeded patch, can use --run instead

* Wed May 19 2004 Jeremy Katz <katzj@redhat.com> - 1.5.0-7
- add patch with reallyforce mode on creation to be used by anaconda

* Wed May 12 2004 Doug Ledford <dledford@redhat.com> 2.5.0-6
- Fix a bug in the %postun scriptlet related to downgrading to a version
  of mdadm that doesn't include the mdmpd daemon.

* Fri May 07 2004 Doug Ledford <dledford@redhat.com> 1.5.0-5
- Disable service mdmpd by default to avoid [Failed] messages on
  current 2.6 kernels.  Possibly re-enable it by default once the
  2.6 kernels have the md event interface.

* Thu Apr 22 2004 Doug Ledford <dledford@redhat.com> 1.5.0-4
- Update mdmonitor script to start daemon more cleanly
- Repackage mdmpd tarball to include gcc-3.4 changes and to make
  mdmpd properly daemonize at startup instead of forking and leaving
  the child attached to the terminal.

* Thu Mar  4 2004 Bill Nottingham <notting@redhat.com> 1.5.0-3
- ship /var/run/mpmpd (#117497)

* Thu Feb 26 2004 Doug Ledford <dledford@redhat.com> 1.5.0-2
- Add a default MAILADDR line to the mdadm.conf file installed by default
  (Bugzilla #92447)
- Make it build with gcc-3.4

* Mon Feb 23 2004 Doug Ledford <dledford@redhat.com> 1.5.0-1
- Update to 1.5.0 (from Matthew J. Galgoci <mgalgoci@redhat.com>)

* Sun Nov 16 2003 Doug Ledford <dledford@redhat.com> 1.4.0-1
- fix problem with recovery thread sleeping in mdmpd

* Fri Nov 14 2003 Doug Ledford <dledford@redhat.com>
- sync upstream
- add mdmpd package into mdadm package

* Wed Sep 10 2003 Michael K. Johnson <johnsonm@redhat.com> 1.3.0-1
- sync upstream

* Tue Mar 11 2003 Michael K. Johnson <johnsonm@redhat.com> 1.1.0-1
- sync upstream

* Tue Jan 28 2003 Michael K. Johnson <johnsonm@redhat.com> 1.0.1-1
- update for rebuild

* Wed Dec 25 2002 Tim Powers <timp@redhat.com> 1.0.0-8
- fix references to %%install in the changelog so that it will build

* Fri Dec 13 2002 Elliot Lee <sopwith@redhat.com> 1.0.0-7
- Rebuild

* Fri Jul 12 2002 Michael K. Johnson <johnsonm@redhat.com>
- Changed RPM Group to System Environment/Base

* Wed May 15 2002 Michael K. Johnson <johnsonm@redhat.com>
- minor cleanups to the text, conditionalize rm -rf
- added mdmonitor init script

* Fri May 10 2002  <neilb@cse.unsw.edu.au>
- update to 1.0.0
- Set CXFLAGS instead of CFLAGS

* Sat Apr  6 2002  <neilb@cse.unsw.edu.au>
- change %%install to use "make install"

* Fri Mar 15 2002  <gleblanc@localhost.localdomain>
- beautification
- made mdadm.conf non-replaceable config
- renamed Copyright to License in the header
- added missing license file
- used macros for file paths

* Fri Mar 15 2002 Luca Berra <bluca@comedia.it>
- Added Obsoletes: mdctl
- missingok for configfile

* Tue Mar 12 2002 NeilBrown <neilb@cse.unsw.edu.au>
- Add md.4 and mdadm.conf.5 man pages

* Fri Mar 08 2002		Chris Siebenmann <cks@cquest.utoronto.ca>
- builds properly as non-root.

* Fri Mar 08 2002 Derek Vadala <derek@cynicism.com>
- updated for 0.7, fixed /usr/share/doc and added manpage

* Tue Aug 07 2001 Danilo Godec <danci@agenda.si>
- initial RPM build
