File ppc64-diag.spec of Package ppc64-diag

#
# spec file for package ppc64-diag
#
# Copyright (c) 2016 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 http://bugs.opensuse.org/
#


Url:            http://sourceforge.net/projects/linux-diag/files/ppc64-diag
Name:           ppc64-diag
Version:        2.7.1
Release:        0
Summary:        Linux for Power Platform Diagnostics
License:        GPL-2.0+
Group:          System/Monitoring
ExclusiveArch:  ppc ppc64 ppc64le
%if 0%{?suse_version} >= 1210
BuildRequires:  systemd-rpm-macros
%{?systemd_requires}
%define has_systemd 1
%endif
BuildRequires:  bison
BuildRequires:  flex
BuildRequires:  gcc-c++
BuildRequires:  librtas-devel
BuildRequires:  libservicelog-devel
BuildRequires:  libudev-devel
BuildRequires:  libvpd2-devel
BuildRequires:  ncurses-devel
BuildRequires:  sqlite3-devel
Requires:       lsvpd
Requires:       powerpc-utils >= 1.2.15
Requires:       servicelog
# autoselect the package on systems which have the /vdevice/IBM,sp node
# All pSeries POWER5 and later have this property
Supplements:    modalias(vio:TIBM*spS*)
PreReq:         %insserv_prereq
PreReq:         aaa_base
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
Source0:        http://downloads.sourceforge.net/project/linux-diag/ppc64-diag/v%{version}/%{name}-%{version}.tar.gz
#PATCH-FIX-OPENSUSE - ppc64-diag.rtas_errd.patch - fix rtas_errd initscript to comply with openSUSE standards
Patch1:         %{name}.rtas_errd.patch
#PATCH-FIX-OPENSUSE - ppc64-diag.varunused.patch - fix unused variables
Patch2:         %{name}.varunused.patch
#PATCH-FIX-OPENSUSE - ppc64-diag.opal_errd.patch - fix opal_errd initscript to comply with openSUSE standards
Patch3:         %{name}.opal_errd.patch

%description
This package contains various diagnostic tools for PowerLinux.
These tools captures the diagnostic events from Power Systems
platform firmware, SES enclosures and device drivers, and
write events to servicelog database. It also provides automated
responses to urgent events such as environmental conditions and
predictive failures, if appropriate modifies the FRUs fault
indicator(s) and provides event notification to system
administrators or connected service frameworks.

Authors:
--------
    IBM Corporation

%prep
%setup -q
%patch1 -p1
%patch2 -p1
%patch3 -p1

%build
%if 0%{?has_systemd}
  sed -i '/LIBEXEC_DIR/c\LIBEXEC_DIR = \%{_libexecdir}' rules.mk
  sed -i 's@/usr/libexec/ppc64-diag@%{_libexecdir}@g' scripts/opal_errd.service
  sed -i 's@/usr/libexec/ppc64-diag@%{_libexecdir}@g' scripts/rtas_errd.service
%else
  sed -i '/LIBEXEC_DIR/c\LIBEXEC_DIR = \%{_initddir}' rules.mk
%endif
make

%install
make install DESTDIR=$RPM_BUILD_ROOT
chmod 644 $RPM_BUILD_ROOT/etc/ppc64-diag/servevent_parse.pl
mkdir $RPM_BUILD_ROOT/etc/ppc64-diag/ses_pages
ln -sf /usr/sbin/usysattn $RPM_BUILD_ROOT/usr/sbin/usysfault
%if 0%{?has_systemd}
  mkdir -p $RPM_BUILD_ROOT/%{_unitdir}
  install -D -m0644 scripts/rtas_errd.service %{buildroot}%{_unitdir}/
  install -D -m0644 scripts/opal_errd.service %{buildroot}%{_unitdir}/
  ln -s /sbin/service %{buildroot}/usr/sbin/rcrtas_errd
  ln -s /sbin/service %{buildroot}/usr/sbin/rcopal_errd
%else
  pushd $RPM_BUILD_ROOT/etc/init.d
  ln -s rtas_errd $RPM_BUILD_ROOT/usr/sbin/rcrtas_errd
  ln -s opal_errd $RPM_BUILD_ROOT/usr/sbin/rcopal_errd
  popd
%endif

%files
%defattr (-,root,root,-)
%doc %attr(644,root,root) COPYING
/usr/sbin/*
%dir /etc/ppc64-diag
%config /etc/ppc64-diag/*
%config /etc/rc.powerfail
%{_mandir}/man8/explain_syslog.8.gz
%{_mandir}/man8/syslog_to_svclog.8.gz
%{_mandir}/man8/diag_encl.8.gz
%{_mandir}/man8/encl_led.8.gz
%{_mandir}/man8/lp_diag.8.gz
%{_mandir}/man8/usysattn.8.gz
%{_mandir}/man8/usysfault.8.gz
%{_mandir}/man8/usysident.8.gz
%{_mandir}/man8/opal-dump-parse.8.gz
%{_mandir}/man8/opal-elog-parse.8.gz
%{_mandir}/man8/opal_errd.8.gz

%if 0%{?has_systemd}
  %{_unitdir}/rtas_errd.service
  %{_unitdir}/opal_errd.service
  %{_libexecdir}/rtas_errd
  %{_libexecdir}/opal_errd
%else
  %config %attr(755,root,root) %{_initddir}/rtas_errd
  %config %attr(755,root,root) %{_initddir}/opal_errd
%endif

%if 1

%post
%if 0%{?has_systemd}
  %service_add_post rtas_errd.service opal_errd.service
%else
  %{insserv_force_if_yast rtas_errd}
  %{insserv_force_if_yast opal_errd}
  # get it going if outside a chroot
  if test -f /proc/1/exe -a -d /proc/1/root; then
    if test "$(stat -Lc '%%D-%%i' /)" = "$(stat -Lc '%%D-%%i' /proc/1/root)"; then
      rcrtas_errd start || :
      rcopal_errd start || :
    fi
  fi
%endif

%preun
if test "$1" = "0" ; then
   test -f /var/cache/ppc64-diag.registered && rmdir -v /var/cache/ppc64-diag.registered || :
fi
%if 0%{?has_systemd}
  %service_del_preun rtas_errd.service opal_errd.service
%else
  %stop_on_removal rtas_errd
  %stop_on_removal opal_errd
%endif

%postun
%if 0%{?has_systemd}
  %service_del_postun rtas_errd.service opal_errd.service
%else
  %restart_on_update rtas_errd
  %insserv_cleanup rtas_errd
  %restart_on_update opal_errd
  %insserv_cleanup opal_errd
%endif

%pre
%if 0%{?has_systemd}
  %service_add_pre rtas_errd.service opal_errd.service
%endif

%else

%post
# Post-install script --------------------------------------------------
/etc/ppc64-diag/ppc64_diag_setup --register >/dev/null
/etc/ppc64-diag/lp_diag_setup --register >/dev/null
if [ "$1" = "1" ]; then # first install
    %if 0%{?has_systemd}
      %service_add_post rtas_errd.service
      %service_add_post opal_errd.service
    %else
      chkconfig --add rtas_errd
      rcrtas_errd start
      chkconfig --add opal_errd
      rcopal_errd start
    %endif
elif [ "$1" = "2" ]; then # upgrade
    %if 0%{?has_systemd}
      systemctl restart rtas_errd.service
      systemctl restart opal_errd.service
    %else
      rcrtas_errd restart
      rcopal_errd restart
    %endif
fi

%preun
# Pre-uninstall script -------------------------------------------------
if [ "$1" = "0" ]; then # last uninstall
    %if 0%{?has_systemd}
      %service_del_preun rtas_errd.service
      %service_del_preun opal_errd.service
    %else
      rcrtas_errd stop
      chkconfig --del rtas_errd
      rcopal_errd stop
      chkconfig --del opal_errd
    %endif
    /etc/ppc64-diag/ppc64_diag_setup --unregister >/dev/null
    /etc/ppc64-diag/lp_diag_setup --unregister >/dev/null
fi

%triggerin -- librtas
# trigger on librtas upgrades ------------------------------------------
if [ "$2" = "2" ]; then
    %if 0%{?has_systemd}
      systemctl restart rtas_errd.service
      systemctl restart opal_errd.service
    %else
      rcrtas_errd restart
      rcopal_errd restart
    %endif
fi

%postun
%if 0%{?has_systemd}
  %service_del_postun rtas_errd.service
  %service_del_postun opal_errd.service
%endif

%pre
%if 0%{?has_systemd}
  %service_add_pre rtas_errd.service
  %service_add_pre opal_errd.service
%endif
%endif

%changelog
openSUSE Build Service is sponsored by