File lpar2rrd.spec of Package lpar2rrd

#
# spec file for package lpar2rrd
#
# 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/
#

%if 0%{?suse_version}
%define        apxs    /usr/sbin/apxs2
%define        http_user wwwrun
%define        http_group  www

%else
%define        apxs    /usr/sbin/apxs
%define        http_user apache
%define        http_group  apache
%endif

%define apache2_sysconfdir %(%{apxs} -q SYSCONFDIR)
# we wanna have it in /usr/lib eventualy not arch dependent lib64
%if 0%{?sles_version} <= 11
%global _libexecdir %_prefix/lib
%endif

Name:           lpar2rrd
Version:        4.01
Release:        0
License:        GPL-3.0+
Summary:        Monitoring system for IBM POWER systems
Url:            http://www.lpar2rrd.com/
Group:          System/Monitoring
Source:         http://prdownloads.sourceforge.net/project/lpar2rrd/lpar2rrd/%{version}/%{name}-%{version}.tar
Source1:        README.SuSE
Source2:        apache2-lpar2rrd.conf
BuildRequires:  ksh
%if 0%{?suse_version}
BuildRequires:  apache2-devel
%else
BuildRequires:  httpd-devel
%endif
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
BuildArch:      noarch

Requires:       rrdtool
Requires(pre):  openssh
%if 0%{?suse_version} > 1130
%{perl_requires}
%else
Requires:       perl = %perl_version
%endif
Requires:       perl-TimeDate
Requires:       perl-Switch

%description
LPAR2RRD tool is able to produce historical and even nearly "real-time" CPU utilization graphs of LPAR's and
shared CPU usage of IBM Power servers. It also collects complete physical (HW) and
logical configuration of all managed systems/LPAR's and all changes in their state and
configuration and graphs network traffic of IVE (HEA) interfaces.

%prep
%setup -q
gunzip lpar2rrd.tar.Z
tar xf lpar2rrd.tar
chmod a-x README
cp %{S:1} .
%build
cat > sed_fix_configuration << EOF
/#!\/bin\/sh/d
s@INPUTDIR=.*@INPUTDIR=%{_libexecdir}/%{name}/@g
s@WEBDIR=.*@WEBDIR=%{_localstatedir}/lib/%{name}/www@g
s@RRDTOOL=.*@RRDTOOL=%{_bindir}/rrdtool@g
s@PERL=.*@PERL=%__perl@g
s@PERL5LIB=.*@PERL5LIB=%perl_vendorlib:%perl_vendorarch:%{_libexecdir}/%{name}/bin@g
s@SSH_WEB_IDENT=.*@SSH_WEB_IDENT=%{_sysconfdir}/%{name}/ssh/realt_dsa@g
s@ERRLOG=.*@ERRLOG=%{_localstatedir}/log/%{name}/error.log@g
EOF

sed -i -f sed_fix_configuration dist/etc/lpar2rrd.cfg
sed -i -e 's@RLOG=.*@RLOG=%{_localstatedir}/log/%{name}/realt-error.log@g' dist/lpar2rrd-cgi/*.sh
sed -i -e '1i#!/usr/bin/perl' dist/bin/*.pl
# workaround stupid check...
sed -i -e 's/^install_user=`ls.*/install_user=lpar2rrd/g' dist/load.sh
sed -i -e 's/^running_user=`ls.*/running_user=lpar2rrd/g' dist/load.sh
# fix upstream bug...
sed -i -e 's@\$INPUTDIR/error.log@\$ERRLOG@g' dist/bin/install-html.sh

%install
# create required folders - directories :)
install -dm0755 %{buildroot}%{_sysconfdir}/%{name}/ssh
install -dm0755 %{buildroot}%{_localstatedir}/lib/%{name}
install -dm0700 %{buildroot}%{_localstatedir}/lib/%{name}/data
install -dm0700 %{buildroot}%{_localstatedir}/lib/%{name}/config
install -dm0700 %{buildroot}%{_localstatedir}/lib/%{name}/tmp
install -dm0755 %{buildroot}%{_localstatedir}/lib/%{name}/www
install -dm0755 %{buildroot}%{_libexecdir}/%{name}/bin
install -dm0755 %{buildroot}%{_libexecdir}/%{name}/html
install -dm0755 %{buildroot}%{_libexecdir}/%{name}/scripts
install -dm0755 %{buildroot}%{_libexecdir}/%{name}/lpar2rrd-cgi
install -dm0700 %{buildroot}%{_localstatedir}/log/%{name}

#install all perl scripts
install -Dm0755 dist/bin/*.pl %{buildroot}%{_libexecdir}/%{name}/bin
install -Dm0644 dist/bin/*.pm %{buildroot}%{_libexecdir}/%{name}/bin
# do same with shell scripts
install -Dm0755 dist/bin/*sh %{buildroot}%{_libexecdir}/%{name}/bin
install -Dm0755 dist/lpar2rrd-cgi/*sh %{buildroot}%{_libexecdir}/%{name}/lpar2rrd-cgi
install -Dm0644 dist/etc/lpar2rrd.cfg %{buildroot}%{_sysconfdir}/%{name}/%{name}.cfg
install -Dm0755 dist/scripts/*.sh %{buildroot}%{_libexecdir}/%{name}/scripts
# copy html and images
install -Dm0644 dist/html/*.html %{buildroot}%{_libexecdir}/%{name}/html
install -Dm0644 dist/html/top.src %{buildroot}%{_libexecdir}/%{name}/html
install -Dm0644 dist/html/*.jpg %{buildroot}%{_libexecdir}/%{name}/html
install -Dm0644 dist/html/*.png %{buildroot}%{_libexecdir}/%{name}/html
# main run scripts
install -Dm0755 dist/load_alert.sh %{buildroot}%{_libexecdir}/%{name}
install -Dm0755 dist/load_hea.sh %{buildroot}%{_libexecdir}/%{name}
install -Dm0755 dist/load.sh %{buildroot}%{_libexecdir}/%{name}
# apache configuration
install -Dm0644 %{SOURCE2} %{buildroot}/%{apache2_sysconfdir}/conf.d/lpar2rrd.conf
#install -Dm0644 dist/etc/rperf_*  %%{buildroot}%%{_sysconfdir}/%%{name}
# save hw_cfg_lpar.sh and hw_cfg_sys.sh as they can be modified if needed
install -Dm0755 dist/bin/*cfg*sh  %{buildroot}%{_sysconfdir}/%{name}

## make private key not readable
touch -r /etc/shadow %{buildroot}%{_sysconfdir}/%{name}/ssh/id_dsa
touch -r /etc/shadow %{buildroot}%{_sysconfdir}/%{name}/ssh/id_dsa.pub
touch -r /etc/shadow %{buildroot}%{_sysconfdir}/%{name}/ssh/realt_dsa
touch -r /etc/shadow %{buildroot}%{_sysconfdir}/%{name}/ssh/known_hosts
touch %{buildroot}%{_localstatedir}/log/%{name}/realt-error.log

(cd %{buildroot}%{_libexecdir}/%{name} ;  ln -s %{_localstatedir}/log/%{name} logs)
(cd %{buildroot}%{_libexecdir}/%{name} ;  ln -s %{_sysconfdir}/%{name} etc)
(cd %{buildroot}%{_libexecdir}/%{name} ;  ln -s %{_localstatedir}/lib/%{name}/data .)
(cd %{buildroot}%{_libexecdir}/%{name} ;  ln -s %{_localstatedir}/lib/%{name}/config .)
(cd %{buildroot}%{_libexecdir}/%{name} ;  ln -s %{_localstatedir}/lib/%{name}/www .)
(cd %{buildroot}%{_libexecdir}/%{name} ;  ln -s %{_localstatedir}/lib/%{name}/tmp .)
(cd %{buildroot}%{_libexecdir}/%{name}/bin ;  ln -sf %{_sysconfdir}/%{name}/hw_cfg_lpar.sh .)
(cd %{buildroot}%{_libexecdir}/%{name}/bin ;  ln -sf %{_sysconfdir}/%{name}/hw_cfg_sys.sh  .)

%if !0%{?suse_version}
# not needed any more but needed for older versions...
%clean
%{?buildroot:rm -rf %{buildroot}}
%endif

%pre
%{_bindir}/getent passwd lpar2rrd >/dev/null || %{_sbindir}/useradd -r -d %{_localstatedir}/lib/lpar2rrd -s /bin/false -c "LPAR2RRD User" -g www lpar2rrd || :

%post
set -x
if [ ! -L %{_localstatedir}/lib/%{name}/.ssh ]; then
	if [ ! -s %{_sysconfdir}/%{name}/ssh/id_dsa ]; then
		ssh-keygen -t dsa -f %{_sysconfdir}/%{name}/ssh/id_dsa -P ""
		chown lpar2rrd:www %{_sysconfdir}/%{name}/ssh/id_dsa*
		cp -a %{_sysconfdir}/%{name}/ssh/id_dsa %{_sysconfdir}/%{name}/ssh/realt_dsa
		chown wwwrun:www %{_sysconfdir}/%{name}/ssh/realt_dsa
		touch %{_localstatedir}/log/%{name}/realt-error.log
		chown wwwrun:www %{_localstatedir}/log/%{name}/realt-error.log
		ln -s %{_sysconfdir}/%{name}/ssh/ %{_localstatedir}/lib/%{name}/.ssh
	else
		mv %{_localstatedir}/lib/%{name}/.ssh %{_sysconfdir}/%{name}/ssh
		ln -s %{_sysconfdir}/%{name}/ssh/ %{_localstatedir}/lib/%{name}/.ssh
	fi
	# Touch it so user can add hosts to it or it will fail every time...
	touch %{_localstatedir}/lib/%{name}/.ssh/known_hosts
	chown lpar2rrd:www %{_sysconfdir}/%{name}/ssh/known_hosts*
fi


%files
%defattr(-,root,root)
%doc README README.SuSE
%dir %attr(0710,lpar2rrd,%{http_group}) %{_localstatedir}/lib/%{name}
%dir %attr(0710,lpar2rrd,%{http_group}) %{_localstatedir}/lib/%{name}/data
%dir %attr(0700,lpar2rrd,%{http_group}) %{_localstatedir}/lib/%{name}/config
%dir %attr(1770,lpar2rrd,%{http_group}) %{_localstatedir}/lib/%{name}/tmp
%dir %attr(0755,lpar2rrd,%{http_group}) %{_localstatedir}/lib/%{name}/www
%dir %{_sysconfdir}/%{name}
%dir %{_sysconfdir}/%{name}/ssh
%config(noreplace) %{_sysconfdir}/%{name}/%{name}.cfg
%config(noreplace) %attr(0644,root,root) %{_sysconfdir}/%{name}/hw_cfg_lpar.sh
%config(noreplace) %attr(0644,root,root) %{_sysconfdir}/%{name}/hw_cfg_sys.sh
%config(noreplace) %attr(0644,root,root) %{_sysconfdir}/%{name}/custom_make_cfg.sh
#%%config(noreplace) %%attr(0644,root,root) %%{_sysconfdir}/%%{name}/rperf_*
%{_libexecdir}/%{name}
# ssh keys  WILL NOT be deleted on removal of package - should think more about this...
%config(noreplace) %ghost %attr(0640,lpar2rrd,%{http_group}) %{_sysconfdir}/%{name}/ssh/id_dsa
%config(noreplace) %ghost %attr(0644,lpar2rrd,%{http_group}) %{_sysconfdir}/%{name}/ssh/id_dsa.pub
%config(noreplace) %ghost %attr(0640,lpar2rrd,%{http_group}) %{_sysconfdir}/%{name}/ssh/known_hosts
%config(noreplace) %ghost %attr(0600,%{http_user},%{http_group}) %{_sysconfdir}/%{name}/ssh/realt_dsa
%ghost %attr(0600,%{http_user},%{http_group}) %{_localstatedir}/log/%{name}/realt-error.log
%attr(0710,lpar2rrd,%{http_group}) %{_localstatedir}/log/%{name}
%config(noreplace) %{apache2_sysconfdir}/conf.d/lpar2rrd.conf
%{_libexecdir}/%{name}/html/*.png
%{_libexecdir}/%{name}/html/*.jpg

%changelog