File smartmontools.spec of Package smartmontools

# spec file for package smartmontools
# Copyright (c) 2017 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

Name:           smartmontools
Version:        6.5
Release:        0
Source2:        smartmontools.sysconfig
Source3:        %{name}-rpmlintrc
Source4:        %{name}.keyring
# SOURCE-FEATURE-OPENSUSE -- sysconfig support for systemd.
Source5:        %{name}
# SOURCE-FEATURE-SLE bnc851276 -- Supplementary script to update drivedb.h.
# SOURCE-FEATURE-UPSTREAM smartmontools-drivedb.h bnc851276 -- Update of drivedb.h. (Following line is handled by
Source7:        smartmontools-drivedb.h
# PATCH-FEATURE-OPENSUSE smartmontools-suse-default.patch -- Define smart SUSE defaults.
Patch4:         smartmontools-suse-default.patch
# PATCH-FIX-OPENSUSE smartmontools-var-lock-subsys.patch -- Do not use unsupported /var/lock/subsys.
Patch10:        smartmontools-var-lock-subsys.patch
# PATCH-FEATURE-OPENSUSE smartd-service-novm.patch -- Do not start smartd in virtual environment.
Patch11:        smartd-service-novm.patch
# PATCH-FIX-OPENSUSE smartmontools-systemd-no-syslog.patch bsc983938 -- does not exist any more.
Patch12:        smartmontools-systemd-no-syslog.patch
# PATCH-FIX-UPSTREAM smartmontools-scsi-suppress-no-temperature.patch bsc1047198 -- Always suppress "failed to read Temperature" message.
Patch13:        smartmontools-scsi-suppress-no-temperature.patch
# PATCH-FIX-UPSTREAM smartmontools-scsi-temperature-check.patch bsc1047198 -- Fix initial check for SCSI temperature support.
Patch14:        smartmontools-scsi-temperature-check.patch
# PATCH-FIX-UPSTREAM smartmontools-log-scsi-temperature.patch bsc1047198 -- Log SCSI temperature regardless of its origin.
Patch15:        smartmontools-log-scsi-temperature.patch
Requires(pre):  %fillup_prereq
# Needed by generate_smartd_opt:
Requires(pre):  coreutils
BuildRequires:  gcc-c++
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
BuildRequires:  libcap-ng-devel
BuildRequires:  libselinux-devel
BuildRequires:  pkgconfig(systemd)
Summary:        Monitor for SMART devices
License:        GPL-2.0+
Group:          Hardware/Other

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.

%setup -q
cp -a %{SOURCE2} %{SOURCE5} .
# Following line is handled by
cp -a %{SOURCE7}
%patch10 -p1
%patch12 -p1
%patch13 -p1
%patch14 -p1
%patch15 -p1
# PATCH-FEATURE-OPENSUSE (sed on -- 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 "s:/usr/local/etc/sysconfig/smartmontools:%{_localstatedir}/lib/smartmontools/smartd_opts:" < >
if cmp -s ; then
	echo "Failed to modify"
	exit 1
# Check whether drivedb.h from the tarball is older than
# If yes, replace it. If not, fail.
# PACKAGERS: Don't delete this section. It prevents packaging of outdated smartmontools-drivedb.h.
if test -f ; then
	UPD_TIME=$(date -d "$(sed -n 's/^.*$Id: drivedb.h [0-9][0-9]* \([^ ]* [^ ]*\) .*$/\1/p' <" +%s)
	PCK_TIME=$(date -d "$(sed -n 's/^.*$Id: drivedb.h [0-9][0-9]* \([^ ]* [^ ]*\) .*$/\1/p' <drivedb.h)" +%s)
	if test $UPD_TIME -lt $PCK_TIME ; then
		echo >&2 "Packaging error: Attached smartmontools-drivedb.h is older than the one from the release.
		  Please call \"bash ./\" to fix it."
		exit 1
	mv drivedb.h

export CFLAGS="%{optflags} $(getconf LFS_CFLAGS) -fPIE"
export CXXFLAGS="%{optflags} -fPIE $(getconf LFS_CFLAGS)"
export LDFLAGS="-pie"
    --with-savestates \
    --with-attributelog \

make %{?_smp_mflags} BUILD_INFO='"(SUSE RPM)"'
sed "s:@prefix@:%{_prefix}:g;s:@localstatedir@:%{_localstatedir}:g;s:@SERVICE@:$SERVICE:" < >generate_smartd_opts

mkdir -p %{buildroot}%{_prefix}/lib/smartmontools
mkdir -p %{buildroot}%{_localstatedir}/adm/fillup-templates
cp smartmontools.sysconfig %{buildroot}%{_localstatedir}/adm/fillup-templates/sysconfig.smartmontools
mkdir -p %{buildroot}%{_localstatedir}/lib/smartmontools
touch %{buildroot}%{_localstatedir}/lib/smartmontools/smartd_opts
install generate_smartd_opts %{buildroot}%{_prefix}/lib/smartmontools/
cat >%{buildroot}%{_sysconfdir}/smart_drivedb.h <<EOF
/* smart_drivedb.h: Custom drive database. See also %{_datadir}/smartmontools/drivedb.h. */
cp smartd.service %{buildroot}/%{_unitdir}
ln -sf %{_sbindir}/service  %{buildroot}%{_sbindir}/rcsmartd
# INSTALL file is intended only for packagers.
rm %{buildroot}%{_defaultdocdir}/%{name}/INSTALL
# Create empty ghost files for files created by update-smart-drivedb.
touch %{buildroot}%{_datadir}/smartmontools/drivedb.h.{error,lastcheck,old}

