-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-tunnel-helper.sh
More file actions
executable file
·82 lines (60 loc) · 1.4 KB
/
docker-tunnel-helper.sh
File metadata and controls
executable file
·82 lines (60 loc) · 1.4 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/bash
set -ex
BIN="$(cd "$(dirname "$0")" ; pwd)"
source "${BIN}/update-settings.sh"
SERVER="$1"
shift
NAME="$1"
shift
HOST_SETTINGS="$(echo ~/.tunnel/"${SERVER}".sh)"
update-settings "${HOST_SETTINGS}"
END_POINT_SETTINGS="$(echo ~/.tunnel/"${NAME}".sh)"
update-settings "${END_POINT_SETTINGS}"
source "${HOST_SETTINGS}"
source "${END_POINT_SETTINGS}"
ID_FILE=''
USER=''
HOST='localhost'
PORT=''
END_POINT_CONTAINER=''
END_POINT_PORT=''
if [ -e "${HOST_SETTINGS}" ]
then
source "${HOST_SETTINGS}"
fi
if [ -e "${END_POINT_SETTINGS}" ]
then
source "${END_POINT_SETTINGS}"
fi
declare -a ARGUMENTS
function add-argument() {
ARGUMENTS[${#ARGUMENTS[@]}]="$1"
}
function add-arguments() {
for ITEM in "$@"
do
add-argument "${ITEM}"
done
}
function get-var() {
local NAME="$1"
eval "echo \${${NAME}}"
}
TARGET="${HOST}"
if [ -n "${USER}" ]
then
TARGET="${USER}@${TARGET}"
fi
if [ -n "${ID_FILE}" ]
then
add-arguments -i "$(echo ${ID_FILE} | sed -e "s;^~;${HOME};")"
fi
if [ -n "${PORT}" ]
then
add-arguments -p "${PORT}"
fi
add-argument "${TARGET}"
INSPECT_FORMAT="--format='{{.NetworkSettings.IPAddress}}:{{(index (index .NetworkSettings.Ports \"${END_POINT_THAT_PORT}/tcp\") 0).HostPort}}'"
FORWARD="$(ssh "${ARGUMENTS[@]}" docker inspect "${INSPECT_FORMAT}" "${END_POINT_CONTAINER}")"
set -x
ssh -L "${END_POINT_THIS_PORT}:${FORWARD}" -N -n "${ARGUMENTS[@]}"