Name: 		nvme
Version: 	@@VERSION@@
Release: 	1%{?dist}
Summary:  	Core nvme tools
License: 	GPL
Group: 		Development/Tools
URL: 		https://github.com/linux-nvme/nvme-cli/
Source: 	nvme-@@VERSION@@.tar.gz
Provides:	nvme
Requires(post): util-linux
BuildRoot:	%{_tmppath}/%{name}-%{version}-root

%description
NVMe is a fast, scalable, direct attached storage interface. The nvme
cli rpm installs core management tools with minimal dependencies.

%prep
%setup

%build
make

%install
rm -rf $RPM_BUILD_ROOT
make install DESTDIR=%{buildroot} PREFIX=/usr

%files
%defattr(-,root,root)
%doc Documentation/nvme*.1
%{_sbindir}/nvme
%{_mandir}/man1/nvme*.1*
%{_datadir}/bash-completion/completions/nvme
%{_datadir}/zsh/site-functions/_nvme

%clean
rm -rf $RPM_BUILD_ROOT

%post
if [ $1 = 1 ]; then # 1 : This package is being installed for the first time
	if [ ! -f /etc/nvme/hostnqn ]; then
		install -D /dev/null /etc/nvme/hostnqn
		echo $(nvme gen-hostnqn) > /etc/nvme/hostnqn
        fi
        if [ ! -f /etc/nvme/hostid ]; then
                uuidgen > /etc/nvme/hostid
        fi
fi

%preun
if [ "$1" = "remove" ]; then
	if [ -d /etc/nvme ]; then
		rm -f /etc/nvme/hostnqn
		if [ ! -n "`ls -A /etc/nvme`" ]; then
			rm -rf /etc/nvme
		fi
	fi
fi
%changelog
* Mon Oct 15 2018 Eyal Ben-David <eyalbe@il.ibm.com> - 1.6.81.g899a-2
- bash-completion check

* Thu Oct 15 2015 Keith Busch <keith.busch@intel.com>
- Initial RPM spec
