forked from rroemhild/docker-ejabberd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add post startup script to create shared roster groups and add member…
…s. (rroemhild#112)
- Loading branch information
Showing
3 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |