%define tiarra tiarra
%define tiarra_confdir %{_sysconfdir}/%{tiarra}
%define tiarra_logdir %{_localstatedir}/log/%{tiarra}
Summary: Tiarra - IRC Proxy software
Summary(ja): Tiarra - IRC 用中継/クライアントプログラム
Name: %{tiarra}
Version: 20100212
Release: 6%{?_dist_release}
URL: http://www.clovery.jp/%{tiarra}/
Source0: http://www.clovery.jp/tiarra/archive/2010/02/%{tiarra}-%{version}.tar.bz2
Source1: %{tiarra}-vine.conf
Source2: %{tiarra}-init.sh
Patch0: %{tiarra}-%{version}-vine.patch
License: GPL+ or Artistic
Group: Applications/Services
Requires: perl >= 5.6.0
Requires(pre): shadow-utils
Requires(post): chkconfig
Requires(preun): chkconfig
Requires(postun): shadow-utils
BuildArch: noarch
Autoreq: no
BuildRoot: %{_tmppath}/%{name}-%{version}-root
Vendor: Project Vine
Distribution: Vine Linux
Packager: miyabi owa

%description
Tiarra is pure-perl irc proxy(or bot) software, with single-thread,
multi-io, object-oriented framework.

%prep
%setup -q -n %{name}-%{version}
%patch0 -p1
cp %{SOURCE1} .

%build

%install
[ "${RPM_BUILD_ROOT}" != "/" ] && rm -rf ${RPM_BUILD_ROOT}
mkdir -p ${RPM_BUILD_ROOT}%{_bindir}
mkdir -p ${RPM_BUILD_ROOT}%{_datadir}/%{name}
install -m 755 %{name} ${RPM_BUILD_ROOT}%{_bindir}/%{name}
cp -af bundle main module  ${RPM_BUILD_ROOT}%{_datadir}/%{name}

mkdir -p ${RPM_BUILD_ROOT}%{_sysconfdir}/%{name}
install -m 644 %{SOURCE1} ${RPM_BUILD_ROOT}%{_sysconfdir}/%{name}/%{name}-vine-sample.conf
mkdir -p ${RPM_BUILD_ROOT}%{_initdir}
install -m 755 %{SOURCE2} ${RPM_BUILD_ROOT}%{_initdir}/%{name}
mkdir -p ${RPM_BUILD_ROOT}%{tiarra_logdir}


%clean
[ "${RPM_BUILD_ROOT}" != "/" ] && rm -rf ${RPM_BUILD_ROOT}

%pre
if [ $1 -ge 1 ]; then
  grep "%{name}:" /etc/group > /dev/null 2>&1
  if [ $? == 1 ]; then
    /usr/sbin/useradd -c "Tiarra IRC Proxy" -M -r -d / -s /sbin/nologin -U %{name}
  fi
  grep "%{name}:" /etc/passwd > /dev/null 2>&1
  if [ $? == 1 ]; then
    /usr/sbin/useradd -c "Tiarra IRC Proxy" -M -r -d / -s /sbin/nologin %{name}
  fi
  if [ -d %{tiarra_logdir} ]; then
    ls -ld %{tiarra_logdir} | grep root
    if [ $? = 0 ]; then
      chown -R %{name}:%{name} %{tiarra_logdir}
    fi
  fi
fi

%post
if ! /sbin/chkconfig %{name}; then
  /sbin/chkconfig --add %{name}
fi

if [ $1 -eq 2 ]; then
  %{_initdir}/%{name} condrestart
fi

%preun
if [ $1 = 0 ]; then
  %{_initdir}/%{name} stop
  /sbin/chkconfig --del %{name}
fi

%postun
if [ $1 = 0 ]; then
  /usr/sbin/userdel %{name}
fi


%files
%defattr(-, root, root)
%doc AUTHORS ChangeLog ChangeLog.svn HACKING INSTALL LICENSE NEWS
%doc *.conf doc
%{_bindir}/%{name}
%dir %{_datadir}/%{name}
%{_datadir}/%{name}/*
%dir %{_sysconfdir}/%{name}
%{_sysconfdir}/%{name}/%{name}-vine-sample.conf
%{_initdir}/%{name}
%attr(0750, %{name}, %{name}) %dir %{tiarra_logdir}


%changelog
* Mon Apr 18 2011 Masahiro INOUE <miyabi.-.inoue@nifty.com> 20100210-6
 - VineSeed and Vine 5.x was integrated.
 - fix %post section

* Sun Dec 19 2010 Shu KONNO <owa@bg.wakwak.com> 20100212-5
- fixed typo of Summary(ja)

* Mon Dec 13 2010 Shu KONNO <owa@bg.wakwak.com> 20100212-4
- changed rpm-package group to Applications/Services
- updated tiarra-init.sh (set daemon user to %{name})
- added %pre section
- vine-sample.conf files together into one

* Thu Dec 09 2010 Shu KONNO <owa@bg.wakwak.com> 20100212-2
- initial build for VineSeed
  - added tiarra-20100212-vine.patch (by Masahiro INOUE)
  - added tiarra-vine-sample.conf (by Masahiro INOUE)
  - added tiarra-init.sh
  - added tiarra-vine.conf

