#
# Spec file for ocfs-tools
#

# Macros
# This one is hardcoded because, well, it belongs there
%define _prefix /usr
# Because RPM is dumb
%define _unpackaged_files_terminate_build 0
# Because RH defines lib64 on ppc32 builds
%ifarch ppc
%define brokenrhlibdir /usr/lib
%else
%define brokenrhlibdir %{_libdir}
%endif


%define build_ocfs2console	0
%define compile_py		0
%define systemd_enabled	@@SYSTEMD_ENABLED@@

%if %{build_ocfs2console}
%define compile_py		@@COMPILE_PY@@
%endif

Summary: Tools for managing the Oracle Cluster Filesystem 2
Name: ocfs2-tools
Version: @DIST_VERSION@
Release: @@PKG_VERSION@@.@@VENDOR_EXTENSION@@
License: GPL
Group: System Environment/Kernel
Source: ocfs2-tools-@DIST_VERSION@.tar.gz
URL: http://oss.oracle.com/projects/ocfs2-tools/
Distribution: Oracle
Vendor: Oracle
Packager: nobody <nobody@oracle.com>
Exclusiveos: Linux
Requires: bash, which, coreutils, net-tools, e2fsprogs, @@CHKCONFIG_DEP@@, glib2 >= 2.2.3, util-linux >= 2.12j, @@INSTALL_DEP_PKG@@
BuildRequires: e2fsprogs-devel, glib2-devel >= 2.2.3, @@PYGTK_NAME@@ >= 1.99.16, python-devel >= @@PYVERSION@@, util-linux >= 2.12j, @@BUILD_DEP_PKG@@

BuildRoot: %{_tmppath}/ocfs2-tools-%{PACKAGE_VERSION}-%{PACKAGE_RELEASE}-root
%if !%{build_ocfs2console}
Obsoletes: ocfs2console
%endif

%description
Tools to manage Oracle Cluster Filesystem 2 volumes.

%if %{build_ocfs2console}
%package -n ocfs2console
Summary: GUI frontend for OCFS2 management
Group: System Environment/Kernel
Requires: e2fsprogs, glib2 >= 2.2.3, vte >= 0.11.10, @@PYGTK_NAME@@ >= 1.99.16, python >= @@PYVERSION@@, ocfs2-tools = %{version}
AutoReqProv: No


%description -n ocfs2console
GUI frontend for management and debugging of Oracle Cluster Filesystem 2
volumes.
%endif



%package -n ocfs2-tools-devel
Summary: Headers and static archives for ocfs2-tools
Group: Development/Libraries
Requires: e2fsprogs-devel, glib2-devel >= 2.2.3, ocfs2-tools = %{version}
AutoReqProv: No

%description -n ocfs2-tools-devel
ocfs2-tools-devel contains the libraries and header files needed to
develop ocfs2 filesystem-specific programs.



%prep
%setup -n ocfs2-tools-%{version}


%build
%configure --disable-debug --enable-dynamic-ctl --prefix=/usr --mandir=/usr/share/man --libdir=%{brokenrhlibdir}
make


%install

%if %{systemd_enabled}
	mkdir -p $RPM_BUILD_ROOT/usr/lib/systemd/system
	cp -f  vendor/common/o2cb.service $RPM_BUILD_ROOT/usr/lib/systemd/system/
	cp -f  vendor/common/ocfs2.service $RPM_BUILD_ROOT/usr/lib/systemd/system/
	mkdir -p $RPM_BUILD_ROOT/sbin
	cp -f vendor/common/o2cb.init $RPM_BUILD_ROOT/sbin
	cp -f vendor/common/ocfs2.init $RPM_BUILD_ROOT/sbin
%else
	mkdir -p $RPM_BUILD_ROOT/etc/init.d
	cp -f vendor/common/o2cb.init $RPM_BUILD_ROOT/etc/init.d/o2cb
	cp -f vendor/common/ocfs2.init $RPM_BUILD_ROOT/etc/init.d/ocfs2
%endif
if [ -f /etc/redhat-release ]
then
    # Red Hat chkconfig is completely and utterly broken
    perl -p -i -e 'BEGIN() { $k=0;}  if (/^###/) { $k++ } elsif ($k == 1) { printf "#"};' $RPM_BUILD_ROOT/etc/init.d/o2cb
    perl -p -i -e 'BEGIN() { $k=0;}  if (/^###/) { $k++ } elsif ($k == 1) { printf "#"};' $RPM_BUILD_ROOT/etc/init.d/ocfs2
