Last active
August 18, 2020 03:57
-
-
Save jmcmullen/0490778f9fdd1476d409789ae627b681 to your computer and use it in GitHub Desktop.
This file contains hidden or 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/bash | |
| if [[ -z "$NGROK_TOKEN" ]]; then | |
| echo "Please set 'NGROK_TOKEN'" | |
| exit 2 | |
| fi | |
| if [[ -z "$USER_PASS" ]]; then | |
| echo "Please set 'USER_PASS' for user: $USER" | |
| exit 3 | |
| fi | |
| echo "### Install ngrok ###" | |
| wget -q https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-386.zip | |
| unzip ngrok-stable-linux-386.zip | |
| chmod +x ./ngrok | |
| echo "### Update user: $USER password ###" | |
| echo -e "$USER_PASS\n$USER_PASS" | passwd "$(whoami)" | |
| echo "### Start ngrok proxy for 22 port ###" | |
| rm -f .ngrok.log | |
| ./ngrok authtoken "$NGROK_TOKEN" | |
| ./ngrok tcp 22 --log ".ngrok.log" & | |
| sleep 10 | |
| HAS_ERRORS=$(grep "command failed" < .ngrok.log) | |
| if [[ -z "$HAS_ERRORS" ]]; then | |
| echo "" | |
| echo "==========================================" | |
| echo "To connect: $(grep -o -E "tcp://(.+)" < .ngrok.log | sed "s/tcp:\/\//ssh $(whoami)@/" | sed "s/:/ -p /")" | |
| echo "==========================================" | |
| else | |
| echo "$HAS_ERRORS" | |
| exit 4 | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment