From fef0efe5bc5f692bd3a25d1fe73d7142b82b74aa Mon Sep 17 00:00:00 2001
From: Sebastien Robin <seb@nexedi.com>
Date: Fri, 28 Aug 2015 11:56:30 +0200
Subject: [PATCH] erp5: define INSTANCE_HOME for zopes to allow defining
 emergency user if needed

When looking for emergency user, zope configuration is not fully loaded
yet, thus if we do not set INSTANCE_HOME at startup, it will be wrong.
With this change, setting an "access" file under erp5shared folder will
work properly

In the same time, fix HOME folder to not be in a tmp folder
---
 slapos/recipe/generic_zope_zeo_client/__init__.py | 5 ++++-
 stack/erp5/buildout.cfg                           | 2 +-
 stack/erp5/instance-zope.cfg.in                   | 2 ++
 3 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/slapos/recipe/generic_zope_zeo_client/__init__.py b/slapos/recipe/generic_zope_zeo_client/__init__.py
index 082727d32..7b4fb8490 100644
--- a/slapos/recipe/generic_zope_zeo_client/__init__.py
+++ b/slapos/recipe/generic_zope_zeo_client/__init__.py
@@ -105,10 +105,13 @@ class Recipe(GenericBaseRecipe):
     zope_environment = {
       'TMP': self.options['tmp-path'],
       'TMPDIR': self.options['tmp-path'],
-      'HOME': self.options['tmp-path'],
+      'HOME': self.options.get('home-path', self.options.get('tmp-path')),
       'PATH': self.options['bin-path'],
       'TZ': self.options['timezone'],
     }
+    instance_home = self.options.get("instancehome-path", None)
+    if instance_home:
+      zope_environment["INSTANCE_HOME"] = instance_home
 
     # longrequestlogger product which requires environment settings
     longrequest_logger_file = self.options.get('longrequest-logger-file', None)
diff --git a/stack/erp5/buildout.cfg b/stack/erp5/buildout.cfg
index 772c80e4f..f44c8ee45 100644
--- a/stack/erp5/buildout.cfg
+++ b/stack/erp5/buildout.cfg
@@ -318,7 +318,7 @@ md5sum = 9670cf63099e2c520017a23defff51a4
 [template-zope]
 <= download-base
 filename = instance-zope.cfg.in
-md5sum = 995257c4d08365db7ac0d1b40936ef8b
+md5sum = 44c4aa068cffe2c1d8320d59e6d1c499
 link-binary =
   ${aspell:location}/bin/aspell
   ${dmtx-utils:location}/bin/dmtxwrite
diff --git a/stack/erp5/instance-zope.cfg.in b/stack/erp5/instance-zope.cfg.in
index 8a82b97a1..f1d83dc03 100644
--- a/stack/erp5/instance-zope.cfg.in
+++ b/stack/erp5/instance-zope.cfg.in
@@ -182,6 +182,8 @@ user = {{ dumps(slapparameter_dict['inituser-login']) }}
 password = {{ dumps(slapparameter_dict['inituser-password']) }}
 timezone = {{ dumps(slapparameter_dict['timezone']) }}
 tmp-path = ${directory:tmp}
+instancehome-path = ${directory:instance}
+home-path = ${buildout:directory}
 bin-path = ${directory:bin}:{{ parameter_dict['coreutils'] }}/bin
 site-zcml = ${directory:instance-etc}/site.zcml
 runzope-binary = ${preload-userhosts-runzope:rendered}
-- 
2.30.9