-
-
Save Artistan/e1da8a060900d5db3c3eb001e076b4e9 to your computer and use it in GitHub Desktop.
Get ngrok hostname from command line
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
######################################################################################## | |
# I do not need to use the ngrok subdomains... | |
# start ngrok for my local box (vagrant homestead) in th background | |
# get the cname from command line for the ngrok alias | |
# update my subdomain cname to point at new ngrok name | |
# use it!!! | |
######################################################################################## | |
# requires ngrok and jq installed. | |
# get the ip:port | |
if [ -z "$1" ]; then | |
export WEBHOOK_LOCAL_IP=192.168.10.11:80 | |
else | |
export WEBHOOK_LOCAL_IP="$1" | |
fi | |
# get the local hostname | |
if [ -z "$2" ]; then | |
export WEBHOOK_LOCAL_HOST="unwired.local" | |
else | |
export WEBHOOK_LOCAL_HOST="$2" | |
fi | |
nohup ngrok http "$WEBHOOK_LOCAL_IP" -host-header="$WEBHOOK_LOCAL_HOST" & | |
export WEBHOOK_URL="$(curl -s http://localhost:4040/api/tunnels/command_line | jq -r --unbuffered '.public_url')" | |
export WEBHOOK_DOMAIN="${WEBHOOK_URL#https://}" | |
# API TOKEN -- https://cloud.digitalocean.com/account/api/tokens | |
if [ -z "$DROPLET_TOKEN" ]; then | |
echo "unknown token.... cannot update droplet domain, sorry." | |
else | |
# update the record for the CNAME_ID you are looking for | |
curl -X PUT -H "Content-Type: application/json" -H "Authorization: Bearer $DROPLET_TOKEN" -d "{\"data\":\"${WEBHOOK_DOMAIN}.\"}" "https://api.digitalocean.com/v2/domains/${DROPLET_DOMAIN_NAME}/records/${DROPLET_CNAME_ID}" | jq | |
fi | |
echo $WEBHOOK_URL; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# https://stackoverflow.com/questions/20802320/detect-if-homebrew-package-is-installed | |
if brew ls --versions myformula > /dev/null; then | |
# The package is installed | |
brew cask install ngrok | |
else | |
# The package is not installed | |
if hash npm 2>/dev/null; then | |
npm i -g ngrok | |
else | |
echo "no brew or npm to work with." | |
fi | |
fi | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# test if you rc file is working | |
echo $DROPLET_TOKEN | |
echo $DROPLET_DOMAIN_NAME | |
echo $DROPLET_CNAME_ID |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# for droplet auto update -- add to your zsh / bash rc file | |
# https://cloud.digitalocean.com/account/api/tokens | |
export DROPLET_TOKEN="this is my token" | |
# the public domain i will use with a cname pointing at ngrok | |
export DROPLET_DOMAIN_NAME="mydomain.com" | |
# id for the cname i want updated to point at ngrok | |
# set this cname to a very low TTL so that it will update quickly when you start the service. | |
export DROPLET_CNAME_ID="234234" | |
# setup aliases for each of your boxes that you want to share publicly... this assumes ngrok_background.sh script in your home directory | |
alias homestead_public="~/ngrok_background.sh 192.168.10.10:80 homestead.test" | |
alias kill_ngrok="killall ngrok" | |
aliase ngrok_status="curl -s http://localhost:4040/api/tunnels/command_line | jq -r --unbuffered" | |
## droplet helpers | |
# Retrieve an existing Domain | |
alias droplet_domain='curl -X GET -H "Content-Type: application/json" -H "Authorization: Bearer $DROPLET_TOKEN" "https://api.digitalocean.com/v2/domains/${DOMAIN_NAME}" | jq' | |
# get records for the domain... | |
alias droplet_domain_records='curl -X GET -H "Content-Type: application/json" -d '{"per_page": "200"}' -H "Authorization: Bearer $DROPLET_TOKEN" "https://api.digitalocean.com/v2/domains/${DOMAIN_NAME}/records" | jq' | |
# update the record for the CNAME_ID you are looking for | |
alias droplet_update_cname='curl -X PUT -H "Content-Type: application/json" -H "Authorization: Bearer $DROPLET_TOKEN" -d "{\"data\":\"${WEBHOOK_DOMAIN}.\"}" "https://api.digitalocean.com/v2/domains/${DROPLET_DOMAIN_NAME}/records/${DROPLET_CNAME_ID}" | jq' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment