You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
2.7 KiB

  1. #!/bin/bash
  2. . lib/common
  3. set -e
  4. ## If no admin-password set, then don't try to pre-initialize database
  5. admin_password=$(options-get admin-password 2>/dev/null) || exit 0
  6. admin_email=$(options-get admin-email 2>/dev/null ) || true
  7. CONTROL="$SERVICE_DATASTORE/.control"
  8. ## Was it already properly propagated to database ?
  9. control=$(H "${admin_password}" "${admin_email}")
  10. if [ -e "$CONTROL" ]; then
  11. if [ "$control" == "$(cat "$CONTROL")" ]; then
  12. exit 0
  13. else
  14. err "Changing admin password in compose file not yet supported"
  15. exit 1
  16. fi
  17. fi
  18. ##
  19. ## Get domain in option of relation "publish-dir"
  20. ##
  21. if ! url=$(relation:get "$SERVICE_NAME":publish-dir url) || [ -z "$url" ]; then
  22. err "Couldn't get ${WHITE}url${NORMAL} information in ${DARKCYAN}publish-dir${NORMAL} relation's data."
  23. exit 1
  24. fi
  25. protocol="${url%%://*}"
  26. domain="${url#$protocol://}"
  27. domain="${domain%%/*}"
  28. ##
  29. ## We are in post_deploy, so our service is up, we need to get
  30. ## the ``network`` and ``container``'s id to communicate with
  31. ## him.
  32. ##
  33. container_id=$(
  34. for container_id in $(get_running_containers_for_service "$MASTER_BASE_SERVICE_NAME"); do
  35. e "$container_id"
  36. break
  37. done
  38. )
  39. admin_email=${admin_email:-"admin@$domain"}
  40. read-0 network container_ip < <(get_container_network_ip "$container_id")
  41. debug "Running index.php/project/initialize"
  42. echo docker run --network "$network" docker.0k.io/curl -k -s -X POST -H "Host: $domain" -L \
  43. -F sonata_user_registration[username]="admin" \
  44. -F sonata_user_registration[email]="$admin_email" \
  45. -F sonata_user_registration[plainPassword][first]="$admin_password" \
  46. -F sonata_user_registration[plainPassword][second]="$admin_password" \
  47. "$protocol://$container_ip/index.php/project/initialize"
  48. out=$(docker run --network "$network" docker.0k.io/curl -k -s -X POST -H "Host: $domain" -L \
  49. -F sonata_user_registration[username]="admin" \
  50. -F sonata_user_registration[email]="$admin_email" \
  51. -F sonata_user_registration[plainPassword][first]="$admin_password" \
  52. -F sonata_user_registration[plainPassword][second]="$admin_password" \
  53. "$protocol://$container_ip/index.php/project/initialize") || {
  54. err "Failed to run project/initialize script"
  55. echo "$out"
  56. exit 1
  57. }
  58. # #e "$out" > "$SERVICE_DATASTORE/out.html"
  59. # # debug "written $SERVICE_DATASTORE/out.html"
  60. # had_error=
  61. # while read-0 error_msg; do
  62. # had_error=1
  63. # err "Installation failed with these errors:"
  64. # echo "- ${error_msg}" >&2
  65. # done < <(e "$out" | xpath "//div[@class='errors']/ul/li/text()")
  66. # if [ "$had_error" ]; then
  67. # exit 1
  68. # fi
  69. # debug "No error catched on \`\`install.php\`\` result."
  70. # e "$control" > "$CONTROL"
  71. exit 0