Skip to content

Commit fdd8245

Browse files
committed
refactor(entrypoint): beautify script
* create temp dir if not exist * use curly braces for variable substitution
1 parent e497513 commit fdd8245

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

rootfs/entrypoint.sh

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
11
#!/bin/bash
22

33
function open_ssh_tunnel {
4-
local timestamp=`date +%s`
4+
local timestamp=$(date +%s)
55

66
local tunnel_host=${SSH_TUNNEL_HOST:-"serveo.net"}
77
local tunnel_port=${SSH_TUNNEL_PORT:-"443"}
8-
local tunnel_prefix=${SSH_TUNNEL_PREFIX:-$timestamp}
8+
local tunnel_prefix=${SSH_TUNNEL_PREFIX:-${timestamp}}
99
local tunnel_bindings=()
1010
local tunnel_urls=()
1111

1212
for address in ${ADDRESSES[@]}
1313
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}")
1818
done
1919

20-
if [ -z "$tunnel_bindings" ]; then
20+
if [ -z "${tunnel_bindings}" ]; then
2121
exit 1
2222
else
2323
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}
2526

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}
2930
fi
3031
}
3132

0 commit comments

Comments
 (0)