entrypoint.sh 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. if [ -z "$@" ]; then
  13. printf '[]\n'
  14. else
  15. printf '%s\n' "$@" | jq -R . | jq -sc .
  16. fi
  17. }
  18. if [ ! -e "$IPFS_CONFIG_PATH" ]; then
  19. (set -x; ipfs init --empty-repo --profile $IPFS_INIT_PROFILE)
  20. fi
  21. if [ "$IPFS_API_ADDR" != "default" ]; then
  22. ipfs_config_jq_edit '.Addresses.API = $ARGS[0]' --argjson ARGS "$(args_to_json_array "$IPFS_API_ADDR")"
  23. fi
  24. if [ "$IPFS_SWARM_ADDRS" != "default" ]; then
  25. # + ipfs config --json Addresses.Swarm '["/ip4/0.0.0.0/tcp/4001"]'
  26. # Error: api not running
  27. ipfs_config_jq_edit '.Addresses.Swarm |= $ARGS' --argjson ARGS "$(args_to_json_array $IPFS_SWARM_ADDRS)"
  28. fi
  29. if [ ! -z "$IPFS_BOOTSTRAP_ADD" ]; then
  30. # + ipfs bootstrap add -- /dnsaddr/...
  31. # Error: api not running
  32. ipfs_config_jq_edit '.Bootstrap |= (. + $ARGS | unique)' --argjson ARGS "$(args_to_json_array $IPFS_BOOTSTRAP_ADD)"
  33. fi
  34. (set -x; exec "$@")