entrypoint.sh 1021 B

123456789101112131415161718192021222324252627282930313233
  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. if [ "$IPFS_SWARM_ADDRS" != "default" ]; then
  18. # + ipfs config --json Addresses.Swarm '["/ip4/0.0.0.0/tcp/4001"]'
  19. # Error: api not running
  20. ipfs_config_jq_edit '.Addresses.Swarm |= $ARGS.positional' --args $IPFS_SWARM_ADDRS
  21. fi
  22. if [ ! -z "$IPFS_BOOTSTRAP_ADD" ]; then
  23. # + ipfs bootstrap add -- /dnsaddr/...
  24. # Error: api not running
  25. ipfs_config_jq_edit '.Bootstrap |= (. + $ARGS.positional | unique)' --args $IPFS_BOOTSTRAP_ADD
  26. fi
  27. (set -x; exec "$@")