init.sh 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. {% macro init(values) -%}
  2. {%- set url = "https://github.com/storj/storj/releases/latest/download/identity_linux_amd64.zip" %}
  3. {%- set id_path = values.consts.identity_dir %}
  4. {%- set id_tool_dir = "/tmp/identity-tool" %}
  5. {%- set id_tool_dir_files = values.consts.identity_tool_dir_files %}
  6. {%- set flags = "--identity-dir %s"|format(id_path) %}
  7. [ ! -w {{ values.consts.config_dir }} ] && { echo "Config directory is not writable."; exit 1; }
  8. [ ! -r {{ id_path }} ] && { echo "Identity directory is not readable."; exit 1; }
  9. echo "Checking for identity certificate..."
  10. if ! [ -f "{{ id_path }}/ca.cert" ] && ! [ -f "{{ id_path }}/identity.cert" ]; then
  11. echo "Downloading identity generator tool..."; mkdir -p {{ id_tool_dir }}
  12. mkdir -p {{ id_tool_dir_files }}
  13. [ -w {{ id_tool_dir_files }} ] || { echo "Identity tool files directory is not writable."; exit 1; }
  14. [ -w {{ id_path }} ] || { echo "Identity directory is not writable."; exit 1; }
  15. wget -q -O {{ id_tool_dir }}/identity_linux_amd64.zip {{ url }} || { echo "Failed to download identity generator tool."; exit 1; }
  16. unzip -o {{ id_tool_dir }}/identity_linux_amd64.zip -d {{ id_tool_dir }} || { echo "Failed to unzip identity generator tool."; exit 1; }
  17. chmod +x {{ id_tool_dir }}/identity || { echo "Failed to make identity generator tool executable."; exit 1; }
  18. echo "Generating identity certificate..."
  19. {{ id_tool_dir }}/identity create storagenode {{ flags }}
  20. if [ ! -f "{{ id_path }}/storagenode/ca.cert" ] && [ ! -f "{{ id_path }}/storagenode/identity.cert" ]; then
  21. echo "Failed to generate identity certificate."
  22. exit 1
  23. fi
  24. echo "Identity generated successfully at {{ id_path }}"
  25. ls -lhR {{ id_path }}
  26. mv {{ id_path }}/storagenode/identity.key {{ id_path }}/identity.key || { echo "Failed to move identity key."; exit 1; }
  27. mv {{ id_path }}/storagenode/identity.cert {{ id_path }}/identity.cert || { echo "Failed to move identity certificate."; exit 1; }
  28. else
  29. echo "Identity certificate already exists. Skipping..."
  30. fi
  31. echo "Checking if Storj is already setup..."
  32. if ! [ -f {{ values.consts.config_dir }}/config.yaml ]; then
  33. echo "Setting up Storj"
  34. export SETUP="true"
  35. /entrypoint
  36. else
  37. echo "Storj is already setup. Skipping..."
  38. fi
  39. # Mark setup as done so the main container can start
  40. touch {{ values.consts.config_dir }}/setup.done || { echo "Failed to create setup.done file."; exit 1; }
  41. {% endmacro %}