-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsshome
More file actions
executable file
·41 lines (34 loc) · 963 Bytes
/
sshome
File metadata and controls
executable file
·41 lines (34 loc) · 963 Bytes
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
37
38
39
40
#!/bin/bash
# This script is to create a remote tunnel to 'tuanm.dev' server.
# Ensure we can connect to the server before running this script.
# Local HTTP server will then be exposed at https://demo.tuanm.dev.
remote_port=6969
local_port=${2:-80}
command="autossh -N -R localhost:$remote_port:localhost:$local_port tuanm.dev"
disconnect_short_key="^C"
help() {
echo "Usage: sshome start [port]"
}
connect() {
echo "Exposing http://localhost:$local_port to https://demo.tuanm.dev..."
echo "Press $disconnect_short_key to disconnect."
echo "Press $disconnect_short_key^C to exit."
bash -c "$command"
echo -e "\nReconnecting..."
}
start() {
while true; do
connected=`ps aux | grep "$command" | grep -v "grep"`
if test -n $connected; then
connect
fi
for i in {5..1}; do
echo -en "$i\r"; sleep 1
done
done
}
if [ "$1" = "start" ]; then
start
else
help
fi