ngrok_discover 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/bin/sh
  2. if [ "$1" = "/bin/sh" ]; then
  3. shift
  4. fi
  5. if [ -n "$HTTPS_PORT" ]; then
  6. FWD="`echo $HTTPS_PORT | sed 's|^tcp://||'`"
  7. elif [ -n "$HTTP_PORT" ]; then
  8. FWD="`echo $HTTP_PORT | sed 's|^tcp://||'`"
  9. elif [ -n "$APP_PORT" ]; then
  10. FWD="`echo $APP_PORT | sed 's|^tcp://||'`"
  11. fi
  12. ARGS=""
  13. if [ -n "$NGROK_AUTH" ]; then
  14. 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. PROTOCOL="http"
  31. if [ "$NGROK_PROTOCOL" == "TCP" ]; then
  32. PROTOCOL="tcp "
  33. fi
  34. if [ -n "$NGROK_USERNAME" ] && [ -n "$NGROK_PASSWORD" ] && [ -n "$NGROK_AUTH" ]; then
  35. ARGS="$ARGS -auth=\"$NGROK_USERNAME:$NGROK_PASSWORD\" "
  36. elif [ -n "$NGROK_USERNAME" ] || [ -n "$NGROK_PASSWORD" ]; then
  37. if [ -z "$NGROK_AUTH" ]; then
  38. echo "You must specify a username, password, and Ngrok authentication token to use the custom HTTP authentication."
  39. echo "Sign up for an authentication token at https://ngrok.com"
  40. exit 1
  41. fi
  42. fi
  43. case "$1" in
  44. -h|help) ARGS=$1 ;;
  45. *) ARGS="$PROTOCOL $ARGS -log stdout $* $FWD" ;;
  46. esac
  47. exec /bin/ngrok $ARGS