entrypoint.sh 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. #diff -u "$IPFS_CONFIG_PATH" "$tmp" || true
  9. mv "$tmp" "$IPFS_CONFIG_PATH"
  10. }
  11. if [ ! -e "$IPFS_CONFIG_PATH" ]; then
  12. (set -x; ipfs init --empty-repo --profile $IPFS_INIT_PROFILE)
  13. fi
  14. if [ "$IPFS_API_ADDR" != "default" ]; then
  15. ipfs_config_jq_edit '.Addresses.API = $ARGS.positional[0]' --args "$IPFS_API_ADDR"
  16. fi
  17. # compare `Addresses.AppendAnnounce (new in go-ipfs v0.11.0)
  18. # https://github.com/ipfs/go-ipfs/blob/v0.11.0/docs/config.md#addressesappendannounce
  19. if [ "$IPFS_SWARM_ADDRS" != "default" ]; then
  20. # + ipfs config --json Addresses.Swarm '["/ip4/0.0.0.0/tcp/4001"]'
  21. # Error: api not running
  22. ipfs_config_jq_edit '.Addresses.Swarm |= $ARGS.positional' --args $IPFS_SWARM_ADDRS
  23. fi
  24. if [ "$IPFS_GATEWAY_ADDR" != "default" ]; then
  25. ipfs_config_jq_edit '.Addresses.Gateway = $ARGS.positional[0]' --args "$IPFS_GATEWAY_ADDR"
  26. fi
  27. # compare https://github.com/ipfs/go-ipfs/blob/v0.11.0/docs/config.md#peering
  28. if [ ! -z "$IPFS_BOOTSTRAP_ADD" ]; then
  29. # + ipfs bootstrap add -- /dnsaddr/...
  30. # Error: api not running
  31. ipfs_config_jq_edit '.Bootstrap |= (. + $ARGS.positional | unique)' --args $IPFS_BOOTSTRAP_ADD
  32. fi
  33. (set -x; exec "$@")