# Check syntax of drivedb.h that may come from a later snapshot (code from update-smart-drivedb)
if ./smartctl -B drivedb.h -P showall >/dev/null; then :; else
  echo "drivedb.h.error: rejected by smartctl, probably no longer compatible" >&2
  exit 1
# Intelligent drivedb.h update, part 0.
# Check that drivedb.h has well formed svn RELEASE. We will need it for the intelligent update.
DRIVEDB_H_RELEASE_CHECK="$(sed -n 's/^.*$Id: drivedb.h \([0-9][0-9]*\) .*$/\1/p' <%{buildroot}%{_datadir}/smartmontools/drivedb.h)"
# Fail if the file has broken release number.
# Fail if there is no BRANCH= in update-smart-drivedb
grep -q "^BRANCH=\"[^\"]*\"$" update-smart-drivedb

%service_add_pre smartd.service
# Intelligent drivedb.h update, part 1.
# Extract drivedb.h branch for installed version. We will need it in %%post.
if test -f %{_sbindir}/update-smart-drivedb ; then
    eval $(grep "^BRANCH=\"[^\"]*\"$" /usr/sbin/update-smart-drivedb)
    if test -n "$BRANCH" ; then
	echo -n "$BRANCH" >%{_datadir}/smartmontools/drivedb.h.branch.rpmtemp
# Save installed drivedb.h. Maybe the sysadmin called update-smart-drivedb,
# and the installed drivedb.h may be even newer than the new packaged one.
if test -f %{_datadir}/smartmontools/drivedb.h ; then
    # Be on safe side, remove any potential drivedb.h.rpmsave.
    rm -f %{_datadir}/smartmontools/drivedb.h.rpmsave
    ln %{_datadir}/smartmontools/drivedb.h %{_datadir}/smartmontools/drivedb.h.rpmsave

# First prepare sysconfig.
# Then generate initial %%{_localstatedir}/lib/smartmontools/smartd_opts needed by smartd.service.
SMARTD_SKIP_INIT=1 %{_prefix}/lib/smartmontools/generate_smartd_opts
# No start by default here.. belongs to -presets packages
%service_add_post smartd.service
# Intelligent drivedb.h update, part 2.
# Now we have the old system drivedb.h.rpmsave and the new packaged drivedb.h.
if test -f %{_datadir}/smartmontools/drivedb.h.rpmsave ; then
    # Compare their release numbers.
    DRIVEDB_H_RELEASE_RPM="$(sed -n 's/^.*$Id: drivedb.h \([0-9][0-9]*\) .*$/\1/p' <%{_datadir}/smartmontools/drivedb.h)"
    DRIVEDB_H_RELEASE_SAVED="$(sed -n 's/^.*$Id: drivedb.h \([0-9][0-9]*\) .*$/\1/p' <%{_datadir}/smartmontools/drivedb.h.rpmsave)"
    # Note: The SAVED release number may be broken. The test syntax must cover it and replace old file.
	# If it is an update to the new branch, always replace the database.
	# Extract drivedb.h branch for the new version to BRANCH.
	eval $(grep "^BRANCH=\"[^\"]*\"$" /usr/sbin/update-smart-drivedb)
	if test -f %{_datadir}/smartmontools/drivedb.h.branch.rpmtemp ; then
	if test "$BRANCH" = "$OLD_BRANCH" ; then
	    # It is safe to keep later version of installed database.
	    mv %{_datadir}/smartmontools/drivedb.h.rpmsave %{_datadir}/smartmontools/drivedb.h
	    # Saved file needs to be replaced.
	    rm %{_datadir}/smartmontools/drivedb.h.rpmsave
	    # We returned to the vanilla packages, remove files created by update-smart-drivedb.
	    rm -f %{_datadir}/smartmontools/drivedb.h.{error,lastcheck,old}
	    echo >&2 "%{name} updated to a version that requires new branch of drivedb.h"
	    echo >&2 "Replacing your custom drivedb.h."
	    echo >&2 "You may need to call update-smart-drivedb."
	# Saved file is older or equal, or saved file has broken release number.
	rm %{_datadir}/smartmontools/drivedb.h.rpmsave
	# We returned to the vanilla packages, remove files created by update-smart-drivedb.
	rm -f %{_datadir}/smartmontools/drivedb.h.{error,lastcheck,old}
rm -f %{_datadir}/smartmontools/drivedb.h.branch.rpmtemp

%service_del_preun smartd.service

%service_del_postun smartd.service
# Clean all attrlogs and state files.
if test "$1" = 0 ; then
    rm -rf %{_localstatedir}/lib/smartmontools

%defattr(-, root, root)
%doc %{_docdir}/%{name}
%dir %{_datadir}/smartmontools
%verify(not md5 size mtime) %{_datadir}/smartmontools/drivedb.h
%ghost %{_datadir}/smartmontools/drivedb.h.error
%ghost %{_datadir}/smartmontools/drivedb.h.lastcheck
%ghost %{_datadir}/smartmontools/drivedb.h.old
%doc %{_mandir}/man*/*
%dir %{_localstatedir}/lib/smartmontools
%ghost %{_localstatedir}/lib/smartmontools/smartd_opts
%config(noreplace) %{_sysconfdir}/smart_drivedb.h
%config(noreplace) %{_sysconfdir}/smartd.conf
%config(noreplace) %{_sysconfdir}/
%config %dir %{_sysconfdir}/smartd_warning.d