-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlink-ssh.sh
More file actions
executable file
·70 lines (61 loc) · 1.19 KB
/
link-ssh.sh
File metadata and controls
executable file
·70 lines (61 loc) · 1.19 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
#!/bin/bash
# ssh to a linked container (e.g., a tunnel endpoint)
declare -a ARGUMENTS
function add-argument() {
ARGUMENTS[${#ARGUMENTS[@]}]="$1"
}
CONTAINER="$1"
shift
USER_PART=''
IDENTITY="${HOME}/.ssh/id_rsa"
while [ ".$1" != ".${1#-}" ]
do
OPT="$1"
shift
if [ ".${OPT}" = ".--" ]
then
break
fi
case "${OPT}" in
-u|--user)
USER_PART="$1@"
shift
;;
-p|--port)
add-argument -p
add-argument "$1"
shift
;;
-i)
IDENTITY="$1"
shift
;;
-v|-vv|-vvv)
add-argument "${OPT}"
set +x
;;
*)
echo "Unknown option: ${OPT}" >&2
exit 1
esac
done
NAME="${CONTAINER}"
if [ -n "${USER}" ]
then
NAME="${USER}_${NAME}"
USER="${USER}@"
fi
NAME="ssh_${NAME}"
SSH_DIR="$(echo ~/.ssh)"
add-argument -i
add-argument "${IDENTITY}"
add-argument -o
add-argument "UserKnownHostsFile=${SSH_DIR}/known_hosts"
docker rm -f "${NAME}" || true
run-docker-wrapped-command.sh \
--name "${NAME}" \
-i -t \
-v "${SSH_DIR}:${SSH_DIR}" \
--link "${CONTAINER}" \
ssh \
ssh -i "${IDENTITY}" "${ARGUMENTS[@]}" "${USER_PART}${CONTAINER}" "$@"