File SOGo.spec of Package SOGo3

#
# spec file for package SOGo
#
# Copyright (c) 2015 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/
#


%define         sope_soname            4_9
%define         sope_version           4.9
%define         gs_library             %{_libdir}/GNUstep
%define         gs_makefiles           %{_datadir}/GNUstep/Makefiles
%define         grp                    sogo
%define         usr                    sogo
%define			sogo_mversion		SOGo3
%define			sogo_name		SOGo
%if ! %{defined _fillupdir}
  %define _fillupdir /var/adm/fillup-templates
%endif
Name:           SOGo3
Summary:        Scalable OpenGroupware.org (Inverse edition)
Version:        3.2.10
%define         lib_version %{version}
Release:        0
License:        GPL-2.0+ or LGPL-2.1+
Group:          Productivity/Networking/Email/Utilities
Url:            http://www.sogo.nu/
Source0:        http://www.sogo.nu/files/downloads/SOGo/Sources/%{sogo_name}-%{version}.tar.gz
Source1:        %{sogo_name}.sysconfig
Source2:        %{sogo_name}.init
Source3:        %{sogo_name}.logrotate
Source4:        %{sogo_name}.wrapper
Source100:      %{sogo_name}.rpmlintrc
# set TABS
Patch1:         %{sogo_name}-makefile.patch
# FIX install DESTDIR for versitCardsSaxDriver
Patch2:         %{sogo_name}-DESTDIR.patch
# Fix error SOGo mail bundles not loading (could not load product: MailPartViewers)
Patch3:         %{sogo_name}-makefile2.patch
# Fix Program returns random data in a function
# Patch4:                 %{sogo_name}-SOGoContentObject.m.patch
#####
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
PreReq:         %fillup_prereq
BuildRequires:  gcc-objc
#BuildRequires:  gnustep-base
BuildRequires:  gnustep-base-devel
#BuildRequires:  gnustep-make
#BuildRequires:  httpd
BuildRequires:  libcurl-devel
BuildRequires:  libmemcached-devel
#BuildRequires:  patch
BuildRequires:  SOPE-devel
BuildRequires:  SOPE-core
%if 0%{?suse_version} > 1030 || 0%{?fedora_version} > 8
BuildRequires:  fdupes
%endif
BuildRequires:  libffi6
%if 0%{?suse_version} >= 1500
BuildRequires:  insserv-compat
%endif
#
Requires:       gnustep-base
Requires:       httpd
Requires:       memcached
Requires:       SOPE-appserver
Requires:       SOPE-core
#
Recommends:     cron
Recommends:     logrotate
Recommends:     tmpwatch

%description
SOGo is a groupware server built around OpenGroupware.org (OGo) and
the SOPE application server.  It focuses on scalability.

The Inverse edition of this project has many feature enhancements:
- CalDAV and GroupDAV compliance
- full handling of vCard as well as vCalendar/iCalendar formats
- support for folder sharing and ACLs

The Web interface has been rewritten in an AJAX fashion to provided a faster
UI for the users, consistency in look and feel with the Mozilla applications,
and to reduce the load of the transactions on the server.

%package -n libGDLContentStore%{sope_soname}
Summary:        Storage backend for folder abstraction
Group:          System/Libraries

%description -n libGDLContentStore%{sope_soname}
The storage backend implements the "low level" folder abstraction, which is
basically an arbitary "BLOB" containing some document.

%package -n libNGCards%{sope_soname}
Summary:        SOPE library for iCal and VCard formats
Group:          System/Libraries

%description -n libNGCards%{sope_soname}
SOPE versit parsing library for iCal and VCard formats

%package devel
Summary:        Development headers and libraries for SOGo
Group:          Development/Libraries/C and C++
Requires:       %{name} = %{version}
Requires:       libGDLContentStore%{sope_soname} = %{version}
Requires:       libNGCards%{sope_soname} = %{version}
Requires:       libGDLAccess%{sope_soname} = %{version}

%description devel
Development headers and libraries for SOGo. Needed to create modules.

%package tool
Summary:        Command-line toolsuite for SOGo
Group:          Productivity/Networking/Email/Utilities

%description tool
Administrative tool for SOGo that provides the following internal commands:
  backup          -- backup user folders
  restore         -- restore user folders
  remove-doubles  -- remove duplicate contacts from the user addressbooks
  check-doubles   -- list user addressbooks with duplicate contacts

%package slapd-sockd
Summary:        SOGo backend for slapd and back-sock
Group:          Productivity/Networking/Email/Utilities

%description slapd-sockd
SOGo backend for slapd and back-sock, enabling access to private addressbooks
via LDAP.

%package -n sogo3-activesync
Summary:      SOGo module to handle ActiveSync requests
Group:        Productivity/Groupware
Requires:     %{name} = %{version}
#Requires:     libwbxml2
BuildRequires: libwbxml2-devel
#AutoReqProv:  off

%description -n sogo3-activesync
SOGo module to handle ActiveSync requests again ActiveSyncServer

%prep
%setup -q -n %{sogo_name}-%{version}
%patch1
%patch2
%patch3
#%patch4
#####
# remove --rpath in GNUmakefile
for makefiledir in UI/Contacts UI/SOGoUI UI/MailerUI UI/Common UI/MailPartViewers \
 UI/PreferencesUI UI/MainUI UI/AdministrationUI UI/Scheduler OpenChange \
 SoObjects/SOGo Main Tests/Unit Tools; do
   sed -i 's/^\(ADDITIONAL_LDFLAGS.*\)\(--rpath,\)\(.*\)//' ${makefiledir}/GNUmakefile
done   
sed -i 's/^\(ADDITIONAL_LDFLAGS.*\)\(--rpath,\)\(.*\)//' Tests/Integration/GNUmakefile.preamble
sed -i 's/^\(.*\)\(-Wl,-rpath,$(SOGO_SYSLIBDIR)\/sogo\)\(.*\)//' SoObjects/common.make
sed -i 's/^\(.*\)\(-Wl,-rpath,$(SOGO_SYSLIBDIR)\/sogo\)\(.*\)//' ActiveSync/common.make
cat SoObjects/common.make
# some SOGoDefaults
sed -i \
  -e 's,\(WOLogFile\ =\ "\).*\(";\),\1/var/log/%{name}/sogo.log\2,' \
  -e 's,\(WOPidFile\ =\ "\).*\(";\),\1/var/run/%{name}/sogo.pid\2,' \
  -e 's,\(SOGoMailSpoolPath\ =\ "\)/tmp\(";\),\1/var/spool/%{name}\2,' \
  SoObjects/%{sogo_name}/SOGoDefaults.plist

# fix perm
chmod 644 Scripts/*.sh

# ****************************** build ********************************
%build
. %{gs_makefiles}/GNUstep.sh
./configure \
  --disable-debug \
  --enable-strip

case %{_target_platform} in
ppc64-*)
  cc="gcc -m64";
  ldflags="-m64";;
*)
  cc="gcc";
  ldflags="";;
esac

make CC="$cc" LDFLAGS="$ldflags" messages=yes

# ****************************** install ******************************
%install

case %{_target_platform} in
ppc64-*)
  cc="gcc -m64";
  ldflags="-m64";;
*)
  cc="gcc";
  ldflags="";;
esac

make DESTDIR=%{buildroot} \
  GNUSTEP_INSTALLATION_DOMAIN=SYSTEM \
  CC="$cc" LDFLAGS="$ldflags" \
  install
#mkdir -p %{buildroot}%{_sysconfdir}/init.d
mkdir -p %{buildroot}%{_sysconfdir}/cron.daily
#mkdir -p %{buildroot}%{_sysconfdir}/logrotate.d
#mkdir -p %{buildroot}%{_sysconfdir}/apache2/conf.d
mkdir -p %{buildroot}%{_sysconfdir}/ld.so.conf.d
#mkdir -p %{buildroot}%{_prefix}/sbin
#mkdir -p %{buildroot}%{_localstatedir}/run/%{name}
mkdir -p %{buildroot}%{_localstatedir}/log/%{name}
mkdir -p %{buildroot}%{_localstatedir}/spool/%{name}
#mkdir -p %{buildroot}%{_localstatedir}/adm/fillup-templates

install -D -m0644 Apache/%{sogo_name}.conf %{buildroot}%{_sysconfdir}/apache2/conf.d/%{name}.conf
cat > %{buildroot}%{_sysconfdir}/cron.daily/%{name}.nu-tmpwatch << "EOF"
#!/bin/sh
if [ -x /usr/sbin/tmpwatch ]; then
  /usr/sbin/tmpwatch 24 /var/spool/%{name}
else
  echo "missing tool: tmpwatch"
fi
EOF
echo %{_libdir}/sogo > %{buildroot}%{_sysconfdir}/ld.so.conf.d/%{name}.conf
install -D -m0644 %{S:1} %{buildroot}%{_fillupdir}/sysconfig.%{name}
install -D -m0755 %{S:2} %{buildroot}%{_initrddir}/sogod
install -D -m0644 %{S:3} %{buildroot}%{_sysconfdir}/logrotate.d/%{name}
install -D -m0755 %{S:4} %{buildroot}%{_sbindir}/sogod-wrapper
chmod 755 %{buildroot}%{_sbindir}/sogod
chmod 755 %{buildroot}%{_sysconfdir}/cron.daily/%{name}.nu-tmpwatch
ln -sf %{_sysconfdir}/init.d/sogod %{buildroot}%{_sbindir}/rcsogod
#rm -rf %{buildroot}%{prefix}/Tools/test_quick_extract

# fix libSOGo.so links
#pushd %{buildroot}%{_libdir}
#for so in libSOGo.so libSOGo.so.2 libSOGo.so.%{lib_version}; do
#  rm %{buildroot}%{_libdir}/sogo/${so}
#  ln -sf ../../lib/GNUstep/Frameworks/%{name}.framework/Versions/Current/sogo/${so} \
#    %{buildroot}%{_libdir}/sogo/${so}
#done
#popd

%if 0%{?suse_version} > 1030 || 0%{?fedora_version} > 8
%fdupes %{buildroot}%{gs_library}
%endif

# ActiveSync
(pushd ActiveSync; \
 LD_LIBRARY_PATH=${RPM_BUILD_ROOT}%{_libdir} \
 make DESTDIR=${RPM_BUILD_ROOT} \
     GNUSTEP_INSTALLATION_DOMAIN=SYSTEM \
      CC="$cc" LDFLAGS="$ldflags" \
   install)

# **************************** pkgscripts *****************************
%pre
# add group
%{_sbindir}/groupadd -r %{grp} 2>/dev/null || :
# add user
%{_sbindir}/useradd -c "%{name} account" -d /var/lib/%{name} -G %{grp} -g %{grp} \
  -r -s /bin/false %{usr} 2>/dev/null || :

%preun
%stop_on_removal sogod

%post
%fillup_and_insserv sogod
/sbin/ldconfig
#
#if ! id sogo >& /dev/null; then /usr/sbin/useradd sogo > /dev/null 2>&1; fi
#if ! [ -d ~sogo ]; then /bin/mkdir ~sogo > /dev/null 2>&1; fi
#touch ~sogo/.profile
#grep -q '^source %{gs_makefiles}/GNUstep.sh' ~sogo/.profile || echo "source %{gs_makefiles}/GNUstep.sh" >> ~sogo/.profile
#/bin/chown -R sogo ~sogo
#/bin/chown -R sogo /var/log/sogod
#/bin/chown -R sogo /var/spool/sogod
#/bin/chmod 700 /var/spool/sogod

%postun
%restart_on_update sogod
%insserv_cleanup
/sbin/ldconfig
#
#if test "$1" = "0"
#then
#  if [ -e ~sogo/.profile ]; then
#    mv -f ~sogo/.profile ~sogo/.profile.orig
#    egrep -v "^source %{gs_makefiles}/GNUstep.sh" ~sogo/.profile.orig > ~sogo/.profile
#    rm -f ~sogo/.profile.orig
#    /bin/chown sogo ~sogo/.profile
#  fi
#  /usr/sbin/userdel sogo
#  /usr/sbin/groupdel sogo > /dev/null 2>&1
#  /bin/rm -rf /var/spool/sogod
#fi

%post -n libNGCards%{sope_soname} -p /sbin/ldconfig
%postun -n libNGCards%{sope_soname} -p /sbin/ldconfig

%post -n libGDLContentStore%{sope_soname} -p /sbin/ldconfig
%postun -n libGDLContentStore%{sope_soname}
/sbin/ldconfig

# ****************************** clean ********************************
%clean
rm -fr %{buildroot}

# ****************************** files ********************************
%files
%defattr(-,root,root,-)
%doc ChangeLog COPYING.* NEWS
%doc Scripts/*
%dir %{_sysconfdir}/apache2/
%dir %{_sysconfdir}/apache2/conf.d
%config(noreplace) %{_sysconfdir}/apache2/conf.d/%{name}.conf
%config %{_fillupdir}/sysconfig.%{name}
%config %{_sysconfdir}/cron.daily/%{name}.nu-tmpwatch
%config %{_sysconfdir}/logrotate.d/%{name}
%config %{_sysconfdir}/ld.so.conf.d/%{name}.conf
%{_sysconfdir}/init.d/sogod
%{_sbindir}/sogod
%{_sbindir}/sogod-wrapper
%{_sbindir}/rcsogod
%attr(750,%{usr},root) %{_localstatedir}/log/%{name}
%attr(750,%{usr},root) %{_localstatedir}/spool/%{name}
%dir %{_libdir}/sogo
%{_libdir}/sogo/libSOGo.so.*
%{_libdir}/sogo/libSOGoUI.so.*
#%{_libdir}/libOGoContentStore.so.*
%dir %{gs_library}/Frameworks
%dir %{gs_library}/Frameworks/%{sogo_name}.framework
%dir %{gs_library}/Frameworks/%{sogo_name}.framework/sogo
%{gs_library}/Frameworks/%{sogo_name}.framework/Resources
%dir %{gs_library}/Frameworks/%{sogo_name}.framework/Versions
%dir %{gs_library}/Frameworks/%{sogo_name}.framework/Versions/3
%dir %{gs_library}/Frameworks/%{sogo_name}.framework/Versions/3/sogo
%{gs_library}/Frameworks/%{sogo_name}.framework/Versions/3/sogo/libSOGo*
%{gs_library}/Frameworks/%{sogo_name}.framework/Versions/3/Resources
%{gs_library}/Frameworks/%{sogo_name}.framework/Versions/Current
%dir %{gs_library}/%{sogo_name}
%{gs_library}/%{sogo_name}/AdministrationUI.%{sogo_name}
%{gs_library}/%{sogo_name}/Appointments.%{sogo_name}
%{gs_library}/%{sogo_name}/CommonUI.%{sogo_name}
%{gs_library}/%{sogo_name}/Contacts.%{sogo_name}
%{gs_library}/%{sogo_name}/ContactsUI.%{sogo_name}
%{gs_library}/%{sogo_name}/Mailer.%{sogo_name}
%{gs_library}/%{sogo_name}/MailerUI.%{sogo_name}
%{gs_library}/%{sogo_name}/MailPartViewers.%{sogo_name}
%{gs_library}/%{sogo_name}/MainUI.%{sogo_name}
%{gs_library}/%{sogo_name}/PreferencesUI.%{sogo_name}
%{gs_library}/%{sogo_name}/SchedulerUI.%{sogo_name}
%{gs_library}/%{sogo_name}/Templates
%{gs_library}/%{sogo_name}/WebServerResources
%{gs_library}/OCSTypeModels
%{gs_library}/WOxElemBuilders-%{sope_version}

%files tool
%defattr(-,root,root,-)
%{_sbindir}/sogo-tool
%{_sbindir}/sogo-ealarms-notify

%files slapd-sockd
%defattr(-,root,root,-)
%{_sbindir}/sogo-slapd-sockd

%files -n sogo3-activesync
%defattr(-,root,root,-)
%{gs_library}/SOGo/ActiveSync.SOGo
%doc ActiveSync/LICENSE ActiveSync/README

%files -n libGDLContentStore%{sope_soname}
%defattr(-,root,root,-)
%{_libdir}/sogo/libGDLContentStore*.so.%{sope_version}*

%files -n libNGCards%{sope_soname}
%defattr(-,root,root,-)
%{_libdir}/sogo/libNGCards.so.*
%{gs_library}/SaxDrivers-%{sope_version}
%{gs_library}/SaxMappings
%{gs_library}/Libraries/Resources

%files devel
%defattr(-,root,root,-)
%{_includedir}/%{sogo_name}
%{_includedir}/SOGoUI
%{_libdir}/sogo/libSOGo.so
%{_libdir}/sogo/libSOGoUI.so
#%{_libdir}/sogo/libOGoContentStore.so
%{gs_library}/Frameworks/%{sogo_name}.framework/Headers
%{gs_library}/Frameworks/%{sogo_name}.framework/sogo/libSOGo.so
%{gs_library}/Frameworks/%{sogo_name}.framework/sogo/%{sogo_name}
%{gs_library}/Frameworks/%{sogo_name}.framework/Versions/3/Headers
#%{gs_library}/Frameworks/%{name}.framework/Versions/3/Resources
#%{gs_library}/Frameworks/%{name}.framework/Versions/3/sogo/libSOGo*
%{gs_library}/Frameworks/%{sogo_name}.framework/Versions/3/sogo/%{sogo_name}
# ***** LibGDLContentStore *****
%{_includedir}/GDLContentStore
%{_libdir}/sogo/libGDLContentStore*.so
# ***** LibNGCards *****
%{_includedir}/NGCards
%{_libdir}/sogo/libNGCards.so

# ********************************* changelog *************************
%changelog
openSUSE Build Service is sponsored by