setup.sh 825 B

123456789101112131415161718192021222324252627
  1. {% macro setup(tpl, config) %}
  2. #!/bin/bash
  3. set -e
  4. {%- set cfg_path = "/config/settings.json" %}
  5. {%- set tmp_path = "/tmp/settings.json" %}
  6. {%- set redir_cmd = '%s && mv %s "%s" && echo -n " Done!" || { echo -n " Failed."; exit 1; }' | format(tmp_path, tmp_path, cfg_path) %}
  7. if [ ! -f {{ cfg_path }} ]; then
  8. echo "No settings.json found, exiting"
  9. exit 1
  10. fi
  11. if [ ! -w {{ cfg_path }} ]; then
  12. echo "Settings.json is not writable, exiting"
  13. exit 1
  14. fi
  15. echo -e "\nStarting setup..."
  16. {%- for key, val in config.items() %}
  17. echo -n -e "\t - Setting [{{ key }}] to [{{ tpl.funcs.auto_cast(val) | tojson }}]..."
  18. jq '."{{ key }}" = {{ tpl.funcs.auto_cast(val) | tojson }}' "{{ cfg_path }}" > {{ redir_cmd }}
  19. echo " New value is [$(jq '."{{ key }}"' {{ cfg_path }})]";
  20. {%- endfor %}
  21. echo -e "Finished setup.\n"
  22. {% endmacro %}