Index: npl/mailserver/kopano_conf/root/etc/kopano/userscripts/companies_common.sh
===================================================================
--- npl/mailserver/kopano_conf/root/etc/kopano/userscripts/companies_common.sh	(revision a2d969e7ad0485dba4b6e18761e3d62cb5e85588)
+++ npl/mailserver/kopano_conf/root/etc/kopano/userscripts/companies_common.sh	(revision a2d969e7ad0485dba4b6e18761e3d62cb5e85588)
@@ -0,0 +1,24 @@
+# shell include script
+
+KOPANO_LANG="${KOPANO_USERSCRIPT_LOCALE:-${LC_MESSAGES:-en_US}}"
+PATH=/bin:/usr/local/bin:/usr/bin
+export KOPANO_LANG PATH
+
+if [ -z "${KOPANO_COMPANY_SCRIPTS}" ] ; then
+    exec >&2
+    echo "Do not execute this script directly"
+    exit 1
+fi
+
+if [ ! -d "${KOPANO_COMPANY_SCRIPTS}" ] ; then
+    exec >&2
+    echo "${KOPANO_COMPANY_SCRIPTS} does not exist or is not a directory"
+    exit 1
+fi
+
+if [ -z "${KOPANO_COMPANY}" -a -z "${KOPANO_COMPANYID}" ] ; then
+    exec >&2
+    echo "KOPANO_COMPANY and KOPANO_COMPANYID is not set."
+    exit 1
+fi
+exec "$PKGLIBEXECDIR/kscriptrun" "$KOPANO_COMPANY_SCRIPTS"
Index: npl/mailserver/kopano_conf/root/etc/kopano/userscripts/createcompany
===================================================================
--- npl/mailserver/kopano_conf/root/etc/kopano/userscripts/createcompany	(revision a2d969e7ad0485dba4b6e18761e3d62cb5e85588)
+++ npl/mailserver/kopano_conf/root/etc/kopano/userscripts/createcompany	(revision a2d969e7ad0485dba4b6e18761e3d62cb5e85588)
@@ -0,0 +1,20 @@
+#! /bin/sh
+
+# Script that is executed whenever a new company is created in the
+# external user source, such as an Active Directory tree or
+# /etc/passwd.
+
+# This script executes all scripts in /etc/kopano/userscripts/createcompany.d
+# using find.  The environment variable KOPANO_COMPANY is set, but
+# beware that this string can contain any characters, so take heed to
+# correct quoting.
+
+if [ -f /usr/etc/sysconfig/kopano ]; then
+  . /usr/etc/sysconfig/kopano
+elif [ -f /usr/etc/default/kopano ]; then
+  # Used on Debian in place of sysconfig
+  . /usr/etc/default/kopano
+fi
+PKGLIBEXECDIR=/usr/libexec/kopano
+KOPANO_COMPANY_SCRIPTS=/etc/kopano/userscripts/createcompany.d
+. /etc/kopano/userscripts/companies_common.sh
Index: npl/mailserver/kopano_conf/root/etc/kopano/userscripts/createcompany.d/00createpublic
===================================================================
--- npl/mailserver/kopano_conf/root/etc/kopano/userscripts/createcompany.d/00createpublic	(revision a2d969e7ad0485dba4b6e18761e3d62cb5e85588)
+++ npl/mailserver/kopano_conf/root/etc/kopano/userscripts/createcompany.d/00createpublic	(revision a2d969e7ad0485dba4b6e18761e3d62cb5e85588)
@@ -0,0 +1,10 @@
+#! /bin/sh
+
+# Create a public store for the new company.
+
+PATH=$PATH:/sbin:/usr/local/sbin:/usr/sbin
+
+# The KOPANO_COMPANY variable from the server will always be in UTF-8
+# format.  The --utf8 option must be set before this value is used,
+# since the current locale isn't necessarily UTF-8.
+kopano-admin -v --utf8 -s -I "${KOPANO_COMPANY}"
Index: npl/mailserver/kopano_conf/root/etc/kopano/userscripts/creategroup
===================================================================
--- npl/mailserver/kopano_conf/root/etc/kopano/userscripts/creategroup	(revision a2d969e7ad0485dba4b6e18761e3d62cb5e85588)
+++ npl/mailserver/kopano_conf/root/etc/kopano/userscripts/creategroup	(revision a2d969e7ad0485dba4b6e18761e3d62cb5e85588)
@@ -0,0 +1,19 @@
+#! /bin/sh
+
+# Script that is executed whenever a new group is created in the
+# external user source, such as an Active Directory tree or
+# /etc/passwd.
+
+# This script executes all scripts in /etc/kopano/userscripts/creategroup.d
+# using find.  The environment variable KOPANO_GROUP is set, but
+# beware that this string can contain any characters, so take heed to
+# correct quoting.
+
+if [ -f /usr/etc/sysconfig/kopano ]; then
+  . /usr/etc/sysconfig/kopano
+elif [ -f /usr/etc/default/kopano ]; then
+  . /usr/etc/default/kopano
+fi
+PKGLIBEXECDIR=/usr/libexec/kopano
+KOPANO_GROUP_SCRIPTS=/etc/kopano/userscripts/creategroup.d
+. /etc/kopano/userscripts/groups_common.sh
Index: npl/mailserver/kopano_conf/root/etc/kopano/userscripts/createuser
===================================================================
--- npl/mailserver/kopano_conf/root/etc/kopano/userscripts/createuser	(revision a2d969e7ad0485dba4b6e18761e3d62cb5e85588)
+++ npl/mailserver/kopano_conf/root/etc/kopano/userscripts/createuser	(revision a2d969e7ad0485dba4b6e18761e3d62cb5e85588)
@@ -0,0 +1,19 @@
+#! /bin/sh
+
+# Script that is executed whenever a new user is created in the
+# external user source, such as an Active Directory tree or
+# /etc/passwd.
+
+# This script executes all scripts in /etc/kopano/userscripts/createuser.d
+# using find.  The environment variable KOPANO_USER is set, but
+# beware that this string can contain any characters, so take heed to
+# correct quoting.
+
+if [ -f /usr/etc/sysconfig/kopano ]; then
+  . /usr/etc/sysconfig/kopano
+elif [ -f /usr/etc/default/kopano ]; then
+  . /usr/etc/default/kopano
+fi
+PKGLIBEXECDIR=/usr/libexec/kopano
+KOPANO_USER_SCRIPTS=/etc/kopano/userscripts/createuser.d
+. /etc/kopano/userscripts/users_common.sh
Index: npl/mailserver/kopano_conf/root/etc/kopano/userscripts/createuser.d/00createstore
===================================================================
--- npl/mailserver/kopano_conf/root/etc/kopano/userscripts/createuser.d/00createstore	(revision a2d969e7ad0485dba4b6e18761e3d62cb5e85588)
+++ npl/mailserver/kopano_conf/root/etc/kopano/userscripts/createuser.d/00createstore	(revision a2d969e7ad0485dba4b6e18761e3d62cb5e85588)
@@ -0,0 +1,11 @@
+#! /bin/sh
+
+# Create a Kopano user for an already existing external user.  Create
+# and initialize the user's stores.
+
+PATH=$PATH:/sbin:/usr/local/sbin:/usr/sbin
+
+# The KOPANO_USER variable from the server will always be in UTF-8
+# format.  The --utf8 option must be set before this value is used,
+# since the current locale isn't necessarily UTF-8.
+kopano-admin -v --utf8 --create-store "${KOPANO_USER}" --lang "${KOPANO_LANG}"
Index: npl/mailserver/kopano_conf/root/etc/kopano/userscripts/deletecompany
===================================================================
--- npl/mailserver/kopano_conf/root/etc/kopano/userscripts/deletecompany	(revision a2d969e7ad0485dba4b6e18761e3d62cb5e85588)
+++ npl/mailserver/kopano_conf/root/etc/kopano/userscripts/deletecompany	(revision a2d969e7ad0485dba4b6e18761e3d62cb5e85588)
@@ -0,0 +1,19 @@
+#! /bin/sh
+
+# Script that is executed whenever a new company is deleted from
+# the external user source, such as an Active Directory tree or
+# /etc/passwd.
+
+# This script executes all scripts in /etc/kopano/userscripts/deletecompany.d
+# using find.  The environment variable KOPANO_COMPANY is set, but
+# beware that this string can contain any characters, so take heed to
+# correct quoting.
+
+if [ -f /usr/etc/sysconfig/kopano ]; then
+  . /usr/etc/sysconfig/kopano
+elif [ -f /usr/etc/default/kopano ]; then
+  . /usr/etc/default/kopano
+fi
+PKGLIBEXECDIR=/usr/libexec/kopano
+KOPANO_COMPANY_SCRIPTS=/etc/kopano/userscripts/deletecompany.d
+. /etc/kopano/userscripts/companies_common.sh
Index: npl/mailserver/kopano_conf/root/etc/kopano/userscripts/deletegroup
===================================================================
--- npl/mailserver/kopano_conf/root/etc/kopano/userscripts/deletegroup	(revision a2d969e7ad0485dba4b6e18761e3d62cb5e85588)
+++ npl/mailserver/kopano_conf/root/etc/kopano/userscripts/deletegroup	(revision a2d969e7ad0485dba4b6e18761e3d62cb5e85588)
@@ -0,0 +1,19 @@
+#! /bin/sh
+
+# Script that is executed whenever a new group is deleted from
+# the external user source, such as an Active Directory tree or
+# /etc/passwd.
+
+# This script executes all scripts in /etc/kopano/userscripts/deletegroup.d
+# using find.  The environment variable KOPANO_GROUP is set, but
+# beware that this string can contain any characters, so take heed to
+# correct quoting.
+
+if [ -f /usr/etc/sysconfig/kopano ]; then
+  . /usr/etc/sysconfig/kopano
+elif [ -f /usr/etc/default/kopano ]; then
+  . /usr/etc/default/kopano
+fi
+PKGLIBEXECDIR=/usr/libexec/kopano
+KOPANO_GROUP_SCRIPTS=/etc/kopano/userscripts/deletegroup.d
+. /etc/kopano/userscripts/groups_common.sh
Index: npl/mailserver/kopano_conf/root/etc/kopano/userscripts/deleteuser
===================================================================
--- npl/mailserver/kopano_conf/root/etc/kopano/userscripts/deleteuser	(revision a2d969e7ad0485dba4b6e18761e3d62cb5e85588)
+++ npl/mailserver/kopano_conf/root/etc/kopano/userscripts/deleteuser	(revision a2d969e7ad0485dba4b6e18761e3d62cb5e85588)
@@ -0,0 +1,19 @@
+#! /bin/sh
+
+# Script that is executed whenever a new user is deleted from
+# the external user source, such as an Active Directory tree or
+# /etc/passwd.
+
+# This script executes all scripts in /etc/kopano/userscripts/deleteuser.d
+# using find.  The environment variable KOPANO_USER is set, but beware
+# that this string can contain any characters, so take heed to correct
+# quoting.
+
+if [ -f /usr/etc/sysconfig/kopano ]; then
+  . /usr/etc/sysconfig/kopano
+elif [ -f /usr/etc/default/kopano ]; then
+  . /usr/etc/default/kopano
+fi
+PKGLIBEXECDIR=/usr/libexec/kopano
+KOPANO_USER_SCRIPTS=/etc/kopano/userscripts/deleteuser.d
+. /etc/kopano/userscripts/users_common.sh
Index: npl/mailserver/kopano_conf/root/etc/kopano/userscripts/groups_common.sh
===================================================================
--- npl/mailserver/kopano_conf/root/etc/kopano/userscripts/groups_common.sh	(revision a2d969e7ad0485dba4b6e18761e3d62cb5e85588)
+++ npl/mailserver/kopano_conf/root/etc/kopano/userscripts/groups_common.sh	(revision a2d969e7ad0485dba4b6e18761e3d62cb5e85588)
@@ -0,0 +1,24 @@
+# shell include script
+
+KOPANO_LANG="${KOPANO_USERSCRIPT_LOCALE:-${LC_MESSAGES:-en_US}}"
+PATH=/bin:/usr/local/bin:/usr/bin
+export KOPANO_LANG PATH
+
+if [ -z "${KOPANO_GROUP_SCRIPTS}" ] ; then
+    exec >&2
+    echo "Do not execute this script directly"
+    exit 1
+fi
+
+if [ ! -d "${KOPANO_GROUP_SCRIPTS}" ] ; then
+    exec >&2
+    echo "${KOPANO_GROUP_SCRIPTS} does not exist or is not a directory"
+    exit 1
+fi
+
+if [ -z "${KOPANO_GROUP}" -a -z "${KOPANO_GROUPID}" ] ; then
+    exec >&2
+    echo "KOPANO_GROUP and KOPANO_GROUPID is not set."
+    exit 1
+fi
+exec "$PKGLIBEXECDIR/kscriptrun" "$KOPANO_GROUP_SCRIPTS"
Index: npl/mailserver/kopano_conf/root/etc/kopano/userscripts/users_common.sh
===================================================================
--- npl/mailserver/kopano_conf/root/etc/kopano/userscripts/users_common.sh	(revision a2d969e7ad0485dba4b6e18761e3d62cb5e85588)
+++ npl/mailserver/kopano_conf/root/etc/kopano/userscripts/users_common.sh	(revision a2d969e7ad0485dba4b6e18761e3d62cb5e85588)
@@ -0,0 +1,24 @@
+# shell include script
+
+KOPANO_LANG="${KOPANO_USERSCRIPT_LOCALE:-${LC_MESSAGES:-C}}"
+PATH=/bin:/usr/local/bin:/usr/bin
+export KOPANO_LANG PATH
+
+if [ -z "${KOPANO_USER_SCRIPTS}" ] ; then
+    exec >&2
+    echo "Do not execute this script directly"
+    exit 1
+fi
+
+if [ ! -d "${KOPANO_USER_SCRIPTS}" ] ; then
+    exec >&2
+    echo "${KOPANO_USER_SCRIPTS} does not exist or is not a directory"
+    exit 1
+fi
+
+if [ -z "${KOPANO_USER}" -a -z "${KOPANO_STOREGUID}" ] ; then
+    exec >&2
+    echo "KOPANO_USER and KOPANO_STOREGUID is not set."
+    exit 1
+fi
+exec "$PKGLIBEXECDIR/kscriptrun" "$KOPANO_USER_SCRIPTS"
