Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

50 rindas
1.4KB

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