entrypoint.sh 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  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 [ ! -z "$IPFS_BOOTSTRAP_ADD" ]; then
  25. # + ipfs bootstrap add -- /dnsaddr/...
  26. # Error: api not running
  27. ipfs_config_jq_edit '.Bootstrap |= (. + $ARGS.positional | unique)' --args $IPFS_BOOTSTRAP_ADD
  28. fi
  29. (set -x; exec "$@")