Skip to content

Commit

Permalink
Add post startup script to create shared roster groups and add member…
Browse files Browse the repository at this point in the history
  • Loading branch information
rcoup authored and rroemhild committed Oct 11, 2017
1 parent df21b8e commit e8f1ed9
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,20 @@ Register more than one user:
EJABBERD_USERS=admin@example.ninja:password1234 user1@test.com user1@xyz.io
```

## Shared Roster Groups

Automatically create roster groups and register users during container startup. To create shared roster groups, separate with whitespace:

```
EJABBERD_GROUPS=group1@example.ninja group2@test.com
```

To add users to shared roster groups, separate with whitespace:

```
EJABBERD_GROUP_MEMBERS=admin@example.ninja:group1@example.ninja user1@test.com:group2@test.com
```

## SSL
- **EJABBERD_SKIP_MAKE_SSLCERT**: Skip generating ssl certificates. Default: false
- **EJABBERD_SSLCERT_HOST**: SSL Certificate for the hostname.
Expand Down
1 change: 1 addition & 0 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ run_scripts() {
local run_script_dir="${EJABBERD_HOME}/scripts/${1}"
for script in ${run_script_dir}/*.sh ; do
if [ -f ${script} -a -x ${script} ] ; then
echo "${script}..."
${script}
fi
done
Expand Down
78 changes: 78 additions & 0 deletions scripts/post/30_ejabberd_setup_groups.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/bin/bash
set -e

source "${EJABBERD_HOME}/scripts/lib/base_config.sh"
source "${EJABBERD_HOME}/scripts/lib/config.sh"
source "${EJABBERD_HOME}/scripts/lib/base_functions.sh"
source "${EJABBERD_HOME}/scripts/lib/functions.sh"


create_group() {
local group=$1
local host=$2

echo "Creating roster group: ${group}@${host}"
# Do not exit if group already registered
${EJABBERDCTL} srg_create ${group} ${host} ${group} '' ${group} || true
}

register_group_member() {
local user=$1
local host=$2
local group=$1
local grouphost=$2

echo "Adding ${user} ${host} to roster group ${group}@${grouphost}"
# Do not exit if user is already a member
${EJABBERDCTL} srg_user_add ${user} ${host} ${group} ${grouphost} || true
}


register_all_groups() {
# register shared roster groups from environment $EJABBERD_GROUPS
# Use whitespace to seperate groups.
#
# sample:
# - create two groups:
# -e "EJABBERD_GROUPS=admin@example.com test@example.com"
for group in ${EJABBERD_GROUPS} ; do
local name=${group%%@*}
local host=${group#*@}

create_group ${name} ${host}
done
}

register_all_group_members() {
# register shared roster group members from environment $EJABBERD_GROUP_MEMBERS
# Use whitespace to seperate groups.
#
# sample:
# - add two users to groups:
# -e "EJABBERD_GROUP_MEMBERS=user@xmpp.kx.gd:group@xmpp.kx.gd user2@xmpp.kx.gd:group@xmpp.kx.gd"

for member in ${EJABBERD_GROUP_MEMBERS} ; do
local user=${member%%:*}
local group=${user#*:}

local username=${user%%@*}
local userhost=${user#*@}

local groupname=${group%%@*}
local grouphost=${group#*@}

register_group_member ${username} ${userhost} ${groupname} ${grouphost}
done
}


file_exist ${FIRST_START_DONE_FILE} \
&& exit 0

is_set ${EJABBERD_GROUPS} \
&& register_all_groups

is_set ${EJABBERD_GROUP_MEMBERS} \
&& register_all_group_members

exit 0

0 comments on commit e8f1ed9

Please sign in to comment.