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.

116 lines
3.4 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. ## XXXvlab: there is a tiny lapse of time where database is not yet
  22. ## installed, and admin password is the default value.
  23. ## XXXvlab: can't get real config here
  24. if ! read-0 publish_dir_ts _ _ < <(get_service_relation "$SERVICE_NAME" "publish-dir"); then
  25. err "Couldn't find relation ${DARKCYAN}publish-dir${NORMAL}."
  26. exit 1
  27. fi
  28. publish_dir_relation_dir=$(get_relation_data_dir "$SERVICE_NAME" "$publish_dir_ts" "publish-dir") || {
  29. err "Failed to find relation file"
  30. exit 1
  31. }
  32. publish_dir_relation_config=$(cat "$publish_dir_relation_dir/data") || exit 2
  33. domain=$(e "$publish_dir_relation_config" | shyaml get-value domain) || {
  34. err "Couldn't get domain information in ${DARKCYAN}publish-dir${NORMAL} relation's data."
  35. exit 1
  36. }
  37. url=$(e "$publish_dir_relation_config" | shyaml get-value url) || {
  38. err "Couldn't get domain information in ${DARKCYAN}publish-dir${NORMAL} relation's data."
  39. exit 1
  40. }
  41. protocol="${url%%://*}"
  42. ##
  43. ## We are in post_deploy, so our service is up, we need to get
  44. ## the ``network`` and ``container``'s id to communicate with
  45. ## him.
  46. ##
  47. container_id=$(
  48. for container_id in $(get_running_containers_for_service "$MASTER_BASE_SERVICE_NAME"); do
  49. e "$container_id"
  50. break
  51. done
  52. )
  53. admin_email=${admin_email:-"admin@$domain"}
  54. read-0 network container_ip < <(get_container_network_ip "$container_id")
  55. debug "Running index.php/project/initialize"
  56. echo docker run --network "$network" docker.0k.io/curl -k -s -X POST -H "Host: $domain" -L \
  57. -F sonata_user_registration[username]="admin" \
  58. -F sonata_user_registration[email]="$admin_email" \
  59. -F sonata_user_registration[plainPassword][first]="$admin_password" \
  60. -F sonata_user_registration[plainPassword][second]="$admin_password" \
  61. "$protocol://$container_ip/index.php/project/initialize"
  62. out=$(docker run --network "$network" docker.0k.io/curl -k -s -X POST -H "Host: $domain" -L \
  63. -F sonata_user_registration[username]="admin" \
  64. -F sonata_user_registration[email]="$admin_email" \
  65. -F sonata_user_registration[plainPassword][first]="$admin_password" \
  66. -F sonata_user_registration[plainPassword][second]="$admin_password" \
  67. "$protocol://$container_ip/index.php/project/initialize") || {
  68. err "Failed to run project/initialize script"
  69. echo "$out"
  70. exit 1
  71. }
  72. # #e "$out" > "$SERVICE_DATASTORE/out.html"
  73. # # debug "written $SERVICE_DATASTORE/out.html"
  74. # had_error=
  75. # while read-0 error_msg; do
  76. # had_error=1
  77. # err "Installation failed with these errors:"
  78. # echo "- ${error_msg}" >&2
  79. # done < <(e "$out" | xpath "//div[@class='errors']/ul/li/text()")
  80. # if [ "$had_error" ]; then
  81. # exit 1
  82. # fi
  83. # debug "No error catched on \`\`install.php\`\` result."
  84. # e "$control" > "$CONTROL"
  85. exit 0