File openoffice.org-oood.spec of Package openoffice.org-oood

%define prefix       openoffice.org-
%define deamon_name  oood

%define version      0.2.0
%define release      6

%define server_user   oood
%define config_dir    %{_sysconfdir}/oood
%define server_dir    %{_var}/lib/oood
%define run_dir       %{_var}/run/oood
%define log_dir       %{_var}/log/oood


Summary:       Standalone server for converting various types of docs to/from OpenOffice format, extracting and editing metadata.
Name:          %{prefix}%{deamon_name}
Version:       %{version}
Release:       %{release}
License:       GPL
Group:         System/Servers
Source0:       %{deamon_name}-%{version}.tar.bz2
Patch1:        openoffice.org-2.0.3-skip-registration.patch
Patch2:        SimpleXMLRPCServer.patch
URL:           http://svn.erp5.org/erp5/trunk/utils/ooodoc_server/
BuildRoot:     %{_tmppath}/%{name}-%{version}-%{release}-rootdir
Requires:      python >= 2.3, openoffice.org-pyuno >= 2.0.0, xorg-x11-Xvfb
Requires(pre): rpm-helper, patch
BuildRequires: python >= 2.3

#----------------------------------------------------------------------
%description
A server for converting docs from other formats to OOo, generating pdf files, keeping unchangeable snapshots in pdf format, getting and setting metadata. To be used together with ERP5 Document business template, although can be run standalone for any other client application.

It returns a file in a desired format; html files are zipped because they often consist of more than one file.

#----------------------------------------------------------------------

%prep
%setup -c


%build


%install
%{__rm} -rf  %{buildroot}

# Create and populate /etc/oood/
%{__mkdir_p} %{buildroot}/%{config_dir}
%{__mv} %{deamon_name}/config.py   %{buildroot}/%{config_dir}/
%py_compile %{buildroot}/%{config_dir}

# For next 2007 release, look at http://qa.mandriva.com/twiki/bin/view/Main/InitscriptHowto
%{__mkdir_p} %{buildroot}%{_initrddir}
%{__mv} %{deamon_name}/oood.rc %{buildroot}%{_initrddir}/oood

# Create /var/lib/oood/tmp/
%{__mkdir_p} %{buildroot}/%{server_dir}/tmp

