aboutsummaryrefslogtreecommitdiff
path: root/docker/post
diff options
context:
space:
mode:
authorRafael Römhild <r.roemhild@s-v.de>2016-11-11 00:12:54 +0100
committerChristophe Romain <christophe.romain@process-one.net>2016-11-16 11:48:50 +0100
commit5a01b5f1fc991044920a84bf97959c2e4c21b7d2 (patch)
tree696255307a36e0b0708c30ca82d42834bcfc6940 /docker/post
parentMinor cosmetic changes on pubsub code (diff)
add docker support
Diffstat (limited to 'docker/post')
-rwxr-xr-xdocker/post/10_ejabberd_modules_update_specs.sh24
-rwxr-xr-xdocker/post/11_ejabberd_install_modules.sh144
-rwxr-xr-xdocker/post/20_ejabberd_register_users.sh72
-rwxr-xr-xdocker/post/99_first_start_done.sh17
4 files changed, 257 insertions, 0 deletions
diff --git a/docker/post/10_ejabberd_modules_update_specs.sh b/docker/post/10_ejabberd_modules_update_specs.sh
new file mode 100755
index 000000000..9e916016a
--- /dev/null
+++ b/docker/post/10_ejabberd_modules_update_specs.sh
@@ -0,0 +1,24 @@
+#!/bin/bash
+set -e
+
+# Updates the known modules as to be found in https://github.com/processone/ejabberd-contrib
+
+source "${EJABBERD_HOME}/docker/lib/base_config.sh"
+source "${EJABBERD_HOME}/docker/lib/config.sh"
+source "${EJABBERD_HOME}/docker/lib/base_functions.sh"
+source "${EJABBERD_HOME}/docker/lib/functions.sh"
+
+
+run_modules_update_specs() {
+ log "Updating module specs... "
+ ${EJABBERDCTL} modules_update_specs
+}
+
+
+is_true ${EJABBERD_SKIP_MODULES_UPDATE} \
+ && exit 0
+
+run_modules_update_specs
+
+
+exit 0
diff --git a/docker/post/11_ejabberd_install_modules.sh b/docker/post/11_ejabberd_install_modules.sh
new file mode 100755
index 000000000..2dd4f3922
--- /dev/null
+++ b/docker/post/11_ejabberd_install_modules.sh
@@ -0,0 +1,144 @@
+#!/bin/bash
+set -e
+
+# Installs modules as defined in environment variables
+
+source "${EJABBERD_HOME}/docker/lib/base_config.sh"
+source "${EJABBERD_HOME}/docker/lib/config.sh"
+source "${EJABBERD_HOME}/docker/lib/base_functions.sh"
+source "${EJABBERD_HOME}/docker/lib/functions.sh"
+
+
+install_module_from_source() {
+ local module_name=$1
+ local module_source_path=${EJABBERD_HOME}/module_source/${module_name}
+ local module_install_folder=${EJABBERD_HOME}/.ejabberd-modules/sources/${module_name}
+
+ log "Analyzing module ${module_name} for installation"
+ # Make sure that the module exists in the source folder before attempting a copy
+
+ if [ ! -d ${module_source_path} ]; then
+ log "Error: Module ${module_name} not found in ${EJABBERD_HOME}/module_source"
+ log "Please use a shared volume to populate your module in ${EJABBERD_HOME}/module_source"
+ return 1;
+ fi
+
+ # Check to see if the module is already installed
+ local install_count=$(${EJABBERDCTL} modules_installed | grep -ce "^${module_name}[[:space:]]")
+ if [ $install_count -gt 0 ]; then
+ log "Error: Module already installed: ${module_name}"
+ return 1;
+ fi
+
+ # Copy the module into the shared folder
+ log "Copying module to ejabberd folder ${module_install_folder}"
+ mkdir -p ${module_install_folder}
+ cp -R ${module_source_path} ${module_install_folder}
+
+ # Run the ejabberdctl module_check on the module
+ log "Running module_check on ${module_name}"
+ ${EJABBERDCTL} module_check ${module_name}
+ if [ $? -ne 0 ]; then
+ log "Module check failed for ${module_name}"
+ return 1;
+ fi
+ log "Module check succeeded for ${module_name}"
+
+ # Install the module
+ log "Running module_install on ${module_name}"
+ ${EJABBERDCTL} module_install ${module_name}
+ if [ $? -ne 0 ]; then
+ log "Module installation failed for ${module_name}"
+ return 1;
+ fi
+ log "Module installation succeeded for ${module_name}"
+
+ return 0;
+}
+
+install_module_from_ejabberd_contrib() {
+ local module_name=$1
+
+ # Check to see if the module is already installed
+ local install_count=$(${EJABBERDCTL} modules_installed | grep -ce "^${module_name}[[:space:]]")
+ if [ $install_count -gt 0 ]; then
+ log "Error: Module already installed: ejabberd_contrib ${module_name}"
+ return 1;
+ fi
+
+ # Install the module
+ log "Running module_install on ejabberd_contrib ${module_name}"
+ ${EJABBERDCTL} module_install ${module_name}
+ if [ $? -ne 0 ]; then
+ log "Module installation failed for ejabberd_contrib ${module_name}"
+ return 1;
+ fi
+ log "Module installation succeeded for ejabberd_contrib ${module_name}"
+
+ return 0;
+}
+
+enable_custom_auth_module_override() {
+ module_name=$1;
+ # When using custom authentication modules, the module name must be
+ # in the following pattern: ejabberd_auth_foo, where foo is the
+ # value you will use for your auth_method yml configuration.
+ required_prefix="ejabberd_auth_"
+
+ if [[ "${module_name}" != "${required_prefix}"* ]]; then
+ log "Error: module_name must begin with ${required_prefix}"
+ exit 1;
+ fi
+
+ log "Checking custom auth module: ${module_name}"
+ # Make sure the auth module is installed
+ local install_count=$(${EJABBERDCTL} modules_installed | grep -ce "^${module_name}[[:space:]]")
+ if [ $install_count -eq 0 ]; then
+ log "Error: custom auth_module not installed: ${module_name}"
+ return 1;
+ fi
+
+ custom_auth_method=${module_name#$required_prefix}
+ echo -e "\nauth_method: [${custom_auth_method}]" >> ${CONFIGFILE}
+ log "Custom auth module ${module_name} configuration complete."
+}
+
+file_exist ${FIRST_START_DONE_FILE} \
+ && exit 0
+
+is_restart_needed=0;
+
+if [ -n "${EJABBERD_SOURCE_MODULES}" ]; then
+ for module_name in ${EJABBERD_SOURCE_MODULES} ; do
+ install_module_from_source ${module_name}
+ done
+ is_restart_needed=1;
+fi
+
+# Check the EJABBERD_CONTRIB_MODULES variable for any ejabberd_contrib modules
+if [ -n "${EJABBERD_CONTRIB_MODULES}" ]; then
+ for module_name in ${EJABBERD_CONTRIB_MODULES} ; do
+ install_module_from_ejabberd_contrib ${module_name}
+ done
+ is_restart_needed=1;
+fi
+
+# If a custom module was defined for handling auth, we need to override
+# the pre-defined auth methods in the config.
+if [ -n "${EJABBERD_CUSTOM_AUTH_MODULE_OVERRIDE}" ]; then
+ enable_custom_auth_module_override "${EJABBERD_CUSTOM_AUTH_MODULE_OVERRIDE}"
+ is_restart_needed=1;
+fi
+
+# If any modules were installed, restart the server, if the option is enabled
+if [ ${is_restart_needed} -eq 1 ]; then
+ if is_true ${EJABBERD_RESTART_AFTER_MODULE_INSTALL} ; then
+ log "Restarting ejabberd after successful module installation(s)"
+ ${EJABBERDCTL} restart
+ child=$!
+ ${EJABBERDCTL} "started"
+ wait $child
+ fi
+fi
+
+exit 0
diff --git a/docker/post/20_ejabberd_register_users.sh b/docker/post/20_ejabberd_register_users.sh
new file mode 100755
index 000000000..9dc910eeb
--- /dev/null
+++ b/docker/post/20_ejabberd_register_users.sh
@@ -0,0 +1,72 @@
+#!/bin/bash
+set -e
+
+source "${EJABBERD_HOME}/docker/lib/base_config.sh"
+source "${EJABBERD_HOME}/docker/lib/config.sh"
+source "${EJABBERD_HOME}/docker/lib/base_functions.sh"
+source "${EJABBERD_HOME}/docker/lib/functions.sh"
+
+# Do not exit if users already registered
+set +e
+
+randpw() {
+ < /dev/urandom tr -dc A-Z-a-z-0-9 | head -c ${1:-16};
+ echo;
+}
+
+
+register_user() {
+ local user=$1
+ local domain=$2
+ local password=$3
+
+ ${EJABBERDCTL} register ${user} ${domain} ${password}
+ return $?
+}
+
+
+register_all_users() {
+ # register users from environment $EJABBERD_USERS with given
+ # password or random password written to stout. Use whitespace
+ # to seperate users.
+ #
+ # sample:
+ # - add a user with an given password:
+ # -e "EJABBERD_USERS=admin@example.com:adminSecret"
+ # - add a user with a random password:
+ # -e "EJABBERD_USERS=user@example.com"
+ # - set password for admin and use random for user1:
+ # -e "EJABBERD_USERS=admin@example.com:adminSecret user@example.com"
+
+ for user in ${EJABBERD_USERS} ; do
+ local jid=${user%%:*}
+ local password=${user#*:}
+
+ local username=${jid%%@*}
+ local domain=${jid#*@}
+
+ [[ "${password}" == "${jid}" ]] \
+ && password=$(randpw)
+
+ register_user ${username} ${domain} ${password}
+ local retval=$?
+
+ [[ ${retval} -eq 0 ]] \
+ && log "Password for user ${username}@${domain} is ${password}"
+ done
+}
+
+
+file_exist ${FIRST_START_DONE_FILE} \
+ && exit 0
+
+
+file_exist ${CLUSTER_NODE_FILE} \
+ && exit 0
+
+
+is_set ${EJABBERD_USERS} \
+ && register_all_users
+
+
+exit 0
diff --git a/docker/post/99_first_start_done.sh b/docker/post/99_first_start_done.sh
new file mode 100755
index 000000000..394531cf6
--- /dev/null
+++ b/docker/post/99_first_start_done.sh
@@ -0,0 +1,17 @@
+#!/bin/bash
+set -e
+
+# Write a first-start-done file
+
+source "${EJABBERD_HOME}/docker/lib/base_config.sh"
+source "${EJABBERD_HOME}/docker/lib/config.sh"
+source "${EJABBERD_HOME}/docker/lib/base_functions.sh"
+source "${EJABBERD_HOME}/docker/lib/functions.sh"
+
+
+if [ ! -e "${FIRST_START_DONE_FILE}" ]; then
+ touch ${FIRST_START_DONE_FILE}
+fi
+
+
+exit 0