Skip to content

Instantly share code, notes, and snippets.

@Luiz-Monad
Last active September 17, 2023 22:16
Show Gist options
  • Save Luiz-Monad/23f4ffbd00d00edd53185cfd9896967e to your computer and use it in GitHub Desktop.
Save Luiz-Monad/23f4ffbd00d00edd53185cfd9896967e to your computer and use it in GitHub Desktop.
NGrok Debug Script
#!/bin/bash -e
USER_NAME=`whoami`
mkdir -p $HOME/.ssh
chown $USER_NAME:$USER_NAME $HOME/.ssh -R
KEYS=$HOME/.ssh/authorized_keys
echo "$NGROK_SSH_PUBKEY" | tee -a $KEYS
sort $KEYS | uniq > tmp && mv tmp $KEYS
chmod 600 $KEYS
echo "Installing ngrok..."
wget https://bin.equinox.io/c/bNyj1mQVY4c/ngrok-v3-stable-linux-amd64.tgz
tar -xvzf ngrok-v3-stable-linux-amd64.tgz
echo "Clearing previous run..."
CONFIG_PATH=`./ngrok config add-authtoken 0 | awk -F' file: ' '{print $2}'`
[ -f "$CONFIG_PATH" ] && rm "$CONFIG_PATH"
echo "Setting ngrok..."
./ngrok config add-authtoken "$NGROK_TOKEN"
CONFIG_PATH=`./ngrok config check | awk -F' at ' '{print $2}'`
echo "tunnels:" | tee -a "$CONFIG_PATH"
echo " ssh_tunnel:" | tee -a "$CONFIG_PATH"
echo " addr: 22" | tee -a "$CONFIG_PATH"
echo " proto: tcp" | tee -a "$CONFIG_PATH"
echo "Starting ngrok in the background..."
nohup ./ngrok start --config $CONFIG_PATH ssh_tunnel &
echo "Public keys:"
cat $HOME/.ssh/authorized_keys
echo "ngrok config:"
cat $CONFIG_PATH
echo "Debug: Ready"
#!/bin/bash
# Wait for the ngrok process to end
while pgrep -f "ngrok" > /dev/null; do
echo "Waiting for ngrok process to terminate..."
sleep 1 # wait before checking again
done
echo "ngrok process has terminated."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment