container_daemon 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/bin/sh
  2. set -e
  3. user=ipfs
  4. repo="$IPFS_PATH"
  5. if [ `id -u` -eq 0 ]; then
  6. echo "Changing user to $user"
  7. # ensure folder is writable
  8. su-exec "$user" test -w "$repo" || chown -R -- "$user" "$repo"
  9. # restart script with new privileges
  10. exec su-exec "$user" "$0" "$@"
  11. fi
  12. # 2nd invocation with regular user
  13. ipfs version
  14. if [ -e "$repo/config" ]; then
  15. echo "Found IPFS fs-repo at $repo"
  16. else
  17. case "$IPFS_PROFILE" in
  18. "") INIT_ARGS="" ;;
  19. *) INIT_ARGS="--profile=$IPFS_PROFILE" ;;
  20. esac
  21. ipfs init $INIT_ARGS
  22. ipfs config Addresses.API /ip4/0.0.0.0/tcp/5001
  23. ipfs config Addresses.Gateway /ip4/0.0.0.0/tcp/8080
  24. ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["*"]'
  25. ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["PUT", "POST"]'
  26. # Set up the swarm key, if provided
  27. SWARM_KEY_FILE="$repo/swarm.key"
  28. SWARM_KEY_PERM=0400
  29. # Create a swarm key from a given environment variable
  30. if [ ! -z "$IPFS_SWARM_KEY" ] ; then
  31. echo "Copying swarm key from variable..."
  32. echo -e "$IPFS_SWARM_KEY" >"$SWARM_KEY_FILE" || exit 1
  33. chmod $SWARM_KEY_PERM "$SWARM_KEY_FILE"
  34. fi
  35. # Unset the swarm key variable
  36. unset IPFS_SWARM_KEY
  37. # Check during initialization if a swarm key was provided and
  38. # copy it to the ipfs directory with the right permissions
  39. # WARNING: This will replace the swarm key if it exists
  40. if [ ! -z "$IPFS_SWARM_KEY_FILE" ] ; then
  41. echo "Copying swarm key from file..."
  42. install -m $SWARM_KEY_PERM "$IPFS_SWARM_KEY_FILE" "$SWARM_KEY_FILE" || exit 1
  43. fi
  44. # Unset the swarm key file variable
  45. unset IPFS_SWARM_KEY_FILE
  46. fi
  47. exec ipfs "$@"