config.sh 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. {% macro config(values, cfg=[]) -%}
  2. #!/bin/sh
  3. {%- set cfg_path = "%s/config.yaml"|format(values.consts.config_path) %}
  4. if [ ! -f "{{ cfg_path }}" ]; then
  5. echo "File [{{ cfg_path }}] does not exist. Copying default config..."
  6. cp -v "/shared/config.example.yaml" "{{ cfg_path }}"
  7. else
  8. echo "File [{{ cfg_path }}] exists!"
  9. fi
  10. echo "Updating [{{ cfg_path }}] file..."
  11. {%- for c in cfg %}
  12. {%- for key, value in c.items() %}
  13. echo ''
  14. echo "Updating [{{ key }}] key..."
  15. yq -i '.{{ key }} = {{ value|tojson }}' "{{ cfg_path }}"
  16. echo "New value for [{{ key }}]: $(yq '.{{ key }}' "{{ cfg_path }}")"
  17. {%- endfor %}
  18. {%- endfor %}
  19. echo "Done!"
  20. {% endmacro %}
  21. {% macro fetch_db_seed(values) -%}
  22. #!/bin/sh
  23. {{ skip_step_or_continue(values=values, step="fetch_db_seed") }}
  24. mkdir -p /shared/seed
  25. cd /shared/seed
  26. echo "Fetching seed..."
  27. git init || { echo "Failed to initialize git repo"; exit 1; }
  28. git remote add invidious https://github.com/iv-org/invidious.git || { echo "Failed to add remote"; exit 1; }
  29. git fetch invidious || { echo "Failed to fetch remote"; exit 1; }
  30. # Get the following directories: config, docker
  31. git checkout invidious/master -- config docker || { echo "Failed to checkout"; exit 1; }
  32. echo "Fetched seed successfully"
  33. mv -fv config/config.example.yml /shared/config.example.yaml || { echo "Failed to move config"; exit 1; }
  34. mv -fv config docker || { echo "Failed to move files"; exit 1; }
  35. echo "Done!"
  36. {% endmacro %}
  37. {% macro apply_db_seed(values) -%}
  38. #!/bin/sh
  39. {{ skip_step_or_continue(values=values, step="apply_db_seed") }}
  40. echo "Applying seed..."
  41. cd /shared/seed/docker
  42. ./init-invidious-db.sh || { echo "Failed to apply seed"; exit 1; }
  43. echo "Done!"
  44. {% endmacro %}
  45. {% macro skip_step_or_continue(values, step='') -%}
  46. {%- set cfg_path = "%s/config.yaml"|format(values.consts.config_path) %}
  47. touch "{{ cfg_path }}"
  48. if [ -f "{{ cfg_path }}" ]; then
  49. echo "Found existing config file [{{ cfg_path }}]."
  50. echo "Treating it as an existing installation. Skipping step [{{ step }}]..."
  51. echo "If you are re-installing, please remove the file and restart the app."
  52. echo "After it is up and running, you can update the config file to your needs and restart the app."
  53. exit 0
  54. fi
  55. {% endmacro %}