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.

117 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. if ! [ -d "$MATOMO_CODE/vendor" ]; then
  19. # XXXvlab: can't get real config here
  20. if ! read-0 publish_dir_ts _ _ < <(get_service_relation "$SERVICE_NAME" "publish-dir"); then
  21. err "Couldn't find relation ${DARKCYAN}publish-dir${NORMAL}."
  22. exit 1
  23. fi
  24. publish_dir_relation_dir=$(get_relation_data_dir "$SERVICE_NAME" "$publish_dir_ts" "publish-dir") || {
  25. err "Failed to find relation file"
  26. exit 1
  27. }
  28. publish_dir_relation_config=$(cat "$publish_dir_relation_dir/data") || exit 2
  29. domain=$(e "$publish_dir_relation_config" | shyaml get-value domain) || {
  30. err "Couldn't get domain information in ${DARKCYAN}publish-dir${NORMAL} relation's data."
  31. exit 1
  32. }
  33. url=$(e "$publish_dir_relation_config" | shyaml get-value url) || {
  34. err "Couldn't get url information in ${DARKCYAN}publish-dir${NORMAL} relation's data."
  35. exit 1
  36. }
  37. ##
  38. ## Get domain in option of relation "publish-dir"
  39. ##
  40. container_id=$(
  41. for container_id in $(get_running_containers_for_service "$MASTER_BASE_SERVICE_NAME"); do
  42. e "$container_id"
  43. break
  44. done
  45. )
  46. docker exec -i "$container_id" bash <<EOF
  47. type -p "composer" || {
  48. cd /tmp
  49. curl -sS https://getcomposer.org/installer | php || {
  50. echo "Error occured while attempting to install compose." >&2
  51. exit 1
  52. }
  53. mv -v /tmp/composer.phar /usr/local/bin/composer || exit 1
  54. }
  55. cd /var/www/$domain &&
  56. composer install
  57. EOF
  58. fi
  59. ##
  60. ## Required wizard
  61. ##
  62. if [ "$(crudini --get "$MATOMO_CONFIG_FILE" General installation_in_progress)" == 1 ]; then
  63. curl "$url/index.php?action=tablesCreation" >/dev/null || {
  64. err "Table creation failed."
  65. exit 1
  66. }
  67. orig_uid_gid=$(stat --format=%u:%g "$MATOMO_CONFIG_FILE")
  68. uid_gid=$(stat --format=%u:%g "$SERVICE_DATASTORE/var/tmp/matomo/index.php")
  69. chown "$uid_gid" "$MATOMO_CONFIG_FILE"
  70. curl "$url/index.php?action=setupSuperUser" \
  71. --data-urlencode login="admin" \
  72. --data-urlencode password="$admin_password" \
  73. --data-urlencode password_bis="$admin_password" \
  74. --data-urlencode email="${admin_email:-admin@localhost.localnet}" \
  75. --data-urlencode subscribe_newsletter_piwikorg="0" \
  76. --data-urlencode subscribe_newsletter_piwikpro="0" || {
  77. err "Setting admin account failed."
  78. exit 1
  79. }
  80. chown "$orig_uid_gid" "$MATOMO_CONFIG_FILE"
  81. crudini --set "$MATOMO_CONFIG_FILE" General installation_in_progress 0
  82. #curl "$url/index.php?action=firstWebsiteSetup" \
  83. # --data-urlencode siteName="$SITE_NAME" \
  84. # --data-urlencode url="$url" \
  85. # --data-urlencode timezone="$(cat /etc/timezone)" \
  86. # --data-urlencode ecommerce="0" || {
  87. # err "First Web Site Setup failed."
  88. # exit 1
  89. #}
  90. fi
  91. exit 0