|
1 | 1 | #!/bin/bash
|
2 | 2 |
|
3 | 3 | function open_ssh_tunnel {
|
4 |
| - local timestamp=`date +%s` |
| 4 | + local timestamp=$(date +%s) |
5 | 5 |
|
6 | 6 | local tunnel_host=${SSH_TUNNEL_HOST:-"serveo.net"}
|
7 | 7 | local tunnel_port=${SSH_TUNNEL_PORT:-"443"}
|
8 |
| - local tunnel_prefix=${SSH_TUNNEL_PREFIX:-$timestamp} |
| 8 | + local tunnel_prefix=${SSH_TUNNEL_PREFIX:-${timestamp}} |
9 | 9 | local tunnel_bindings=()
|
10 | 10 | local tunnel_urls=()
|
11 | 11 |
|
12 | 12 | for address in ${ADDRESSES[@]}
|
13 | 13 | do
|
14 |
| - local remote_hostname=$(echo $address | cut -d ':' -f 1) |
15 |
| - local tunnel_address=$tunnel_prefix-$remote_hostname:$tunnel_port |
16 |
| - tunnel_bindings+=("$tunnel_address:$address") |
17 |
| - tunnel_urls+=("https://$tunnel_prefix-$remote_hostname.$tunnel_host") |
| 14 | + local remote_hostname=$(echo ${address} | cut -d ':' -f 1) |
| 15 | + local tunnel_address=${tunnel_prefix}-${remote_hostname}:${tunnel_port} |
| 16 | + tunnel_bindings+=("${tunnel_address}:${address}") |
| 17 | + tunnel_urls+=("https://${tunnel_prefix}-${remote_hostname}.${tunnel_host}") |
18 | 18 | done
|
19 | 19 |
|
20 |
| - if [ -z "$tunnel_bindings" ]; then |
| 20 | + if [ -z "${tunnel_bindings}" ]; then |
21 | 21 | exit 1
|
22 | 22 | else
|
23 | 23 | local output_file=${OUTPUT_FILE:-"/tmp/ssh-proxy/output.txt"}
|
24 |
| - printf "%s\n" ${tunnel_urls[@]} > $output_file |
| 24 | + mkdir -p $(dirname ${output_file}) |
| 25 | + printf "%s\n" ${tunnel_urls[@]} > ${output_file} |
25 | 26 |
|
26 |
| - local cmd="ssh -T -o ExitOnForwardFailure=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null $SSH_ARGS $(printf " -R %s" ${tunnel_bindings[@]}) $tunnel_host" |
27 |
| - echo $cmd |
28 |
| - exec $cmd |
| 27 | + local cmd="ssh -T -o ExitOnForwardFailure=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ${SSH_ARGS} $(printf " -R %s" ${tunnel_bindings[@]}) ${tunnel_host}" |
| 28 | + echo ${cmd} |
| 29 | + exec ${cmd} |
29 | 30 | fi
|
30 | 31 | }
|
31 | 32 |
|
|
0 commit comments