[buildout]

# XXX-Marco - Extra dependencies
# ------------------------------
# for libmemcached / opendkim:
#   sudo apt-get install libcloog-ppl0
# for heimdal:
#   sudo apt-get install libncurses5-dev
# for libjunixsocket:
#   sudo apt-get install gcc-multilib
#
# Changes in the Zimbra sources:
#   mysql will be compiled with the embedded yaSSL library instead of openssl
#   back-perl in openldap is disabled for linking issues to libperl.a
#
# XXX TODO: grep -R 'opt\\/zimbra' .
#           grep -R '/usr/bin/procmail' .
#           netcat, sysstat?

extends =
  /home/marco/src/slapos/stack/slapos.cfg
  /home/marco/src/slapos/component/git/buildout.cfg
  /home/marco/src/slapos/component/autoconf/buildout.cfg
  /home/marco/src/slapos/component/automake/buildout.cfg
  /home/marco/src/slapos/component/libtool/buildout.cfg
  /home/marco/src/slapos/component/pkgconfig/buildout.cfg
  /home/marco/src/slapos/component/bison/buildout.cfg
  /home/marco/src/slapos/component/flex/buildout.cfg
  /home/marco/src/slapos/component/unzip/buildout.cfg
  /home/marco/src/slapos/component/cmake/buildout.cfg
  /home/marco/src/slapos/component/ncurses/buildout.cfg
  /home/marco/src/slapos/component/bzip2/buildout.cfg
  /home/marco/src/slapos/component/pcre/buildout.cfg
  /home/marco/src/slapos/component/perl/buildout.cfg
  /home/marco/src/slapos/component/perl-libwww-perl/buildout.cfg
  /home/marco/src/slapos/component/perl-URI/buildout.cfg
  /home/marco/src/slapos/component/sqlite3/buildout.cfg
  /home/marco/src/slapos/component/pax/buildout.cfg


parts =
  slapos-cookbook
  directories
  jdk
  jdk-sources
  jdk-sources-policy
  jdk-sources-policy2
  junit
  junixsocket
  junixsocket-sources
  ant
  autoconf
  automake
  libtool
  pkgconfig
  bison
  flex
  unzip
  cmake
  ncurses
  bzip2
  sqlite3
  pax-download
  pax
  pcre
  perl
  perl-libwww-perl
  perl-URI
  zimbra-sources
  zimbra-sources-search-replace
  environment
  sh-environment
  zimbra-build


develop =
  /home/marco/src/slapos

[versions]
slapos.cookbook =
inotifyx = 0.2.0
netifaces = 0.8


[jdk-download]
# hack to download java and policy files, bypassing javascript requirement
recipe = plone.recipe.command
location = ${buildout:parts-directory}/${:_buildout_section_name_}
web-dirname = 7u15-b03
filename = jdk-7u15-linux-x64.tar.gz
policy-filename = UnlimitedJCEPolicyJDK7.zip
stop-on-error = True
update = true
command =
    mkdir -p ${:location}
    wget --no-cookies --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com" \
        "http://download.oracle.com/otn-pub/java/jdk/${:web-dirname}/${:filename}" \
        -O ${:location}/${:filename}
    wget --no-cookies --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com" \
        http://download.oracle.com/otn-pub/java/jce/7/${:policy-filename} \
        -O ${:location}/${:policy-filename}


[jdk]
# Uncompress the downloaded JDK
recipe = hexagonit.recipe.download
url = ${jdk-download:location}/${jdk-download:filename}
md5sum = 118a16aab9ff2c3f7c7788658cc77734
strip-top-level-dir = True


[jdk-sources]
# copy the jdk tarball inside the build tree
recipe = plone.recipe.command
zimbra-target = ${zimbra-sources:location}/ThirdPartyBuilds/x86_64/java
zimbra-filename = jdk1.7.0_15.tgz
update-command = ${:command}
command =
    mkdir -p ${:zimbra-target}
    cp ${jdk-download:location}/${jdk-download:filename} ${:zimbra-target}/${:zimbra-filename}
    # alternate spelling (the jdk is referenced with two different names)
    ln -s ${:zimbra-target}/${:zimbra-filename} ${:zimbra-target}/jdk-1.7.0_15.tgz



#------------------------
# The policy files are looked for under two different paths.

[jdk-sources-policy]
# copy the java policy inside the build tree
recipe = hexagonit.recipe.download
url = ${jdk-download:location}/${jdk-download:policy-filename}
destination = ${jdk-sources:zimbra-target}/jce
strip-top-level-dir = True

[jdk-sources-policy2]
# copy the java policy inside the build tree
recipe = hexagonit.recipe.download
url = ${jdk-download:location}/${jdk-download:policy-filename}
destination = ${jdk-sources:zimbra-target}/jce/UnlimitedJCEPolicy7/
strip-top-level-dir = True

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



[junit]
recipe = hexagonit.recipe.download
filename = junit-4.8.2.jar
url = http://zimbra.imladris.sk/download/jars/${:filename}
md5sum = 8a498c3d820db50cc7255d8c46c1ebd1
download-only = True
destination = ${zimbra-sources:location}/ZimbraCommon/jars


[junixsocket]
# build the native junixsocket library. the .jar parts are already inside the jars/ folder
recipe = hexagonit.recipe.cmmi
url = http://junixsocket.googlecode.com/files/junixsocket-1.3-src.tar.bz2
md5sum = fe249aba3bf568d71a5174506cf4ae80
configure-command = /bin/true
make-binary = ${ant:location}/bin/ant
make-targets =
environment-dependency = ${environment:recipe}
junit-path = ${junit:destination}/${junit:filename}
pre-make-hook = ${:_profile_base_location_}/junixsocket-hooks.py:fix_build_xml
post-make-hook = ${:_profile_base_location_}/junixsocket-hooks.py:install_library


[junixsocket-sources]
# copy the junixsocket library inside the build tree
recipe = plone.recipe.command
zimbra-target = ${zimbra-sources:location}/ThirdPartyBuilds/x86_64/java
update-command = ${:command}
command =
    mkdir -p ${:zimbra-target}/junixsocket
    cd ${:zimbra-target}/junixsocket 
    tar --extract --bzip2 --file ${junixsocket:location}/junixsocket-1.3-bin.tar.bz2 --wildcards '*.so' --strip-components=2


[ant]
recipe = hexagonit.recipe.download
# latest releases
# url = http://mirrors.linsrv.net/apache//ant/binaries/${:filename}
url = http://archive.apache.org/dist/ant/binaries/${:filename}
filename = apache-ant-1.9.0-bin.tar.gz
md5sum = 8360ecbf5375769241abf7145954b62b
strip-top-level-dir = True


[zimbra-sources]
# checkout the zimbra and thirt party sources.
recipe = slapos.recipe.build:gitclone
#repository = https://marco.mariani@bitbucket.org/marco.mariani/zimbra-5682.git
repository = /home/marco/src/zimbra-5682
branch = buildout
develop = True
git-executable = ${git:location}/bin/git


[zimbra-sources-search-replace]
# replace all remaining occurrences of /opt/zimbra
recipe = plone.recipe.command
ZIMBRA_HOME = ${environment:ZIMBRA_HOME}
PERL_BINARY = ${perl:location}/bin/perl
stop-on-error = True
update-command = ${:command}
command =
  cd ${zimbra-sources:location}
  find . -name LocalConfig.java -exec sed -i 's#= FS + "opt" + FS + "zimbra"#= "${:ZIMBRA_HOME}"#g' {} \;
  SUB1='s#/opt/zimbra#${:ZIMBRA_HOME}#g'
  SUB2='1{s|^#!/usr/bin/perl|#!${:PERL_BINARY}|}'
  find . -name '.git' -prune -o -type f -exec sed -i "$SUB1;$SUB2" {} \;


[zimbra-build]
# run the main build script for zimbra itself and thirt parties as well.
recipe = plone.recipe.command
command = ${zimbra-sources:location}/ZimbraBuild/buildZCS.sh -t -p --tpoverride
update-command = ${:command}
stop-on-error = True


[environment-base]
# provides existing envvars to the [environment] section
recipe = collective.recipe.environment


[environment]
# environment needed for building the applications.
recipe = collective.recipe.environment
ZIMBRA_HOME = ${directories:zimbra-home}
JAVA_HOME = ${jdk:location}
ANT_HOME = ${ant:location}
PATH = ${perl:location}/bin:/bin:${:JAVA_HOME}/bin:${:ANT_HOME}/bin:${autoconf:location}/bin:${automake:location}/bin:${libtool:location}/bin:${pkgconfig:location}/bin:${bison:location}/bin:${flex:location}/bin:${unzip:location}/bin:${cmake:location}/bin:${ncurses:location}/bin:${m4:location}/bin:${bzip2:location}/bin:${pcre:location}/bin:${sqlite3:location}/bin:${pax:location}/bin:/usr/local/bin:/usr/bin
LD_LIBRARY_PATH = ${:ZIMBRA_HOME}/bdb/lib:${:ZIMBRA_HOME}/mysql/lib
BZIP2_PREFIX = ${bzip2:location}
PCRE_PREFIX = ${pcre:location}
NCURSES_PREFIX = ${ncurses:location}
MAKEARGS=-j4
ZIMBRA_USER=${environment-base:USER}


[sh-environment]
# environment needed for running/debugging the applications, exported to a shell script to be sourced.
recipe = collective.recipe.template
output = ${buildout:directory}/environment.sh
input = inline:
  export ZIMBRA_HOME="${environment:ZIMBRA_HOME}"
  export JAVA_HOME="${environment:JAVA_HOME}"
  export ANT_HOME="${environment:ANT_HOME}"
  export PATH="${environment:PATH}:${environment:ZIMBRA_HOME}/bin"
  export LD_LIBRARY_PATH="${environment:LD_LIBRARY_PATH}"
  export BZIP2_PREFIX="${environment:BZIP2_PREFIX}"
  export PCRE_PREFIX="${environment:PCRE_PREFIX}"
  export NCURSES_PREFIX="${environment:NCURSES_PREFIX}"
  export MAKEARGS="${environment:MAKEARGS}"
  export ZIMBRA_USER="${environment:ZIMBRA_USER}"



[directories]
recipe = slapos.cookbook:mkdirectory
zimbra-home = ${buildout:directory}/zimbra-home



[zimbra-unpack-store]
# extract binaries and scripts from the .deb packages
# export ZIMBRA_INSTALLED_PKGS="zimbra-core zimbra-store"
recipe = plone.recipe.command
stop-on-error = True
PACKAGE_LIST = zimbra-core zimbra-store
ZIMBRA_HOME = ${environment:ZIMBRA_HOME}
PACKAGES = /home/marco/zbuild/amd64
update-command = ${:command}
command =
  rm -rf ${:ZIMBRA_HOME}
  mkdir ${:ZIMBRA_HOME}
  cd ${:ZIMBRA_HOME}
  for pkg_name in ${:PACKAGE_LIST}; do
    echo "Unpacking $pkg_name..."
    ar x ${:PACKAGES}/$pkg_name*.deb
    tar xvf data.tar.gz --strip=5 >/dev/null
    rm data.tar.gz
    rm control.tar.gz
  done

  ln -sf bdb-* bdb
  ln -sf curl-* curl
  ln -sf cyrus-sasl-* cyrus-sasl
  ln -sf heimdal-* heimdal
  ln -sf jdk* java
  ln -sf mysql-standard-* mysql
  ln -sf openldap-* openldap
  ln -sf openssl-* openssl
  ln -sf rsync-* rsync
  ln -sf tcmalloc-* tcmalloc
  ln -sf jetty-distribution-* jetty
  ln -sf jetty-distribution-* mailboxd

  mkdir -p data/tmp
  chmod 1777 data/tmp
  mkdir backup ssl .ssh zmstat




[zimbra-unpack-ldap]
# extract binaries and scripts from the .deb packages
# export ZIMBRA_INSTALLED_PKGS="zimbra-core zimbra-ldap"
# TODO:
# sudo setcap 'cap_net_bind_service=+ep' /home/marco/zbuild/zimbra-home/openldap/sbin/slapd
recipe = plone.recipe.command
stop-on-error = True
PACKAGE_LIST = zimbra-core zimbra-ldap
ZIMBRA_HOME = ${environment:ZIMBRA_HOME}
PACKAGES = /home/marco/zbuild/amd64
update-command = ${:command}
command =
  rm -rf ${:ZIMBRA_HOME}
  mkdir ${:ZIMBRA_HOME}
  cd ${:ZIMBRA_HOME}
  for pkg_name in ${:PACKAGE_LIST}; do
    echo "Unpacking $pkg_name..."
    ar x ${:PACKAGES}/$pkg_name*.deb
    tar xvf data.tar.gz --strip=5 >/dev/null
    rm data.tar.gz
    rm control.tar.gz
  done

  ln -sf bdb-* bdb
  ln -sf curl-* curl
  ln -sf cyrus-sasl-* cyrus-sasl
  ln -sf heimdal-* heimdal
  ln -sf jdk* java
  ln -sf libtool* libtool
  ln -sf mysql-standard-* mysql
  ln -sf openldap-* openldap
  ln -sf openssl-* openssl
  ln -sf rsync-* rsync
  ln -sf tcmalloc-* tcmalloc
  
  mkdir -p data/tmp
  chmod 1777 data/tmp
  mkdir -p data/ldap/config
  mkdir -p data/ldap/mdb/db




[zimbra-unpack-mta]
# extract binaries and scripts from the .deb packages
# export ZIMBRA_INSTALLED_PKGS="zimbra-core zimbra-mta"
# TODO:
# sudo setcap 'cap_net_bind_service=+ep' zimbra-home/postfix/libexec/master
recipe = plone.recipe.command
stop-on-error = True
PACKAGE_LIST = zimbra-core zimbra-mta
ZIMBRA_HOME = ${environment:ZIMBRA_HOME}
PACKAGES = /home/marco/zbuild/amd64
update-command = ${:command}
command =
  rm -rf ${:ZIMBRA_HOME}
  mkdir ${:ZIMBRA_HOME}
  cd ${:ZIMBRA_HOME}
  for pkg_name in ${:PACKAGE_LIST}; do
    echo "Unpacking $pkg_name..."
    ar x ${:PACKAGES}/$pkg_name*.deb
    tar xvf data.tar.gz --strip=5 >/dev/null
    rm data.tar.gz
    rm control.tar.gz
  done

  ln -sf altermime-* altermime
  ln -sf amavisd-* amavisd
  ln -sf bdb-* bdb
  ln -sf cbpolicyd-* cbpolicyd
  ln -sf clamav-* clamav
  ln -sf curl-* curl
  ln -sf cyrus-sasl-* cyrus-sasl
  ln -sf dspam* dspam
  ln -sf heimdal-* heimdal
  ln -sf libmemcached* libmemcached
  ln -sf mysql* mysql
  ln -sf opendkim* opendkim
  ln -sf openldap-* openldap
  ln -sf openssl-* openssl
  ln -sf postfix* postfix
  ln -sf rsync-* rsync
  ln -sf tcmalloc-* tcmalloc
  ln -sf jdk* java
  ln -sf zeromq* zeromq
  mkdir -p data/amavisd/db
  mkdir -p data/amavisd/tmp
  mkdir -p data/amavisd/var
  mkdir -p data/amavisd/quarantine
  mkdir -p data/clamav/db
  mkdir -p data/postfix/spool/pid
  mkdir -p data/tmp
  chmod 1777 data/tmp



# TODO
#  touch postfix/conf/main.cf
#  ln -s /home/marco/zbuild/zimbra-home/postfix/conf/aliases /etc/aliases                                                                              

# see also
# http://www.zimbra.com/docs/ne/6.0.6/multi_server_install/multi-server_install.5.06.html









[zimbra-unpack-all]
# extract binaries and scripts from the .deb packages
# export ZIMBRA_INSTALLED_PKGS="zimbra-core zimbra-ldap zimbra-mta zimbra-store"
# TODO:
# sudo setcap 'cap_net_bind_service=+ep' /home/marco/zbuild/zimbra-home/openldap/sbin/slapd
# sudo setcap 'cap_net_bind_service=+ep' /home/marco/zbuild/zimbra-home/postfix/libexec/master
recipe = plone.recipe.command
stop-on-error = True
PACKAGE_LIST = zimbra-core zimbra-ldap zimbra-mta zimbra-store
ZIMBRA_HOME = ${environment:ZIMBRA_HOME}
PACKAGES = /home/marco/zbuild/amd64
update-command = ${:command}
command =
  rm -rf ${:ZIMBRA_HOME}
  mkdir ${:ZIMBRA_HOME}
  cd ${:ZIMBRA_HOME}
  for pkg_name in ${:PACKAGE_LIST}; do
    echo "Unpacking $pkg_name..."
    ar x ${:PACKAGES}/$pkg_name*.deb
    tar xvf data.tar.gz --strip=5 >/dev/null
    rm data.tar.gz
    rm control.tar.gz
  done

  ln -sf altermime-* altermime
  ln -sf amavisd-* amavisd
  ln -sf bdb-* bdb
  ln -sf cbpolicyd-* cbpolicyd
  ln -sf clamav-* clamav
  ln -sf curl-* curl
  ln -sf cyrus-sasl-* cyrus-sasl
  ln -sf dspam* dspam
  ln -sf heimdal-* heimdal
  ln -sf jdk* java
  ln -sf libtool* libtool
  ln -sf libmemcached* libmemcached
  ln -sf mysql* mysql
  ln -sf opendkim* opendkim
  ln -sf openldap-* openldap
  ln -sf openssl-* openssl
  ln -sf postfix* postfix
  ln -sf rsync-* rsync
  ln -sf tcmalloc-* tcmalloc
  ln -sf jetty-distribution-* jetty
  ln -sf jetty-distribution-* mailboxd
  ln -sf zeromq* zeromq

  mkdir -p data/tmp
  chmod 1777 data/tmp
  mkdir backup ssl .ssh zmstat
  mkdir -p data/ldap/config
  mkdir -p data/ldap/mdb/db
  mkdir -p data/amavisd/db
  mkdir -p data/amavisd/tmp
  mkdir -p data/amavisd/var
  mkdir -p data/amavisd/quarantine
  mkdir -p data/clamav/db
  mkdir -p data/postfix/spool/pid