entrypoint.sh 1.3 KB

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