-
Notifications
You must be signed in to change notification settings - Fork 0
/
ssh-server.sh
37 lines (26 loc) · 830 Bytes
/
ssh-server.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/bash
if [[ -z "$NGROK_TOKEN" ]]; then
echo "Please set 'NGROK_TOKEN'"
exit 2
fi
if [[ -z "$SSH_PASSWORD" ]]; then
echo "Please set 'SSH_PASSWORD' for user: $USER"
exit 3
fi
wget -q https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-386.zip
unzip ngrok-stable-linux-386.zip
chmod +x ./ngrok
echo -e "$SSH_PASSWORD\n$SSH_PASSWORD" | sudo passwd "$USER"
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 "To connect: $(grep -o -E "tcp://(.+)" < .ngrok.log | sed "s/tcp:\/\//ssh $USER@/" | sed "s/:/ -p /")"
echo ""
else
echo "$HAS_ERRORS"
exit 4
fi