entrypoint.sh 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 authorization token.
  24. if [ -n "$NGROK_AUTH" ]; then
  25. ARGS="$ARGS -authtoken=$NGROK_AUTH "
  26. fi
  27. # Set the subdomain or hostname, depending on which is set
  28. if [ -n "$NGROK_HOSTNAME" ] && [ -n "$NGROK_AUTH" ]; then
  29. ARGS="$ARGS -hostname=$NGROK_HOSTNAME "
  30. elif [ -n "$NGROK_SUBDOMAIN" ] && [ -n "$NGROK_AUTH" ]; then
  31. ARGS="$ARGS -subdomain=$NGROK_SUBDOMAIN "
  32. elif [ -n "$NGROK_HOSTNAME" ] || [ -n "$NGROK_SUBDOMAIN" ]; then
  33. if [ -z "$NGROK_AUTH" ]; then
  34. echo "You must specify an authentication token after registering at https://ngrok.com to use custom domains."
  35. exit 1
  36. fi
  37. fi
  38. if [ -n "$NGROK_HEADER" ]; then
  39. ARGS="$ARGS -host-header=$NGROK_HEADER "
  40. fi
  41. if [ -n "$NGROK_USERNAME" ] && [ -n "$NGROK_PASSWORD" ] && [ -n "$NGROK_AUTH" ]; then
  42. ARGS="$ARGS -auth=\"$NGROK_USERNAME:$NGROK_PASSWORD\" "
  43. elif [ -n "$NGROK_USERNAME" ] || [ -n "$NGROK_PASSWORD" ]; then
  44. if [ -z "$NGROK_AUTH" ]; then
  45. echo "You must specify a username, password, and Ngrok authentication token to use the custom HTTP authentication."
  46. echo "Sign up for an authentication token at https://ngrok.com"
  47. exit 1
  48. fi
  49. fi
  50. ARGS="$ARGS -log stdout"
  51. # Set the port.
  52. if [ -z "$NGROK_PORT" ]; then
  53. echo "You must specify a NGROK_PORT to expose."
  54. exit 1
  55. fi
  56. ARGS="$ARGS `echo $NGROK_PORT | sed 's|^tcp://||'`"
  57. set -x
  58. exec $ARGS