#
# spec file for package Big Sister
#
# Copyright (c) 2002 Thomas Aeby, Switzerland
# This file and all modifications and additions to the pristine
# package are under the same license as the package itself.
#

%define		INITDIR 	@INIT_DIR@
Name:         bigsister
Version:      @BIGSISTER_VERSION@
Release:      @PACKAGE_RELEASE@
Copyright:	1997-2002 Thomas Aeby, Switzerland
Group:        util
Url:		http://bigsister.graeff.com/
Provides:	bigsister
Summary:      Big Sister Network and System Monitor
Source:		%{name}-%{version}.tar.bz2
%define		MyRoot	 	%{_tmppath}/%{name}-%{version}-build
BuildRoot:    %{MyRoot}
BuildArchitectures: noarch

%description
Big Sister is a network and system monitor. 

%package server
Summary:      Big Sister Display Server
Autoreqprov:	on
Group:        util
Requires:	bigsister = %{version}

%package agent
Summary: Big Sister agent
Autoreqprov:	on
Group: util
Requires:	bigsister = %{version}

%prep
%setup

%build
id bigsis 2>/dev/null >/dev/null || useradd -d /var/lib/bigsister -s /bin/sh -r bigsis
./configure --enable-fhs --with-user=bigsis --with-cgi=/bigsis/cgi --with-url=/bigsis
make

%install
[ "$RPM_BUILD_ROOT" != "/" ] && [ -d $RPM_BUILD_ROOT ] && rm -rf $RPM_BUILD_ROOT
make install DESTDIR=`[ "$RPM_BUILD_ROOT" != "/" ] && echo -n "$RPM_BUILD_ROOT"`
mv "$RPM_BUILD_ROOT/usr/share/bigsister/etc/moduleinfo/files" "$RPM_BUILD_ROOT/usr/share/bigsister/etc/moduleinfo/files.new"
find "$RPM_BUILD_ROOT/etc/bigsister" "$RPM_BUILD_ROOT/usr/share/bigsister" -user bigsis | xargs chown root

files="$RPM_BUILD_ROOT/etclist"
cat /dev/null > $files
echo "%dir /etc/bigsister" > $files
for f in "$RPM_BUILD_ROOT"/etc/bigsister/*; do
    f=`basename "$f"`
    # it seems %config does time stamp tests - which is a bad idea
    touch -t 200001010100 $RPM_BUILD_ROOT/etc/bigsister/$f
    test "$f" = "uxmon-net" && continue
    test "$f" = "bb-display.cfg" && continue
    echo "%config /etc/bigsister/$f" >>$files
done

case "@DOC_DIR@" in
    /usr/share/bigsister/*)
    	;;
    *)
        echo "@DOC_DIR@" >> $files
	;;
esac

case "@MAN_DIR@" in
    "")
	;;
    /usr/share/bigsister/*)
	;;
    *)
	echo "@MAN_DIR@/*/bs::*" >> $files
	;;
esac

%description server
The Big Sister display server.

%description agent
The Big Sister data collection agent.

%post
PATH=/sbin:/usr/sbin:${PATH}
export PATH
id bigsis 2>/dev/null >/dev/null || useradd -d /var/lib/bigsister -s /bin/sh -r bigsis
if chkconfig >/dev/null 2>&1 ; then
    /sbin/chkconfig --add bigsister
    /sbin/chkconfig bigsister on
else
    ln -sf ${INITDIR}/bigsister /etc/rc.d/rc2.d/S98bigsis
    ln -sf ${INITDIR}/bigsister /etc/rc.d/rc2.d/K98bigsis
fi
chown -R bigsis /var/lib/bigsister /etc/bigsister

# join moduleinfo/files database
modinfo=/usr/share/bigsister/etc/moduleinfo/files
[ -f $modinfo ] || cat /dev/null > $modinfo
cat $modinfo $modinfo.new | sort -u > /tmp/modinfo.$$
cp /tmp/modinfo.$$ $modinfo
rm -f $modinfo.new

%post server
rm -f /var/lib/bigsister/www/graphs/*.html || true

# search for apache config
htconf=""
for dir in /etc/httpd /etc/httpd/conf /etc/apache /etc/apache/conf; do
    if [ -f "$dir/httpd.conf" ]; then
        htconf=$dir/httpd.conf
    fi
done
if [ "$htconf" != "" ]; then
    # patching httpd.conf
    line="Include /etc/bigsister/httpd.conf"
    if grep "^$line" $htconf > /dev/null 2>&1; then
        :
    else
        echo "$line" >> $htconf
    fi
fi

%preun server
# search for apache config
htconf=""
for dir in /etc/httpd /etc/httpd/conf /etc/apache /etc/apache/conf; do
    if [ -f "$dir/httpd.conf" ]; then
        htconf=$dir/httpd.conf
    fi
done
if [ "$htconf" != "" ]; then
    # patching httpd.conf
    line="Include /etc/bigsister/httpd.conf"
    if grep "^$line" $htconf > /dev/null 2>&1; then
        if cp -p $htconf $htconf.$$ \
	    && grep -v "^$line" $htconf > $htconf.$$ \
  	    && mv $htconf.$$ $htconf; then
	        :
	else
	    rm -f $htconf.$$
	fi
    fi
fi


%post agent

%files -f %{MyRoot}/etclist
/usr/share/bigsister
/var/lib/bigsister
%{INITDIR}/bigsister
%docdir @DOC_DIR@
/usr/sbin/bsmodule
/usr/sbin/bsadmin

%files server
%config /etc/bigsister/bb-display.cfg
@crondir@/bigsister_logs

%files agent
%config /etc/bigsister/uxmon-net

