config.sh.jinja 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. {% macro config_script(values, db_url) -%}
  2. {%- set config_file = "%s/configuration.yaml"|format(values.consts.config_path) %}
  3. {%- set default_files_path = "/default/init" %}
  4. {%- set extra_files_to_create = ["automations.yaml", "scripts.yaml", "scenes.yaml"] %}
  5. #!/bin/sh
  6. if [ ! -f "{{ config_file }}" ]; then
  7. echo "File [{{ config_file }}] does NOT exist. Creating..."
  8. cp "{{ default_files_path }}/configuration.default" "{{ config_file }}"
  9. {%- for file in extra_files_to_create %}
  10. if [ ! -f "{{ values.consts.config_path }}/{{ file }}" ]; then
  11. echo "File [{{ values.consts.config_path }}/{{ file }}] does NOT exist. Creating..."
  12. cp "{{ default_files_path }}/empty.default" "{{ values.consts.config_path }}/{{ file }}"
  13. fi
  14. {%- endfor %}
  15. fi
  16. chmod +rw "{{ config_file }}" || echo "Failed to set permissions on [{{ config_file }}]"
  17. if ! yq --exit-status '.recorder' < "{{ config_file }}" &> /dev/null; then
  18. echo "Section [recorder] does NOT exist in [{{ config_file }}]. Appending..."
  19. echo "" >> "{{ config_file }}"
  20. cat "{{ default_files_path }}/recorder.default" >> "{{ config_file }}"
  21. fi
  22. echo "Ensure DB URL is up to date [{{ db_url }}] in [{{ config_file }}]"
  23. yq -i '.recorder.db_url = "{{ db_url }}"' "{{ config_file }}"
  24. if ! yq --exit-status '.http' < "{{ config_file }}" &> /dev/null; then
  25. echo "Section [http] does NOT exist in [{{ config_file }}]. Appending..."
  26. yq -i '.http = {}' "{{ config_file }}"
  27. fi
  28. echo "Matching server port to configured port [{{ values.network.web_port.port_number }}] in [{{ config_file }}]"
  29. yq -i '.http.server_port = {{ values.network.web_port.port_number }}' "{{ config_file }}"
  30. {%- if values.network.certificate_id %}
  31. echo "Setting up ssl paths [{{ values.consts.ssl_key_path }}] and [{{ values.consts.ssl_cert_path }}] in [{{ config_file }}]"
  32. yq -i '.http.ssl_key = "{{ values.consts.ssl_key_path }}"' "{{ config_file }}"
  33. yq -i '.http.ssl_certificate = "{{ values.consts.ssl_cert_path }}"' "{{ config_file }}"
  34. {%- endif %}
  35. echo "Done"
  36. {%- endmacro %}