瀏覽代碼

Split users addition out from deploy script

So it can be called independently.
multi_domain
ßingen 8 年之前
父節點
當前提交
8125dadcb2
共有 2 個檔案被更改,包括 49 行新增37 行删除
  1. +48
    -0
      add_users.sh
  2. +1
    -37
      deploy.sh

+ 48
- 0
add_users.sh 查看文件

@@ -0,0 +1,48 @@
#!/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 Running | grep openldap | awk '{ print $4 }')
#echo Host=$host
if [ -z $host ]; then
echo "No host found!";
exit 1;
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
scp -r images/rpi-openldap/users $host:/tmp/

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"

+ 1
- 37
deploy.sh 查看文件

@@ -29,40 +29,4 @@ sleep 60

# ##### Add users to LDAP ###### #

host=$(docker stack ps ${STACK_NAME} | grep Running | grep openldap | awk '{ print $4 }')
#echo Host=$host
if [ -z $host ]; then
echo "No host found!";
exit 1;
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
scp -r images/rpi-openldap/users $host:/tmp/

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"
./add_users.sh ${STACK_NAME}

Loading…
取消
儲存