-
Notifications
You must be signed in to change notification settings - Fork 3
/
add_users.sh
executable file
·55 lines (45 loc) · 1.49 KB
/
add_users.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
STACK_NAME=$1
if [ $# -eq 0 ]; then
echo "You must pass stack name as a parameter"
exit 1
fi
# ##### Add users to LDAP ###### #
host=$(docker stack ps ${STACK_NAME} | grep -v Shutdown | grep Running | grep openldap | awk '{ print $4 }')
#echo Host=$host
if [ -z $host ]; then
echo "No host found!";
exit 1;
fi
# add avahi suffix
localhostname=$(cat /etc/hostname)
if [ "${localhostname}" != "${host}" ]; then
host=${host}.local
fi
container=$(ssh $host 'docker ps | grep openldap | cut -f1 -d" "')
#echo Container=$container
if [ -z $container ]; then
echo "Qué me estás container?!";
exit 1;
fi
# read variables, for mail data path
. .env
# Replace Mail data path for users
find images/rpi-openldap/users -type f -exec \
sed -i "s/\${MAIL_DATA_PATH}/${MAIL_DATA_PATH//\//\\/}/g" {} \;
echo Copying user files to Host $host
ssh $host "mkdir -p /tmp/users"
scp -r images/rpi-openldap/users/userimport*.ldif $host:/tmp/users/
echo Copying user files to Container $container in Host $host
ssh $host "docker cp /tmp/users $container:/tmp/"
echo Adding users to openldap
ssh $host \
"for i in \$(ls /tmp/users/userimport*.ldif); do \
ls \$i;
docker exec ${container} sh -c \
'slapadd -l '\$i; \
done;"
#'ldapadd -w \$(cat \${LDAP_ADMIN_PWD_FILE}) -D cn=admin,dc=\${LDAP_ORGANIZATION},dc=\${LDAP_EXTENSION} -f '\$i; \
echo Removing copied user files
ssh $host "docker exec ${container} sh -c 'rm -Rf /tmp/users'"
ssh $host "rm -Rf /tmp/users"