# sitelib for noarch packages, sitearch for others (remove the unneeded one)
%{!?python_sitelib: %define python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")}
%{!?python_version: %define python_version %(%{__python} -c "import sys; print sys.version[0:3]")}

Name:           rainbow
Version:        0.7.5.11.20080104git6c25f7
Release:        1%{?dist}
Summary:        The OLPC security service

Group:          System Environment/Daemons
License:        MIT
URL:            http://wiki.laptop.org/go/Rainbow
Source0:        http://dev.laptop.org/~mstone/releases/SOURCES/%{name}-%{version}.tar.bz2
BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)

BuildArch:      noarch
Requires:       dbus
Requires:       sugar >= 0.65-0.77.20071105git.0a9676171d
Requires:       ipython
BuildRequires:  python-devel
BuildRequires:  python-setuptools

%description
The service component of the OLPC Bitfrost security platform.

%prep
%setup -q -n Rainbow-%{version}


%build
%{__python} setup.py build


%install
rm -rf $RPM_BUILD_ROOT
%{__python} setup.py install -O1 --skip-build --root $RPM_BUILD_ROOT

install -d $RPM_BUILD_ROOT/%{_sbindir}
install -m 755 bin/rainbow-replay-spool $RPM_BUILD_ROOT/%{_sbindir}/rainbow-replay-spool
install -m 755 bin/rainbow-daemon       $RPM_BUILD_ROOT/%{_sbindir}/rainbow-daemon

install -d $RPM_BUILD_ROOT/%{_sysconfdir}/init.d/
install etc/init.d/rainbow $RPM_BUILD_ROOT/%{_sysconfdir}/init.d/rainbow

install -d $RPM_BUILD_ROOT/%{_sysconfdir}/dbus-1/system.d
install -d $RPM_BUILD_ROOT/%{_sysconfdir}/security/console.perms.d
install -m 644 rainbow/conf/51-rainbow.perms $RPM_BUILD_ROOT/%{_sysconfdir}/security/console.perms.d/51-rainbow.perms
install -m 644 rainbow/conf/session-olpc.conf $RPM_BUILD_ROOT/%{_sysconfdir}/dbus-1/session-olpc.conf
install -m 644 rainbow/conf/org.laptop.security.Rainbow.conf $RPM_BUILD_ROOT/%{_sysconfdir}/dbus-1/system.d/org.laptop.security.Rainbow.conf

install -d $RPM_BUILD_ROOT/%{_sysconfdir}/rainbow
install -m 644 rainbow/conf/rainbow.conf $RPM_BUILD_ROOT/%{_sysconfdir}/rainbow/rainbow.conf

install -d $RPM_BUILD_ROOT/%{_localstatedir}/log
touch $RPM_BUILD_ROOT/%{_localstatedir}/log/rainbow
chmod 644 $RPM_BUILD_ROOT/%{_localstatedir}/log/rainbow

# Turn rainbow on by default.
touch $RPM_BUILD_ROOT/%{_sysconfdir}/olpc-security


%post
/sbin/chkconfig --add rainbow


%preun
if [ "$1" -eq 0 ]; then
  /sbin/service rainbow stop > /dev/null 2>&1 || :
  /sbin/chkconfig --del rainbow
fi
exit 0

%postun
if [ "$1" -gt 0 ]; then
  /sbin/service rainbow restart > /dev/null 2>&1 || :
fi
exit 0

%clean
rm -rf $RPM_BUILD_ROOT


