nc.jinja.sh 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. {% macro occ(values) -%}
  2. #!/bin/bash
  3. uid="$(id -u)"
  4. gid="$(id -g)"
  5. if [ "$uid" = "0" ]; then
  6. user='www-data'
  7. group='www-data'
  8. else
  9. user="$uid"
  10. group="$gid"
  11. fi
  12. run_as() {
  13. if [ "$(id -u)" = "0" ]; then
  14. su -p "$user" -s /bin/bash -c "php /var/www/html/occ $(printf '%q ' "$@")"
  15. else
  16. /bin/bash -c "php /var/www/html/occ $(printf '%q ' "$@")"
  17. fi
  18. }
  19. run_as "$@"
  20. {%- endmacro -%}
  21. {% macro hosts_update(values) -%}
  22. #!/bin/bash
  23. config_file="/var/www/html/config/config.php"
  24. {# Reason for sed: https://github.com/nextcloud/server/issues/44924 #}
  25. echo "Updating database and redis host in config.php"
  26. sed -i "s/\('dbhost' => '\)[^']*postgres:5432',/\1{{ values.consts.postgres_container_name }}:5432',/" "$config_file" || { echo "Failed to update database host. Exiting..."; exit 1; }
  27. occ config:system:set redis host --value="{{ values.consts.redis_container_name }}" || { echo "Failed to update redis host. Continuing..."; exit 0; }
  28. {%- endmacro -%}
  29. {% macro trusted_domains_update() -%}
  30. #!/bin/bash
  31. set_list() {
  32. list_name="${1:?"list_name is unset"}"
  33. space_delimited_values="${2:?"space_delimited_values is unset"}"
  34. # Get current list
  35. current_list="$(occ config:system:get "$list_name")"
  36. # Convert newline separated values to space separated
  37. current_list="$(echo "$current_list" | tr '\n' ' ')"
  38. # Merge current list with new values
  39. merged_list="$(echo "$current_list $space_delimited_values" | tr ' ' '\n' | xargs -I{} echo {})"
  40. # Remove duplicate values
  41. merged_list="$(echo "$merged_list" | tr ' ' '\n' | sort -u | tr '\n' ' ')"
  42. if [ -n "${merged_list}" ]; then
  43. # Remove current list, so we can replace it with the new one
  44. occ config:system:delete "$list_name" || return
  45. IDX=0
  46. # Replace spaces with newlines so the input can have
  47. # mixed entries of space or new line separated values
  48. echo "$merged_list" | tr ' ' '\n' | while IFS= read -r value; do
  49. # Skip empty values
  50. if [ -z "$value" ]; then
  51. continue
  52. fi
  53. occ config:system:set "$list_name" $IDX --value="$value"
  54. IDX=$((IDX+1))
  55. done
  56. fi
  57. }
  58. echo "Updating trusted domains. It will append new domains to the existing list."
  59. echo "If you see a domain that is not longer valid, you need to manually remove it from the list in the config.php file."
  60. set_list "trusted_domains" "${NEXTCLOUD_TRUSTED_DOMAINS}" || { echo "Failed to update trusted domains. Continuing..."; exit 0; }
  61. {%- endmacro -%}
  62. {% macro imaginary_url(host, port) -%}
  63. #!/bin/bash
  64. echo '## Configuring Imaginary...'
  65. occ config:system:set preview_imaginary_url --value={{ "http://%s:%d"|format(host, port) }}
  66. {%- endmacro -%}