entrypoint.sh 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/bin/sh -e
  2. if [ -n "$@" ]; then
  3. exec "$@"
  4. fi
  5. # Legacy compatible:
  6. if [ -z "$NGROK_PORT" ]; then
  7. if [ -n "$HTTPS_PORT" ]; then
  8. NGROK_PORT="$HTTPS_PORT"
  9. elif [ -n "$HTTPS_PORT" ]; then
  10. NGROK_PORT="$HTTP_PORT"
  11. elif [ -n "$APP_PORT" ]; then
  12. NGROK_PORT="$APP_PORT"
  13. fi
  14. fi
  15. ARGS="ngrok"
  16. # Set the protocol.
  17. if [ "$NGROK_PROTOCOL" = "TCP" ]; then
  18. ARGS="$ARGS tcp"
  19. else
  20. ARGS="$ARGS http"
  21. NGROK_PORT="${NGROK_PORT:-80}"
  22. fi
  23. # Set the TLS binding flag
  24. if [ -n "$NGROK_BINDTLS" ]; then
  25. ARGS="$ARGS -bind-tls=$NGROK_BINDTLS "
  26. fi
  27. # Set the authorization token.
  28. if [ -n "$NGROK_AUTH" ]; then
  29. ARGS="$ARGS -authtoken=$NGROK_AUTH "
  30. fi
  31. # Set the subdomain or hostname, depending on which is set
  32. if [ -n "$NGROK_HOSTNAME" ] && [ -n "$NGROK_AUTH" ]; then
  33. ARGS="$ARGS -hostname=$NGROK_HOSTNAME "
  34. elif [ -n "$NGROK_SUBDOMAIN" ] && [ -n "$NGROK_AUTH" ]; then
  35. ARGS="$ARGS -subdomain=$NGROK_SUBDOMAIN "
  36. elif [ -n "$NGROK_HOSTNAME" ] || [ -n "$NGROK_SUBDOMAIN" ]; then
  37. if [ -z "$NGROK_AUTH" ]; then
  38. echo "You must specify an authentication token after registering at https://ngrok.com to use custom domains."
  39. exit 1
  40. fi
  41. fi
  42. # Set a custom region
  43. if [ -n "$NGROK_REGION" ]; then
  44. ARGS="$ARGS -region=$NGROK_REGION "
  45. fi
  46. if [ -n "$NGROK_HEADER" ]; then
  47. ARGS="$ARGS -host-header=$NGROK_HEADER "
  48. fi
  49. if [ -n "$NGROK_USERNAME" ] && [ -n "$NGROK_PASSWORD" ] && [ -n "$NGROK_AUTH" ]; then
  50. ARGS="$ARGS -auth=$NGROK_USERNAME:$NGROK_PASSWORD "
  51. elif [ -n "$NGROK_USERNAME" ] || [ -n "$NGROK_PASSWORD" ]; then
  52. if [ -z "$NGROK_AUTH" ]; then
  53. echo "You must specify a username, password, and Ngrok authentication token to use the custom HTTP authentication."
  54. echo "Sign up for an authentication token at https://ngrok.com"
  55. exit 1
  56. fi
  57. fi
  58. if [ -n "$NGROK_DEBUG" ]; then
  59. ARGS="$ARGS -log stdout"
  60. fi
  61. # Set the port.
  62. if [ -z "$NGROK_PORT" ]; then
  63. echo "You must specify a NGROK_PORT to expose."
  64. exit 1
  65. fi
  66. ARGS="$ARGS `echo $NGROK_PORT | sed 's|^tcp://||'`"
  67. set -x
  68. exec $ARGS