File smartmontools.spec of Package smartmontools

#
# 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:        5.42
Release:        0
Source:         %{name}-%{version}.tar.bz2
Source2:        smartmontools.sysconfig
Source3:        %{name}-rpmlintrc
Patch1:         smartmontools-default-enabled.patch
Patch3:         smartmontools-silent-unsupported.patch
Patch4:         smartmontools-removable.patch
# SUSE-FEATURE-PATCH smartmontools-nobuild-date.patch bnc#647521 pgajdos@suse.cz
Patch8:         smartmontools-nobuild-date.patch
# Fix FSF wrong address
Patch9:         COPYING-address.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
PreReq:         coreutils
%if 0%{?suse_version} > 1130
PreReq:         sysvinit(syslog)
%endif
%if 0%{?suse_version} <= 1100
Requires:       powersave
%endif
%{?systemd_requires}
Url:            http://smartmontools.sourceforge.net/
BuildRequires:  gcc-c++
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
%if 0%{?suse_version} >= 1110
BuildRequires:  libselinux-devel
%endif
%if 0%{?suse_version} >= 1130
BuildRequires:  libcap-ng-devel
%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
%setup -q
cp -a %{SOURCE2} .
%patch1
%patch3
%patch4
%patch8 -p1
%patch9
%patch10 -p1
%patch11

%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)"'

%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
mkdir -p %{buildroot}%{_prefix}/lib/smartmontools
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
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

%clean
rm -rf %{buildroot}

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

%post
# Migrate %{_sysconfdir}/default/smartmontools to sysconfig (<=11.0,>=10.2,upstream)
#BEGIN smartd_opts_migrate
# generated by genopts
function optarg_parse()
{
    OPTARG_INTERVAL=false
    OPTARG_LOGFACILITY=false
    until [ $# -eq 0 ]
    do
	case "$1" in
	--interval )
	    shift
	    OPTARG_INTERVAL=true
	    OPTVAL_INTERVAL="$1"
	    ;;
	--interval=* )
	    OPTARG_INTERVAL=true
	    OPTVAL_INTERVAL="${1#--interval=}"
	    ;;
	--logfacility )
	    shift
	    OPTARG_LOGFACILITY=true
	    OPTVAL_LOGFACILITY="$1"
	    ;;
	--logfacility=* )
	    OPTARG_LOGFACILITY=true
	    OPTVAL_LOGFACILITY="${1#--logfacility=}"
	    ;;
	-* )
	    OPTTMP="${1:1}"
	    until [[ -z "$OPTTMP" ]]
	    do
		case "${OPTTMP:0:1}" in
		i )
		    OPTARG_INTERVAL=true
		    OPTVAL_INTERVAL="${OPTTMP:1}"
		    if [[ -z "$OPTVAL_INTERVAL" ]]
		    then
			shift
			OPTVAL_INTERVAL="$1"
		    else
			break
		    fi
		    ;;
		l )
		    OPTARG_LOGFACILITY=true
		    OPTVAL_LOGFACILITY="${OPTTMP:1}"
		    if [[ -z "$OPTVAL_LOGFACILITY" ]]
		    then
			shift
			OPTVAL_LOGFACILITY="$1"
		    else
			break
		    fi
		    ;;
		esac
	    OPTTMP="${OPTTMP:1}"
	    done
	    ;;
	* )
	    ARGV=("${ARGV[@]}" "$1")
	    ;;
	esac
    shift
    done
}
if test -f %{_sysconfdir}/default/smartmontools -a \! -f %{_sysconfdir}/sysconfig/smartmontools ; then
    . %{_sysconfdir}/default/smartmontools
    optarg_parse $smartd_opts
    EXPR=
    if $OPTARG_INTERVAL ; then
	echo "SMARTD_CHECK_INTERVAL=\"$OPTVAL_INTERVAL\"" >>%{_sysconfdir}/sysconfig/smartmontools
	EXPR="s/=\"1800\"/=\"$OPTVAL_INTERVAL\"/;"
    fi
    if $OPTARG_LOGFACILITY ; then
	echo "SMARTD_LOG_FACILITY=\"$OPTVAL_LOGFACILITY\"" >>%{_sysconfdir}/sysconfig/smartmontools
	EXPR="${EXPR}s/=\"daemon\"/=\"$OPTVAL_LOGFACILITY\"/;"
    fi
    sed "$EXPR" </var/adm/fillup-templates/sysconfig.smartmontools >%{_sysconfdir}/sysconfig/smartmontools
    rm %{_sysconfdir}/default/smartmontools
fi
#END smartd_opts_migrate
# Turn smartd on by default.
%{fillup_and_insserv -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*/*
%{_localstatedir}/lib/smartmontools
%if 0%{?suse_version} <= 1100
%{_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