File nbd.spec of Package nbd

# spec file for package nbd
# Copyright (c) 2018 SUSE LINUX 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

#Compat macro for new _fillupdir macro introduced in Nov 2017
%if ! %{defined _fillupdir}
  %define _fillupdir %{_localstatedir}/adm/fillup-templates
Name:           nbd
Version:        3.16.2
Release:        0
Summary:        Network Block Device Server and Client Utilities
License:        GPL-2.0+
Group:          Productivity/Networking/Other
Source1:        %{name}-server.service
Source3:        config.example
Source4:        nbd-server.sysconfig
Source5:        nbd-client.service
BuildRequires:  pkgconfig
BuildRequires:  systemd-rpm-macros
BuildRequires:  pkgconfig(glib-2.0) >= 2.26.0
BuildRequires:  pkgconfig(gnutls)
Requires(pre):  %fillup_prereq
Requires(pre):  coreutils

This package contains nbd-server. It is the server backend for the nbd
network block device driver that's in the Linux kernel.

nbd can be used to have a filesystem stored on another machine. It does
provide a block device, not a file system; so unless you put a
clustering filesystem on top of it, you can't access it simultaneously
from more than one client. Use NFS or a real cluster FS (such as
ocfs2) if you want to do this. nbd-server can export a file (which may
contain a filesystem image) or a partition. Swapping over nbd is
possible as well, though it's said not to be safe against OOM and
should not be used for that case. nbd-server also has a copy-on-write
mode where changes are saved to a separate file and thrown away when
the connection closes.

The package also contains the nbd-client tools, which you need to
configure the nbd devices on the client side.

%setup -q

make %{?_smp_mflags}


# install systemd unit
install -D -p -m 0644  %{SOURCE5} \
install -D -p -m 0644  %{SOURCE1} \
ln -s %{_sbindir}/service %{buildroot}%{_sbindir}/rc%{name}-server

# autoload nbd module
install -d -m 755 %{buildroot}%{_prefix}/lib/modules-load.d/
echo "nbd" > %{buildroot}%{_prefix}/lib/modules-load.d/%{name}.conf

#echo "#Port	file	options" > $RPM_BUILD_ROOT/etc/nbd-server.conf
mkdir -p %{buildroot}%{_sysconfdir}/nbd-server
touch %{buildroot}%{_sysconfdir}/nbd-server/config
touch %{buildroot}%{_sysconfdir}/nbd-server/allow
install -D -p -m 0644 %{SOURCE3} %{buildroot}%{_sysconfdir}/nbd-server/config.example
install -D -p -m 0644 %{SOURCE4} %{buildroot}%{_fillupdir}/sysconfig.%{name}-server

%service_add_post %{name}-server.service
%fillup_only -n nbd-server
if test -e %{_sysconfdir}/nbd-server.conf; then
  # Do we have to create a generic section?
  unset generic
  if test -e %{_sysconfdir}/nbd-server/config; then generic=1; fi
  grep -vE '^(#|[[:blank:]]*$)' %{_sysconfdir}/nbd-server.conf |
  while read port file opts; do
    if test -z "$generic"; then
      echo > %{_sysconfdir}/nbd-server/config
      echo "[generic]" >> %{_sysconfdir}/nbd-server/config
      echo "	# No generic options yet" >> %{_sysconfdir}/nbd-server/config
      echo >> %{_sysconfdir}/nbd-server/config
    echo " ... convert $port $file $opts -> $nm"
    %{_bindir}/nbd-server $port $file $opts -o "$nm" >> %{_sysconfdir}/nbd-server/config
  mv %{_sysconfdir}/nbd-server.conf %{_sysconfdir}/nbd-server.conf.converted

%service_del_postun %{name}-server.service

%service_add_pre %{name}-server.service

%service_del_preun %{name}-server.service

%dir %{_sysconfdir}/nbd-server
%ghost %config(noreplace) %{_sysconfdir}/nbd-server/config
%ghost %config(noreplace) %{_sysconfdir}/nbd-server/allow
%config %{_sysconfdir}/nbd-server/config.example
%dir %{_prefix}/lib/modules-load.d/