entrypoint.sh 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. echo "authtoken: $NGROK_AUTH" >> ~/.ngrok2/ngrok.yml
  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 the remote-addr if specified
  43. if [ -n "$NGROK_REMOTE_ADDR" ]; then
  44. if [ -z "$NGROK_AUTH" ]; then
  45. echo "You must specify an authentication token after registering at https://ngrok.com to use reserved ip addresses."
  46. exit 1
  47. fi
  48. ARGS="$ARGS -remote-addr=$NGROK_REMOTE_ADDR "
  49. fi
  50. # Set a custom region
  51. if [ -n "$NGROK_REGION" ]; then
  52. ARGS="$ARGS -region=$NGROK_REGION "
  53. fi
  54. if [ -n "$NGROK_HEADER" ]; then
  55. ARGS="$ARGS -host-header=$NGROK_HEADER "
  56. fi
  57. if [ -n "$NGROK_USERNAME" ] && [ -n "$NGROK_PASSWORD" ] && [ -n "$NGROK_AUTH" ]; then
  58. ARGS="$ARGS -auth=$NGROK_USERNAME:$NGROK_PASSWORD "
  59. elif [ -n "$NGROK_USERNAME" ] || [ -n "$NGROK_PASSWORD" ]; then
  60. if [ -z "$NGROK_AUTH" ]; then
  61. echo "You must specify a username, password, and Ngrok authentication token to use the custom HTTP authentication."
  62. echo "Sign up for an authentication token at https://ngrok.com"
  63. exit 1
  64. fi
  65. fi
  66. if [ -n "$NGROK_DEBUG" ]; then
  67. ARGS="$ARGS -log stdout"
  68. fi
  69. # Set the port.
  70. if [ -z "$NGROK_PORT" ]; then
  71. echo "You must specify a NGROK_PORT to expose."
  72. exit 1
  73. fi
  74. if [ -n "$NGROK_LOOK_DOMAIN" ]; then
  75. ARGS="$ARGS `echo $NGROK_LOOK_DOMAIN:$NGROK_PORT | sed 's|^tcp://||'`"
  76. else
  77. ARGS="$ARGS `echo $NGROK_PORT | sed 's|^tcp://||'`"
  78. fi
  79. set -x
  80. exec $ARGS