File smartmontools.spec of Package smartmontools

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

# norootforbuild


Name:           smartmontools
License:        GPLv2+
Group:          Hardware/Other
Version:        5.40
Release:        4
Source:         %{name}-%{version}.tar.bz2
Source2:        smartmontools.sysconfig
Source3:        %{name}-rpmlintrc
Patch:          smartmontools-powersave-notify.patch
Patch1:         smartmontools-default-enabled.patch
Patch2:         smartmontools-lsb-init-script.patch
Patch4:         smartmontools-removable.patch
Patch5:         smartmontools-init-update.patch
Patch6:         smartmontools-sysconfig.patch
Patch7:         smartmontools-strict-aliasing.patch
# SUSE-FEATURE-PATCH smartmontools-nobuild-date.patch bnc#647521 pgajdos@suse.cz
Patch8:         smartmontools-nobuild-date.patch
PreReq:         %insserv_prereq %fillup_prereq coreutils
%if %suse_version > 1130
PreReq:         sysvinit(syslog)
%endif
%if %suse_version <= 1100
Requires:       powersave
%endif
%if %suse_version > 1020
Requires:       licenses
BuildRequires:  licenses
%endif
Url:            http://smartmontools.sourceforge.net/
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
BuildRequires:  gcc-c++
%if %suse_version >= 1110
BuildRequires:  libselinux-devel
%endif
%if %suse_version >= 1130
BuildRequires:  libcap-ng-devel
%endif
Summary:        Monitor for S.M.A.R.T. Disks and Devices

%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.

Authors:
--------
    Bruce Allen <smartmontools-support@lists.sourceforge.net>

%prep
%setup -q
cp -a %{S:2} .
%patch1
%patch2
%patch4
%if %suse_version <= 1100
# Powersave notification was available only in 10.0-11.0 and SLE10.
%patch
%endif
%patch5
%patch6
%patch7
%patch8 -p1

%build
AUTOMAKE=/usr/bin/automake-1.11 ./autogen.sh
export CFLAGS="$RPM_OPT_FLAGS -fPIE"
export CXXFLAGS="$RPM_OPT_FLAGS -fPIE"
export LDFLAGS="-pie"
%configure\
	--with-docdir=%{_defaultdocdir}/%{name}\
%if %suse_version >= 1110
	--with-selinux\
%endif
	--enable-drivedb\
	--enable-savestates\
	--enable-attributelog
make %{?_smp_mflags} BUILD_INFO='"(SUSE RPM)"'

%install
%makeinstall
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/init.d
cp smartd.initd $RPM_BUILD_ROOT%{_sysconfdir}/init.d/smartd
chmod +x $RPM_BUILD_ROOT%{_sysconfdir}/init.d/smartd
ln -s ../..%{_sysconfdir}/init.d/smartd $RPM_BUILD_ROOT%{_sbindir}/rcsmartd
%if %suse_version <= 1100
mkdir -p $RPM_BUILD_ROOT%{_prefix}/lib/smartmontools
cp examplescripts/Example4 $RPM_BUILD_ROOT%{_prefix}/lib/smartmontools/smart-notify
chmod +x $RPM_BUILD_ROOT%{_prefix}/lib/smartmontools/smart-notify
%endif
mkdir -p $RPM_BUILD_ROOT/var/adm/fillup-templates
cp smartmontools.sysconfig $RPM_BUILD_ROOT/var/adm/fillup-templates/sysconfig.smartmontools
mkdir -p $RPM_BUILD_ROOT%{_localstatedir}/lib/smartmontools
#remove installed files we don't want to package
rm -r $RPM_BUILD_ROOT%{_sysconfdir}/rc.d/init.d/
%if %suse_version > 1020
ln -sf %{_datadir}/doc/licenses/md5/$(md5sum COPYING | sed 's/ .*//') $RPM_BUILD_ROOT%{_docdir}/%{name}/COPYING
%endif
cat >$RPM_BUILD_ROOT%{_sysconfdir}/smart_drivedb.h <<EOF
/* smart_drivedb.h: Custom drive database. See also %{_datadir}/smartmontools/drivedb.h. */
EOF

%clean
rm -rf $RPM_BUILD_ROOT

%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}

%preun
%{stop_on_removal smartd}

%postun
%{restart_on_update smartd}
%{insserv_cleanup}

%files
%defattr(-, root, root)
%doc %{_docdir}/%{name}
%{_datadir}/smartmontools
%doc %{_mandir}/man*/*
%{_localstatedir}/lib/smartmontools
%if %suse_version <= 1100
%{_prefix}/lib/smartmontools
%endif
%{_sbindir}/*
%{_sysconfdir}/init.d/*
%config(noreplace) %{_sysconfdir}/smart_drivedb.h
%config(noreplace) %{_sysconfdir}/smartd.conf
/var/adm/fillup-templates/sysconfig.*

%changelog