entrypoint.sh 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/bin/sh
  2. set -eu
  3. ipfs_config_jq_edit() {
  4. tmp=$(mktemp)
  5. (set -x; jq "$@" < "$IPFS_CONFIG_PATH" > "$tmp")
  6. mv "$tmp" "$IPFS_CONFIG_PATH"
  7. }
  8. # --args available in jq >= 1.6
  9. # https://github.com/stedolan/jq/commit/66fb962a6608805f4d7667d39ad0d88158bd1262
  10. # compare fphammerle/docker-ipfs v0.2.0
  11. args_to_json_array() {
  12. printf '%s\n' "$@" | jq -R . | jq -sc .
  13. }
  14. if [ ! -e "$IPFS_CONFIG_PATH" ]; then
  15. (set -x; ipfs init --empty-repo --profile $IPFS_INIT_PROFILE)
  16. fi
  17. if [ "$IPFS_API_ADDR" != "default" ]; then
  18. ipfs_config_jq_edit '.Addresses.API = $ARGS[0]' --argjson ARGS "$(args_to_json_array "$IPFS_API_ADDR")"
  19. fi
  20. if [ "$IPFS_SWARM_ADDRS" != "default" ]; then
  21. # + ipfs config --json Addresses.Swarm '["/ip4/0.0.0.0/tcp/4001"]'
  22. # Error: api not running
  23. ipfs_config_jq_edit '.Addresses.Swarm |= $ARGS' --argjson ARGS "$(args_to_json_array $IPFS_SWARM_ADDRS)"
  24. fi
  25. if [ ! -z "$IPFS_BOOTSTRAP_ADD" ]; then
  26. # + ipfs bootstrap add -- /dnsaddr/...
  27. # Error: api not running
  28. ipfs_config_jq_edit '.Bootstrap |= (. + $ARGS | unique)' --argjson ARGS "$(args_to_json_array $IPFS_BOOTSTRAP_ADD)"
  29. fi
  30. (set -x; exec "$@")