fork 0k-charms
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.

83 lines
2.0 KiB

  1. #!/bin/bash
  2. . lib/common
  3. set -e
  4. domain=$(relation-get domain) || exit 1
  5. url=$(relation-get url) || exit 1
  6. # location=$CONFIGSTORE/$BASE_SERVICE_NAME/var/www/$domain
  7. upload_dir="${SERVICE_DATASTORE}/var/www/$domain/uploads"
  8. if [ -d "$upload_dir" ]; then
  9. uid_gid=$(stat --format=%u:%g "$upload_dir")
  10. else
  11. err "Upload dir '${upload_dir}' was not created. Can't continue."
  12. exit 1
  13. fi
  14. dirs=(
  15. /var/cache/gogocarto
  16. /var/lib/gogocarto/sessions
  17. /var/log/gogocarto
  18. )
  19. to_create=()
  20. for dir in "${dirs[@]}"; do
  21. fdir="${SERVICE_DATASTORE}${dir}"
  22. if ! [ -d "$fdir" ]; then
  23. to_create+=("$fdir")
  24. fi
  25. done
  26. if [ "${#to_create[@]}" -gt 0 ]; then
  27. mkdir -p "${to_create[@]}" &&
  28. chown -v "$uid_gid" "${to_create[@]}" &&
  29. chmod -v g+rwx "${to_create[@]}"
  30. fi
  31. cat <<EOF >> "${GOGOCARTO_CODE}"/.env
  32. BASE_PROTOCOL=${url%%://*}
  33. BASE_URL=$domain
  34. BASE_PATH=/index.php
  35. EOF
  36. cat <<EOF > "${GOGOCARTO_CODE}"/web/.htaccess
  37. Options -MultiViews
  38. RewriteEngine On
  39. RewriteRule ^js/.* - [L]
  40. RewriteCond %{REQUEST_FILENAME} !-f
  41. RewriteRule ^(.*)$ index.php/\$1 [QSA,L]
  42. EOF
  43. ## Make the web part aware of were the PHP app is located
  44. sed -ri "s%^(\s*require\s+).*(/config/bootstrap.php'\s*;\s*)$%\1'/opt/apps/$SERVICE_NAME\2%" \
  45. "${GOGOCARTO_CODE}"/web/index.php || exit 1
  46. ## correct bundles links, these are for static resources (css, js)
  47. ## offered in PHP dependencies.
  48. (
  49. cd "${GOGOCARTO_CODE}"/web/bundles
  50. for i in *; do
  51. link_target=$(readlink "$i")
  52. ln -svf "/opt/apps/${SERVICE_NAME}/vendor/${link_target#*/vendor/}" "$i"
  53. done
  54. ) || exit 1
  55. config-add "
  56. services:
  57. $MASTER_TARGET_SERVICE_NAME:
  58. volumes:
  59. - $GOGOCARTO_CODE:/opt/apps/$SERVICE_NAME:rw
  60. - $SERVICE_DATASTORE/var/cache/gogocarto:/opt/apps/$SERVICE_NAME/var/cache:rw
  61. - $SERVICE_DATASTORE/var/lib/gogocarto/sessions:/opt/apps/$SERVICE_NAME/var/sessions:rw
  62. - $SERVICE_DATASTORE/var/log/gogocarto:/opt/apps/$SERVICE_NAME/var/log:rw
  63. ## Required to give PHP access to this dir
  64. - $upload_dir:/opt/apps/$SERVICE_NAME/web/uploads:rw
  65. "