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.

86 lines
2.5 KiB

  1. #!/bin/bash
  2. set -e
  3. service:relations() {
  4. local service="$1" relation="$2" cache_file="$state_tmpdir/$FUNCNAME.cache.$1.$2" \
  5. rn ts rc td
  6. if [ -e "$cache_file" ]; then
  7. #debug "$FUNCNAME: SESSION cache hit $1"
  8. cat "$cache_file"
  9. return 0
  10. fi
  11. while read-0-err E rn ts rc td; do
  12. [ "$relation" == "$rn" ] && {
  13. printf "%s\0" "$ts" "$rc" "$td"
  14. }
  15. done < <(p-err get_service_relations "$service") > "$cache_file"
  16. if [ "$E" != 0 ]; then
  17. rm -f "$cache_file" ## no cache
  18. return 1
  19. fi
  20. cat "$cache_file"
  21. }
  22. export -f service:relations
  23. export TRAVERSE_SEPARATOR=:
  24. ## Traverse on all service satisfying relation
  25. service:traverse:all() {
  26. local service_path="$1"
  27. local service relation path relation
  28. service=${service_path%%$TRAVERSE_SEPARATOR*}
  29. path=${service_path#*$TRAVERSE_SEPARATOR}
  30. if [[ "$path" == *$TRAVERSE_SEPARATOR* ]]; then
  31. relation=${path%%$TRAVERSE_SEPARATOR*}
  32. path=${path#*$TRAVERSE_SEPARATOR}
  33. else
  34. relation=$path
  35. path=
  36. fi
  37. while read-0-err E ts _ _; do
  38. if [ -n "$path" ]; then
  39. service:traverse "$ts$TRAVERSE_SEPARATOR$path"
  40. else
  41. printf "%s\n" "$ts"
  42. fi
  43. done < <(p-err service:relations "${service}" "${relation}")
  44. if [ "$E" != 0 ]; then
  45. err "Couldn't find service for ${DARKYELLOW}$service${NORMAL}--${DARKCYAN}$relation${NORMAL}--> ?"
  46. return 1
  47. fi
  48. }
  49. export -f service:traverse:all
  50. ##
  51. ## Finish live connection for relation nextcloud_app
  52. ##
  53. nextcloud_services=($(service:traverse:all "$MASTER_BASE_SERVICE_NAME":nextcloud-app)) || return 1
  54. if [ ${#nextcloud_services[@]} != 0 ]; then
  55. if ! collabora_url=$(relation:get "$MASTER_BASE_SERVICE_NAME":web-proxy url) || [ -z "$collabora_url" ]; then
  56. collabora_url="http://$BASE_SERVICE_NAME:9980"
  57. fi
  58. if ! get_healthy_container_ip_for_service "$SERVICE_NAME" 9980; then
  59. exit 17
  60. fi
  61. info "collabora_domain: '$collabora_url'"
  62. for nextcloud_service in "${nextcloud_services[@]}"; do
  63. ## Activate-config will make nextcloud try to connect to collabora.
  64. ## This is why we must run this in post_deploy
  65. compose --no-relations --no-init \
  66. occ "$nextcloud_service" \
  67. app:install richdocuments \; \
  68. config:app:set --value="${collabora_url}" richdocuments wopi_url \; \
  69. richdocuments:activate-config || return 1
  70. done
  71. fi