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.

54 lines
2.2 KiB

  1. #!/bin/bash
  2. set -e
  3. KEY=$(relation-get secret) || true
  4. if [ -z "$KEY" ]; then
  5. KEY=$(gen_password 64)
  6. fi
  7. ## XXXvlab: we really need to have a state based cache thingy, because
  8. ## setting the same password each time is really time consumming.
  9. compose --no-relations --no-init \
  10. occ "$MASTER_TARGET_SERVICE_NAME" \
  11. app:install onlyoffice \; \
  12. config:system:set onlyoffice DocumentServerInternalUrl --value="http://$MASTER_BASE_SERVICE_NAME/" \; \
  13. config:system:set onlyoffice StorageUrl --value="http://$MASTER_TARGET_SERVICE_NAME/" \; \
  14. config:app:set onlyoffice jwt_secret --value="$KEY" \; \
  15. config:system:set allow_local_remote_servers --type=boolean --value=true
  16. if [ -e "$DATASTORE"/"$TARGET_SERVICE_NAME/var/www/html/custom_apps/onlyoffice/lib/Migration/Version070400Date20220607111111.php" ]; then
  17. (
  18. cd "$DATASTORE"/"$TARGET_SERVICE_NAME/var/www/html/custom_apps/onlyoffice/"
  19. patch="$CHARM_PATH/src/patch/00-onlyoffice-nextcloud.patch"
  20. if patch -Np1 --dry-run < "$patch"; then
  21. patch -Np1 < "$patch"
  22. fi
  23. )
  24. fi
  25. ONLYOFFICE_CFG="$SERVICE_CONFIGSTORE/etc/onlyoffice/documentserver/local.json"
  26. out=$(jq ".services.CoAuthoring.token.enable.browser = true |
  27. .services.CoAuthoring.token.enable.request.inbox = true |
  28. .services.CoAuthoring.token.enable.request.outbox = true |
  29. .services.CoAuthoring.secret.inbox.string = \"$KEY\" |
  30. .services.CoAuthoring.secret.outbox.string = \"$KEY\" |
  31. .services.CoAuthoring.secret.session.string = \"$KEY\"" \
  32. "$ONLYOFFICE_CFG")
  33. H1=$(cat "$ONLYOFFICE_CFG" | hash_get)
  34. H2=$(echo "$out" | hash_get)
  35. if [ "$H1" != "$H2" ]; then
  36. echo "$out" > "$ONLYOFFICE_CFG"
  37. ## XXXvlab: onlyoffice need to be restarted if already running and local.json changed.
  38. ## it is about docker exec $SERVICE_NAME supervisor restart ...
  39. for container_id in $(get_running_containers_for_service "$SERVICE_NAME"); do
  40. ## restarting all as documented here: https://api.onlyoffice.com/editors/signature/
  41. docker exec "$container_id" supervisorctl restart all
  42. done
  43. relation-set secret "$KEY"
  44. fi