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.

67 lines
2.7 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. app:enable onlyoffice
  17. ## Got:
  18. # $ ./occ app:enable onlyoffice
  19. # App "ONLYOFFICE" cannot be installed because it is not compatible with this version of the server.
  20. #
  21. ## Should
  22. # $ ./occ app:update onlyoffice
  23. # onlyoffice new version available: 7.5.4
  24. # Error: Database error when running migration 070400Date20220607111111 for app onlyoffice
  25. # An exception occurred while executing a query: SQLSTATE[42P07]: Duplicate table: 7 ERROR: relation "share_id_index" already exists
  26. #
  27. ## Then patch it, and re-update (no error should be done)
  28. if [ -e "$DATASTORE"/"$TARGET_SERVICE_NAME/var/www/html/custom_apps/onlyoffice/lib/Migration/Version070400Date20220607111111.php" ]; then
  29. (
  30. cd "$DATASTORE"/"$TARGET_SERVICE_NAME/var/www/html/custom_apps/onlyoffice/"
  31. patch="$CHARM_PATH/src/patch/00-onlyoffice-nextcloud.patch"
  32. if patch -Np1 --dry-run < "$patch"; then
  33. patch -Np1 < "$patch"
  34. fi
  35. )
  36. fi
  37. ONLYOFFICE_CFG="$SERVICE_CONFIGSTORE/etc/onlyoffice/documentserver/local.json"
  38. out=$(jq ".services.CoAuthoring.token.enable.browser = true |
  39. .services.CoAuthoring.token.enable.request.inbox = true |
  40. .services.CoAuthoring.token.enable.request.outbox = true |
  41. .services.CoAuthoring.secret.inbox.string = \"$KEY\" |
  42. .services.CoAuthoring.secret.outbox.string = \"$KEY\" |
  43. .services.CoAuthoring.secret.session.string = \"$KEY\"" \
  44. "$ONLYOFFICE_CFG")
  45. H1=$(cat "$ONLYOFFICE_CFG" | hash_get)
  46. H2=$(echo "$out" | hash_get)
  47. if [ "$H1" != "$H2" ]; then
  48. echo "$out" > "$ONLYOFFICE_CFG"
  49. ## XXXvlab: onlyoffice need to be restarted if already running and local.json changed.
  50. ## it is about docker exec $SERVICE_NAME supervisor restart ...
  51. for container_id in $(get_running_containers_for_service "$SERVICE_NAME"); do
  52. ## restarting all as documented here: https://api.onlyoffice.com/editors/signature/
  53. docker exec "$container_id" supervisorctl restart all
  54. done
  55. relation-set secret "$KEY"
  56. fi