entrypoint.sh 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/bin/sh -e
  2. if [ -n "$@" ]; then
  3. exec "$@"
  4. fi
  5. ARGS="ngrok"
  6. # Set the protocol.
  7. if [ "$NGROK_PROTOCOL" = "TCP" ]; then
  8. ARGS="$ARGS tcp"
  9. else
  10. ARGS="$ARGS http"
  11. fi
  12. # Set the authorization token.
  13. if [ -n "$NGROK_AUTH" ]; then
  14. ARGS="$ARGS -authtoken=$NGROK_AUTH "
  15. fi
  16. # Set the subdomain or hostname, depending on which is set
  17. if [ -n "$NGROK_HOSTNAME" ] && [ -n "$NGROK_AUTH" ]; then
  18. ARGS="$ARGS -hostname=$NGROK_HOSTNAME "
  19. elif [ -n "$NGROK_SUBDOMAIN" ] && [ -n "$NGROK_AUTH" ]; then
  20. ARGS="$ARGS -subdomain=$NGROK_SUBDOMAIN "
  21. elif [ -n "$NGROK_HOSTNAME" ] || [ -n "$NGROK_SUBDOMAIN" ]; then
  22. if [ -z "$NGROK_AUTH" ]; then
  23. echo "You must specify an authentication token after registering at https://ngrok.com to use custom domains."
  24. exit 1
  25. fi
  26. fi
  27. if [ -n "$NGROK_HEADER" ]; then
  28. ARGS="$ARGS -host-header=$NGROK_HEADER "
  29. fi
  30. if [ -n "$NGROK_USERNAME" ] && [ -n "$NGROK_PASSWORD" ] && [ -n "$NGROK_AUTH" ]; then
  31. ARGS="$ARGS -auth=\"$NGROK_USERNAME:$NGROK_PASSWORD\" "
  32. elif [ -n "$NGROK_USERNAME" ] || [ -n "$NGROK_PASSWORD" ]; then
  33. if [ -z "$NGROK_AUTH" ]; then
  34. echo "You must specify a username, password, and Ngrok authentication token to use the custom HTTP authentication."
  35. echo "Sign up for an authentication token at https://ngrok.com"
  36. exit 1
  37. fi
  38. fi
  39. ARGS="$ARGS -log stdout"
  40. # Set the point.
  41. if [ -n "$HTTPS_PORT" ]; then
  42. ARGS="$ARGS `echo $HTTPS_PORT | sed 's|^tcp://||'`"
  43. elif [ -n "$HTTP_PORT" ]; then
  44. ARGS="$ARGS `echo $HTTP_PORT | sed 's|^tcp://||'`"
  45. elif [ -n "$APP_PORT" ]; then
  46. ARGS="$ARGS `echo $APP_PORT | sed 's|^tcp://||'`"
  47. fi
  48. set -x
  49. exec $ARGS