35 lines
1.2 KiB

  1. #!/bin/bash
  2. ## When writing relation script, remember:
  3. ## - they should be idempotents
  4. ## - they can be launched while the dockers is already up
  5. ## - they are launched from the host
  6. ## - the target of the link is launched first, and get a chance to ``relation-set``
  7. ## - both side of the scripts get to use ``relation-get``.
  8. . lib/common
  9. set -e
  10. exclude_patterns=$(relation-get "exclude-patterns") || true
  11. include_patterns=$(relation-get "include-patterns") || true
  12. include_patterns=${include_patterns:-"- /"}
  13. while read-0 pattern; do
  14. if [[ "$pattern" != /* ]]; then
  15. err "Invalid pattern '$pattern' provided as ${WHITE}exclude-pattern${NORMAL}, " \
  16. "in relation's options."
  17. exit 1
  18. fi
  19. echo "/$BASE_SERVICE_NAME$pattern"
  20. done < <(e "$exclude_patterns" | shyaml get-values-0) >> "$RSYNC_EXCLUDE_PATTERNS"
  21. while read-0 pattern; do
  22. if [[ "$pattern" != /* ]]; then
  23. err "Invalid pattern '$pattern' provided as ${WHITE}exclude-pattern${NORMAL}, " \
  24. "in relation's options."
  25. exit 1
  26. fi
  27. echo "/$BASE_SERVICE_NAME$pattern"
  28. done < <(e "$include_patterns" | shyaml get-values-0) >> "$RSYNC_INCLUDE_PATTERNS"