File smartmontools.spec of Package smartmontools.1183

#
# spec file for package smartmontools
#
# Copyright (c) 2012 SUSE LINUX Products 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 http://bugs.opensuse.org/
#


Name:           smartmontools
Version:        6.0
Release:        0
Source:         %{name}-%{version}.tar.gz
Source1:        %{name}-%{version}.tar.gz.asc
Source2:        smartmontools.sysconfig
Source3:        %{name}-rpmlintrc
Source4:        %{name}.keyring
Source5:        %{name}.generate_smartd_opts.in
Patch1:         smartmontools-default-enabled.patch
Patch3:         smartmontools-silent-unsupported.patch
Patch4:         smartmontools-removable.patch
# PATCH-FEATURE-OPENSUSE smartmontools-sysconfig.patch sbrabec@suse.cz -- Introduce SMARTD_SAVESTATES and SMARTD_ATTRLOG sysconfig varaibles.
Patch6:         smartmontools-sysconfig.patch
# SUSE-FEATURE-PATCH smartmontools-nobuild-date.patch bnc#647521 pgajdos@suse.cz
Patch8:         smartmontools-nobuild-date.patch
# PATCH-FIX-OPENSUSE smartmontools-var-lock-subsys.patch sbrabec@suse.cz -- Do not use unsupported /var/lock/subsys.
Patch10:        smartmontools-var-lock-subsys.patch
Patch11:        smartd-service-novm.patch
PreReq:         %fillup_prereq
PreReq:         %insserv_prereq
# Needed by generate_smartd_opt:
PreReq:         coreutils
%if 0%{?suse_version} > 1130
%if 0%{?suse_version} < 1230
PreReq:         sysvinit(syslog)
%endif
%endif
%if 0%{?suse_version} <= 1100
Requires:       powersave
%endif
Url:            http://smartmontools.sourceforge.net/
BuildRequires:  gcc-c++
%if 0%{?suse_version} > 1220
BuildRequires:  gpg-offline
%endif
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
%if 0%{?suse_version} >= 1110
BuildRequires:  libselinux-devel
%endif
%if 0%{?suse_version} >= 1130
BuildRequires:  libcap-ng-devel
%endif
%if 0%{?suse_version} > 1140
BuildRequires:  systemd
%{?systemd_requires}
%endif
Summary:        Monitor for SMART devices
License:        GPL-2.0+
Group:          Hardware/Other

%description
SMARTmontools controls and monitors storage devices using the
Self-Monitoring, Analysis, and Reporting Technology System (S.M.A.R.T.)
built into ATA, SATA and SCSI Hard Drives. This is used to check the
hard drive reliability and to predict drive failures. The suite
contains two utilities. The first, smartctl, is a command line utility
designed to perform simple S.M.A.R.T. tasks. The second, smartd, is a
daemon that periodically monitors the smart status and reports errors
to syslog. The package is compatible with the ATA/ATAPI-3 to -7
specification. The package is intended to incorporate as much "vendor
specific" and "reserved" information as possible about disk drives. The
commands man smartctl and man smartd will provide more information.

%prep
%if 0%{?gpg_verify:1}
%gpg_verify %{S:1}
%endif
%setup -q
cp -a %{SOURCE2} %{SOURCE5} .
%patch1
%patch3
%patch4
%patch6
%patch8 -p1
%patch10 -p1
%patch11
# PATCH-FEATURE-OPENSUSE (sed on smartd.service.in) sbrabec@suse.cz -- Use generated smartd_opts (from SUSE sysconfig file). Systemd smartd.service cannot be smart enough to parse SUSE sysconfig file and generate smartd_opts on fly. And we do not want to launch shell just for it in every boot.
sed -i "s:/usr/local/etc/sysconfig/smartmontools:%{_localstatedir}/lib/smartmontools/smartd_opts:" smartd.service.in

%build
%if %suse_version > 1000
export CFLAGS="%{optflags} -fPIE"
export CXXFLAGS="%{optflags} -fPIE"
export LDFLAGS="-pie"
%endif
%configure\
	--with-docdir=%{_defaultdocdir}/%{name}\
%if %suse_version >= 1110
        --with-selinux\