# Create and populate /var/lib/oood/
%{__cp} -a  %{deamon_name}/*  %{buildroot}/%{server_dir}/
%py_compile %{buildroot}/%{server_dir}

# Create and populate /var/lib/oood/patches/
%{__mkdir_p} %{buildroot}/%{server_dir}/patches
%{__cp} -a  %{PATCH1}  %{buildroot}/%{server_dir}/patches/
%{__cp} -a  %{PATCH2}  %{buildroot}/%{server_dir}/patches/

# Create and populate /var/run/oood
%{__mkdir_p} %{buildroot}%{run_dir}

# Create and populate /var/log/oood
%{__mkdir_p} %{buildroot}%{log_dir}
touch %{buildroot}%{log_dir}/oood.log

# Create logrotate file
%define logrotate_dir %{_sysconfdir}/logrotate.d
%{__mkdir_p} %{buildroot}/%{logrotate_dir}
echo "
/var/log/oood/oood.log {
    sharedscripts
    rotate 10
    daily
    missingok
    compress
}
" > %{buildroot}/%{logrotate_dir}/oood

# Create README file
cat %{deamon_name}/README > README.urpmi


%clean
%{__rm} -rf %{buildroot}


%pre
%_pre_useradd %{server_user} %{run_dir} /bin/bash


%post
# Hack - Silent patch: Bypass the openoffice registration nag screen.
# This patch is hard to apply because we don't know which version of openoffice
#   will be installed on the system: openoffice RPM can came from Mandriva or
#   from OOo official project.
# Because the origin is unknown, we have to calculate where openoffice is installed
#   and modify some configuration files. This is the goal of the code below.
# Path for mandriva    official RPMs:       /usr/lib/ooo-2.0/share/registry/data/org/openoffice
# Path for ooo project official RPMs: /opt/openoffice.org2.0/share/registry/data/org/openoffice
%define patches_dir %{server_dir}/patches
MDV_PATH=`find -P /usr/lib/ -depth -maxdepth 3 -mount -name "soffice" | cut -d '/' -f -4`
OOO_PATH=`find -P /opt/     -depth -maxdepth 3 -mount -name "soffice" | cut -d '/' -f -3`
if test "x$MDV_PATH" != "x"; then
  OOO_ROOT=$MDV_PATH
fi
if test "x$OOO_PATH" != "x"; then
  OOO_ROOT=$OOO_PATH
fi
%define ooo_setup_file    share/registry/data/org/openoffice/Setup.xcu
%define ooo_file_to_patch $OOO_ROOT/%{ooo_setup_file}
%{__cp} -a %{ooo_file_to_patch} %{ooo_file_to_patch}.rpmsave
%{__patch} %{ooo_file_to_patch} --input=%{patches_dir}/openoffice.org-2.0.3-skip-registration.patch

# Update oood config to let it find where openoffice is installed
OOO_ROOT=`echo $OOO_ROOT | python -c "print raw_input().replace('/', '\/')"`
%{__sed} -i "s/\/opt\/openoffice.org2.0/`echo $OOO_ROOT`/g" %{config_dir}/config.py

# Hack / Patch 2
# This patch python XML-RPC server. This patch was commited upstream in official
#   python project, so this patch should be deleted for Mandriva 2008.
%define patches_dir %{server_dir}/patches
%{__cp} -a %{py_libdir}/SimpleXMLRPCServer.py %{py_libdir}/SimpleXMLRPCServer.py.rpmsave
%{__patch} %{py_libdir}/SimpleXMLRPCServer.py --input=%{patches_dir}/SimpleXMLRPCServer.patch


# Add service and start server
%_post_service oood
%__service oood restart


%preun
%__service oood stop
%_preun_service oood

# Unpatch OOo
OOO_ROOT_2=`grep 'uno_path' %{config_dir}/config.py | python -c "print '/'.join(raw_input().split(\"'\")[1].split(\"/\")[:-1])"`
%define ooo_file_to_unpatch $OOO_ROOT_2/%{ooo_setup_file}
%{__mv} %{ooo_file_to_unpatch}.rpmsave %{ooo_file_to_unpatch}

# Unpatche XML-RPC server   
%{__mv} %{py_libdir}/SimpleXMLRPCServer.py.rpmsave %{py_libdir}/SimpleXMLRPCServer.py


%postun
%_postun_userdel %{server_user}


%files

%defattr(0755,root,root,755)
%{_initrddir}/oood
%{logrotate_dir}/oood
%config(noreplace) %{config_dir}
%config(noreplace) %{_sysconfdir}/logrotate.d/oood
%doc %{deamon_name}/VERSION.txt %{deamon_name}/README %{deamon_name}/MAINTAINERS.txt

%defattr(0755,%{server_user},%{server_user},755)
%{server_dir}
%{run_dir}
%{log_dir}
#%create_ghostfile %{log_dir}/oood.log
%config(noreplace) %{log_dir}/oood.log


#----------------------------------------------------------------------
%changelog
* Wed Jan 31 2007 Kevin Deldycke <kevin@nexedi.com> 0.2.0-6mdv2007.0
- XMLRPC python patch is still required (it was merge upstrem in python 2.5 not 2.4)

* Fri Jan 26 2007 Kevin Deldycke <kevin@nexedi.com> 0.2.0-5mdv2007.0
- 'patch' command is required

* Fri Jan 26 2007 Kevin Deldycke <kevin@nexedi.com> 0.2.0-4mdv2007.0
- Fix missing macro

* Fri Jan 26 2007 Kevin Deldycke <kevin@nexedi.com> 0.2.0-3mdv2007.0
- Fix OOo location method
- Remove XMLRPC python server patch: fixed upstream

* Mon Jan 22 2007 Kevin Deldycke <kevin@nexedi.com> 0.2.0-2mdv2007.0
- Rebuild for Mandriva 2007.0

* Thu Jan 18 2007 Kevin Deldycke <kevin@nexedi.com> 0.2.0-1mdk
- Bump to 0.2.0

* Wed Jan 10 2007 Kevin Deldycke <kevin@nexedi.com> 0.1.9-5mdk
- Fix OOo path detection at uninstall

* Wed Jan 10 2007 Kevin Deldycke <kevin@nexedi.com> 0.1.9-4mdk
- Escape slash with backslash for sed manipulation
- In place sed file modification
- Fix dynamic oood config
- Macro-ize sed call

* Wed Jan 10 2007 Kevin Deldycke <kevin@nexedi.com> 0.1.9-3mdk
- Dynamic patch of OpenOffice depending of installed version
- Dynamic oood configuration depending of OpenOffice version
- OpenOffice.org package naming was moved to standard lower-case starting from 2.0 branch, so require at v2.0 of openoffice for oood (this void strange behaviour on Mandriva 2006 where both v1 and v2 are present)

* Thu Nov 30 2006 Kevin Deldycke <kevin@nexedi.com> 0.1.9-2mdk
- Even if it's recommanded to use OpenOffice.org 2.0.3, don't force the requirement of this particular version of OpenOffice

* Thu Nov 30 2006 Kevin Deldycke <kevin@nexedi.com> 0.1.9-1mdk
- Update to version 0.1.9
- Fix file rights
- Move log file to folder
- Add empty log file

* Thu Nov 30 2006 Kevin Deldycke <kevin@nexedi.com> 0.1.8-1mdk
- Update to version 0.1.8
- Macro-ize some hard-coded path reference

* Thu Nov 30 2006 Kevin Deldycke <kevin@nexedi.com> 0.1.7-1mdk
- Update to version 0.1.7
- Add xorg-x11-Xvfb requirement

* Tue Nov 28 2006 Kevin Deldycke <kevin@nexedi.com> 0.1.6-1mdk
- Update to version 0.1.6
- Add Logrotate config file

* Thu Nov 23 2006 Kevin Deldycke <kevin@nexedi.com> 0.1.5-1mdk
- Update to version 0.1.5

* Thu Nov 23 2006 Kevin Deldycke <kevin@nexedi.com> 0.1.4-1mdk
- Update to version 0.1.4
- Do not define initrd files as config files
- Start and stop service automaticcaly at install and uninstall

* Mon Nov 21 2006 Kevin Deldycke <kevin@nexedi.com> 0.1.3-1mdk
- Update to version 0.1.3
- Include server directories
- Don't include ReadMe file twice
- Add rc.d/init.d file to manage oood as a service
- Add oood service to system on install
- Delete oood service on uninstall
- Patch openoffice to skip registration form at first run
- Don't use custom shell script to start server
- Save patches in a separate folder

* Mon Nov 20 2006 Kevin Deldycke <kevin@nexedi.com> 0.1.2-1mdk
- Update to version 0.1.2
- Change package name from OOoDocument_server to openoffice.org-oood
- Update directory name
- Change default access rights

* Thu Nov 02 2006 Kevin Deldycke <kevin@nexedi.com> 0.1.1-1mdk
- Update to version 0.1.1
- Use %mkrel and others generic macro

* Tue Jul 18 2006 Bartlomiej Gorny <bartek@redpoint.mn.pl> 0.1-3mdk
- Second build

* Fri Jun 30 2006 Bartlomiej G�ny <bartek@redpoint.mn.pl> 0.1-2mdk
- first build
openSUSE Build Service is sponsored by