File smartmontools.spec of Package smartmontools

#
# spec file for package smartmontools
#
# Copyright (c) 2013 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.2
Release:        0
Source:         http://sourceforge.net/projects/smartmontools/files/smartmontools/%{version}/%{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
# PATCH-FEATURE-UNITEDLINUX smartmontools-default-enabled.patch sbrabec@suse.cz -- Enable smartd by default.
Patch1:         smartmontools-default-enabled.patch
# PATCH-FEATURE-OPENSUSE smartmontools-removable.patch sbrabec@suse.cz -- Skip removable devices. (bnc#308557) Report raw temperature.
Patch4:         smartmontools-removable.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
# PATCH-FEATURE-OPENSUSE smartd-service-novm.patch crrodriguez@opensuse.org -- Do not start smartd in virtual environment.
Patch11:        smartd-service-novm.patch
PreReq:         %fillup_prereq
PreReq:         %insserv_prereq
# Needed by generate_smartd_opt:
PreReq:         coreutils
%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
BuildRequires:  pkgconfig(systemd)
%{?systemd_requires}
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
%patch4
%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 0%{?suse_version} > 1000
export CFLAGS="%{optflags} -fPIE"
export CXXFLAGS="%{optflags} -fPIE"
export LDFLAGS="-pie"
%endif
%configure\
	--with-docdir=%{_defaultdocdir}/%{name}\
%if 0%{?suse_version} >= 1110
        --with-selinux\
%endif
    --with-systemdsystemunitdir=%{_unitdir}\
	--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
%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
cp smartd.service %{buildroot}/%{_unitdir}
# INSTALL file is intended only for packagers.
rm %{buildroot}%{_defaultdocdir}/%{name}/INSTALL

%clean
rm -rf %{buildroot}

%pre 
%service_add_pre smartd.service

%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
# No start by default here.. belongs to -presets packages
%service_add_post smartd.service

%preun
%service_del_preun smartd.service

%postun
%service_del_postun smartd.service

%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
%{_unitdir}/*
%{_sbindir}/*
%config(noreplace) %{_sysconfdir}/smart_drivedb.h
%config(noreplace) %{_sysconfdir}/smartd.conf
%config(noreplace) %{_sysconfdir}/smartd_warning.sh
%{_localstatedir}/adm/fillup-templates/sysconfig.*

%changelog
openSUSE Build Service is sponsored by