module/gerrit: add support for hooks
diff --git a/module/compose/scheme.sh b/module/compose/scheme.sh
index 0002fae..1310cf5 100644
--- a/module/compose/scheme.sh
+++ b/module/compose/scheme.sh
@@ -67,12 +67,16 @@
       - ${_GERRIT_DKRC_ROOTFS_}/index:/var/gerrit/index
       - ${_GERRIT_DKRC_ROOTFS_}/cache:/var/gerrit/cache
       - ${_GERRIT_DKRC_ROOTFS_}/git:/var/gerrit/git
+      - ${_GERRIT_DKRC_HOOKS_D_}:${_GERRIT_HOOKS_CON_D_}
       - ${_GERRIT_DKRC_ETC_D_}:/var/gerrit/etc
       - ${_GERRIT_LOGS_D_}:/var/gerrit/logs
 ${compose_has_secure_store}
     environment:
       - CANONICAL_WEB_URL=${_GERRIT_CANON_URL_}
       - LISTEN_URL=${_GERRIT_LISTEN_URL_}
+      - HOOKS_REMOTE_ALIAS=${_GERRIT_HOOKS_REMOTE_NAME_}
+      - HOOKS_REMOTE_HOST=${_APACHE_DKRC_FRONTEND_IP_}
+      - HOOKS_LOG_DIR=${_GERRIT_HOOKS_LOG_CON_D_}
     depends_on:
       - ${_APACHE_DKRC_SERVICE_}
     networks:
diff --git a/module/gerrit/holder.sh b/module/gerrit/holder.sh
index eaf939d..df60f71 100644
--- a/module/gerrit/holder.sh
+++ b/module/gerrit/holder.sh
@@ -33,6 +33,10 @@
 _GERRIT_DKRC_ROOTFS_="${mod_rootfs_d}"
 _GERRIT_DKRC_ETC_D_="${etc_d}"
 _GERRIT_LOGS_D_="$logs_d"
+_GERRIT_DKRC_HOOKS_D_="${hooks_d}"
+_GERRIT_HOOKS_CON_D_="/var/gerrit/hooks"
+_GERRIT_HOOKS_REMOTE_NAME_="${_GERRIT_DKRC_SERVICE_}"
+_GERRIT_HOOKS_LOG_CON_D_="/var/gerrit/logs"
 if [ "$gerrit_has_https" -eq 1 ]; then
 	_GERRIT_HAS_HTTPS_="1"
 	_GERRIT_DKRC_KEYSTORE_F_="${keystore_f}"
diff --git a/module/gerrit/module.sh b/module/gerrit/module.sh
index 38ecfaa..1edc3b2 100644
--- a/module/gerrit/module.sh
+++ b/module/gerrit/module.sh
@@ -29,6 +29,8 @@
 
 declare -r etc_d="$mod_rootfs_d/etc"
 declare -r logs_d="$mod_rootfs_d/var/log/gerrit"
+declare -r hooks_d="$mod_rootfs_d/hooks"
+declare -r hooks_mir="gerrit-hooks.git"
 
 declare -r keystore="$host_name.keystore"
 declare -r keystore_pkcs12="$host_name.pkcs12.keystore"
@@ -63,7 +65,7 @@
 # Staged resources
 declare -r war_f="$mod_staging_d/gerrit-$war_version.war"
 
-declare -ar mod_more_dirs=( $etc_d $logs_d )
+declare -ar mod_more_dirs=( $etc_d $logs_d $hooks_d )
 declare -ar mod_more_files=( $config_f $secure_f $entrypoint_f $dockerfile_f $gerrit_cli_f )
 declare -ar mod_more_trefs=( config_t secure_t entrypoint_bang_t dockerfile_t gerrit_cli_bang_t )
 
@@ -120,6 +122,7 @@
 {
 	__fetch_module_common || return $s_err
 	__gerrit_do_keystore  || return $s_err
+	__gerrit_do_hooks     || return $s_err
 }
 
 function __gerrit_do_lock
@@ -260,3 +263,16 @@
 	sudo cp $mod_staging_d/$keystore_pkcs12 $keystore_f || return $s_err
 	sudo chmod 0600 $keystore_f && sudo chown root:root $keystore_f
 }
+
+function __gerrit_do_hooks
+{
+	if [ ! -d "$mod_staging_d/$hooks_mir" ]; then
+		lets -l -w "$hooks_mir not found, not installing hooks"
+		return $s_ok
+	fi
+
+	sudo cp -ar --preserve=all $mod_staging_d/$hooks_mir/* $hooks_d/ || {
+		lets -l -e "failed to install hooks"
+		return $s_err
+	}
+}
diff --git a/module/gerrit/scheme.sh b/module/gerrit/scheme.sh
index 3a066ce..04932ee 100644
--- a/module/gerrit/scheme.sh
+++ b/module/gerrit/scheme.sh
@@ -98,6 +98,9 @@
 [receive]
 	enableSignedPush = false
 
+[hooks]
+	path = ${_GERRIT_HOOKS_CON_D_}
+
 ${config_t_has_secure_config}"
 
 # secure.config isn't part of the instance create/update process, however