%files
%defattr(-,root,root,-)
%{_sysconfdir}/olpc-security
%config(noreplace) %{_sysconfdir}/dbus-1/system.d/org.laptop.security.Rainbow.conf
%config(noreplace) %{_sysconfdir}/rainbow/rainbow.conf
%config(noreplace) %{_sysconfdir}/dbus-1/session-olpc.conf
%config(noreplace) %{_sysconfdir}/security/console.perms.d/51-rainbow.perms
%doc README COPYING AUTHORS
%dir %{python_sitelib}/rainbow
%{python_sitelib}/rainbow/*
%{_sbindir}/rainbow-daemon
%{_sbindir}/rainbow-replay-spool
%{_sysconfdir}/init.d/rainbow
%ghost %{_localstatedir}/log/rainbow
%dir %{python_sitelib}/Rainbow-%{version}-py%{python_version}.egg-info
%{python_sitelib}/Rainbow-%{version}-py%{python_version}.egg-info/*

%changelog
* Wed Dec 26 2007 Michael Stone <michael@laptop.org> - 0.7.6-1.olpc2
- Move Rainbow's spool-dir from /activities to /security/activities; works
  around http://dev.laptop.org/ticket/5033
- Provide a spool-replay script for use by olpc-configure.

* Wed Dec 19 2007 Michael Stone <michael@laptop.org> - 0.7.5-1.olpc2
- Install /etc/olpc-security by default.
- Improve installation-scripts to handle updates. (thanks, Mako).
- Cause rainbow-daemon to request utf8 strings, fixes http://dev.laptop.org/ticket/5011.

* Sat Nov 10 2007 Michael Stone <michael@laptop.org> - 0.7.4-1.olpc2
- Explicitly specify the working directory of launched activities.
- Reduce permissions on activity home dirs.
- Fix the strace option.
- Add ipython dependency so we get detailed tracebacks on failure.
- Make owner.key.pub available to activities.

* Wed Nov 07 2007 Michael Stone <michael@laptop.org> - 0.7.3-1.olpc2
- Replace Rainbow's log dir with a log file.
- Put Rainbow's spool into /activities since we're making /var/run and /var/tmp
  into tmpfsen.

* Mon Nov 05 2007 Michael Stone <michael@laptop.org> - 0.7.2-1.olpc2
- Tell Sugar when we think we've successfully launched activities.

* Mon Nov 05 2007 Michael Stone <michael@laptop.org> - 0.7.1-1.olpc2
- Add rainbow-inject hook for console tests.
- Improve error-detection.
- Explicitly take ownership for all the dirs in Rainbow's spool.
- Reap zombie children.
- Add explicit dependency on an appropriate sugar version.

* Thu Nov 01 2007 Michael Stone <michael@laptop.org> - 0.7.0-1.olpc2
- Remove olpc-update
- Remove dependency on pyvserver

* Thu Sep 27 2007 Michael Stone <michael@laptop.org> - 0.6.7-1
- Add /etc/init.d/rainbow-daemon

* Thu Sep 27 2007 Michael Stone <michael@laptop.org> - 0.6.6-1
- Bump revision number.

* Mon Sep 24 2007 Michael Stone <michael@laptop.org> - 0.6.5-1
- Bump revision number.

* Mon Sep 24 2007 Michael Stone <michael@laptop.org> - 0.6.4-1
- Bump revision number.
- Add dependency on olpccontents

* Wed Sep 19 2007 Michael Stone <michael@laptop.org> - 0.6.3-1
- Fix version/release numbering.
- Correct source line.

* Wed Sep 19 2007 Michael Stone <michael@laptop.org> - 1.0-0.6.2
- Bump revision number.
- Fix installation permissions on executable scripts.
- Add a olpc-update and olpc-update-rsync scripts for performing incremental OS
  updates.

* Mon Sep 10 2007 Michael Stone <michael@laptop.org> - 1.0-0.6.1
- Bump revision number.

* Fri Sep 07 2007 Michael Stone <michael@laptop.org> - 1.0-0.6
- Correct ChangeLog formatting.

* Thu Aug 31 2007 Michael Stone <michael@laptop.org> - 1.0-0.4.4.20070831gita7c737
- Record run-time dependencies on python-sqlalchemy and pyvserver.
- Add a build-number field to the release identifier.

* Thu Aug 30 2007 Michael Stone <michael@laptop.org> - 1.0-0.2.20070830git014607
- Add a new installed binary for runninng updaters.

* Mon Aug 13 2007 Noah Kantrowitz <noah@laptop.org> - 1.0-0.2.20070731gitde262e
- Add dist tag to Release.

* Mon Aug 13 2007 Noah Kantrowitz <noah@laptop.org> - 1.0-0.1.20070731gitde262e
- Remove arch-specific variables.
- Package only needed folders from site-pacakges.
- Use macros in a few more places.

* Tue Jul 31 2007 Noah Kantrowitz <noah@laptop.org> - 1.0-0.0.20070731gitde262e
- Bump to latest version of Rainbow.

* Mon Jul 30 2007 Noah Kantrowitz <noah@laptop.org> - 1.0-0.0.20070730git9a7744
- Adding DBus session bus config and bumping to new snapshop of Rainbow.

* Tue Jul 24 2007 Noah Kantrowitz <noah@laptop.org> - 1.0-0.0.20070723git639686
- Initial version of this spec.