fi
mkdir -p $RPM_BUILD_ROOT/etc/sysconfig
cp -f vendor/common/o2cb.sysconfig $RPM_BUILD_ROOT/etc/sysconfig/o2cb

make DESTDIR="$RPM_BUILD_ROOT" install

%if %{compile_py}
%{__python} -c "import compileall; compileall.compile_dir('$RPM_BUILD_ROOT/%{brokenrhlibdir}/python@@PYVERSION@@/site-packages/ocfs2interface', ddir='%{brokenrhlibdir}/python@@PYVERSION@@/site-packages/ocfs2interface')"
%endif


%clean
rm -rf "$RPM_BUILD_ROOT"


%post
%if !%{systemd_enabled}
	/sbin/chkconfig --add o2cb >/dev/null
	/sbin/chkconfig --add ocfs2 >/dev/null
%else
	# clean up start/kill entry in /etc/rc*.d/ when upgrade.
	if [ -f /etc/init.d/o2cb ]; then
		/sbin/chkconfig --del o2cb >/dev/null
	fi

	if [ -f /etc/init.d/ocfs2 ]; then
		/sbin/chkconfig --del ocfs2 >/dev/null
	fi
%endif

%preun
%if !%{systemd_enabled}
	if [ $1 = 0 ]; then     # execute this only if we are NOT doing an upgrade
		/sbin/chkconfig --del ocfs2 >/dev/null
		/sbin/chkconfig --del o2cb >/dev/null
	fi
%endif

%files
%defattr(-,root,root)
%doc COPYING CREDITS MAINTAINERS
/sbin/fsck.ocfs2
/sbin/mkfs.ocfs2
/sbin/mounted.ocfs2
/sbin/tunefs.ocfs2
/sbin/debugfs.ocfs2
/sbin/o2cb_ctl
/sbin/o2cb
/sbin/mount.ocfs2
/sbin/o2image
/sbin/o2cluster
/sbin/ocfs2_hb_ctl
%if %{systemd_enabled}
/sbin/o2cb.init
/sbin/ocfs2.init
/usr/lib/systemd/system/o2cb.service
/usr/lib/systemd/system/ocfs2.service
%else
/etc/init.d/o2cb
/etc/init.d/ocfs2
%endif
/usr/bin/o2info
/usr/sbin/o2hbmonitor
%config(noreplace) /etc/sysconfig/o2cb
/usr/share/man/man8/debugfs.ocfs2.8.gz
/usr/share/man/man8/fsck.ocfs2.8.gz
/usr/share/man/man8/fsck.ocfs2.checks.8.gz
/usr/share/man/man8/mkfs.ocfs2.8.gz
/usr/share/man/man8/tunefs.ocfs2.8.gz
/usr/share/man/man8/mount.ocfs2.8.gz
/usr/share/man/man8/mounted.ocfs2.8.gz
/usr/share/man/man8/o2cb_ctl.8.gz
/usr/share/man/man8/o2cb.8.gz
/usr/share/man/man8/ocfs2_hb_ctl.8.gz
/usr/share/man/man8/o2image.8.gz
/usr/share/man/man7/o2cb.7.gz
/usr/share/man/man1/o2info.1.gz
/usr/share/man/man8/o2hbmonitor.8.gz
/usr/share/man/man5/ocfs2.cluster.conf.5.gz
/usr/share/man/man5/o2cb.sysconfig.5.gz
/usr/share/man/man7/ocfs2.7.gz
/usr/share/man/man8/o2cluster.8.gz


%if %{build_ocfs2console}
%files -n ocfs2console
%defattr(-,root,root)
%{brokenrhlibdir}/python@@PYVERSION@@/site-packages/ocfs2interface
/usr/sbin/ocfs2console
/usr/share/man/man8/ocfs2console.8.gz
%endif

%files -n ocfs2-tools-devel
%defattr(-,root,root)
%{brokenrhlibdir}/*.a
%{brokenrhlibdir}/pkgconfig/*.pc
%{_includedir}/ocfs2-kernel
%{_includedir}/o2cb
%{_includedir}/o2dlm
%{_includedir}/ocfs2



%changelog
* Thu Jun 18 2015 Junxiao Bi <junxiao.bi@oracle.com>
- Add systemd support

* Thu Jan 27 2005 Manish Singh <manish.singh@oracle.com>
- Add ocfs2console

* Fri Jan 21 2005 Manish Singh <manish.singh@oracle.com>
- Initial rpm spec