%endif
%if 0%{?suse_version} >= 1210
    --with-systemdsystemunitdir=%{_unitdir}\
%endif
	--with-initscriptdir\
	--enable-drivedb\
	--enable-savestates\
	--enable-attributelog
make %{?_smp_mflags} BUILD_INFO='"(SUSE RPM)"'
sed "s:@libdir@:%{_libdir}:g;s:@localstatedir@:%{_localstatedir}:g" <smartmontools.generate_smartd_opts.in >generate_smartd_opts

%install
%makeinstall
mkdir -p %{buildroot}%{_sysconfdir}/init.d
cp smartd.initd %{buildroot}%{_sysconfdir}/init.d/smartd
chmod +x %{buildroot}%{_sysconfdir}/init.d/smartd
ln -s ../..%{_sysconfdir}/init.d/smartd %{buildroot}%{_sbindir}/rcsmartd
%if 0%{?suse_version} <= 1100 || 0%{?suse_version} > 1140
mkdir -p %{buildroot}%{_prefix}/lib/smartmontools
%endif
%if 0%{?suse_version} <= 1100
cp examplescripts/Example4 %{buildroot}%{_prefix}/lib/smartmontools/smart-notify
chmod +x %{buildroot}%{_prefix}/lib/smartmontools/smart-notify
%endif
mkdir -p %{buildroot}%{_localstatedir}/adm/fillup-templates
cp smartmontools.sysconfig %{buildroot}%{_localstatedir}/adm/fillup-templates/sysconfig.smartmontools
mkdir -p %{buildroot}%{_localstatedir}/lib/smartmontools
%if 0%{?suse_version} > 1140
touch %{buildroot}%{_localstatedir}/lib/smartmontools/smartd_opts
install generate_smartd_opts %{buildroot}%{_prefix}/lib/smartmontools/
%endif
cat >%{buildroot}%{_sysconfdir}/smart_drivedb.h <<EOF
/* smart_drivedb.h: Custom drive database. See also %{_datadir}/smartmontools/drivedb.h. */
EOF
%if 0%{?suse_version} >= 1210
	cp smartd.service %{buildroot}/%{_unitdir}
%endif
# INSTALL file is intended only for packagers.
rm %{buildroot}%{_defaultdocdir}/%{name}/INSTALL

%clean
rm -rf %{buildroot}

%pre
%if 0%{?suse_version} >= 1210
	%service_add_pre smartd.service
%endif

%post
# First prepare sysconfig.
%{fillup_only}

%if 0%{?suse_version} > 1140
# Then generate initial %{_localstatedir}/lib/smartmontools/smartd_opts needed by smartd.service.
SMARTD_SKIP_INIT=1 %{_prefix}/lib/smartmontools/generate_smartd_opts
%endif

# Turn smartd on by default.
%{fillup_and_insserv -f -y smartd}

%if 0%{?suse_version} >= 1210
	#systemd
	%service_add_post smartd.service
%endif

%preun
%{stop_on_removal smartd}
%if 0%{?suse_version} >= 1210
	%service_del_preun smartd.service
%endif

%postun
%{restart_on_update smartd}
%{insserv_cleanup}

%if 0%{?suse_version} >= 1210
	%service_del_postun smartd.service
%endif

%files
%defattr(-, root, root)
%doc %{_docdir}/%{name}
%{_datadir}/smartmontools
%doc %{_mandir}/man*/*
%dir %{_localstatedir}/lib/smartmontools
%if 0%{?suse_version} > 1140
%ghost %{_localstatedir}/lib/smartmontools/smartd_opts
%endif
%if 0%{?suse_version} <= 1100 || 0%{?suse_version} > 1140
%{_prefix}/lib/smartmontools
%endif
%if 0%{?suse_version} >= 1210
%{_unitdir}/*
%endif
%{_sbindir}/*
%{_sysconfdir}/init.d/*
%config(noreplace) %{_sysconfdir}/smart_drivedb.h
%config(noreplace) %{_sysconfdir}/smartd.conf
%{_localstatedir}/adm/fillup-templates/sysconfig.*

%changelog
openSUSE Build Service is sponsored by