-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcanal
executable file
·53 lines (42 loc) · 1.21 KB
/
canal
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
#!/bin/bash -e
# Switch to this script's directory
cd "${0%/*}"
export AUTOSSH_POLL=60
# kill all the children when done
trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT
# is this a registered vessel?
infopath="boats/$(hostname -f)"
if [[ ! -f "${infopath}" ]]
then
echo "Not a registered machine."
exit 1
fi
function get_iface_inets {
ip addr | awk '/^[0-9]+:/ {
sub(/:/,"",$2); iface=$2 }
/^[[:space:]]*inet / {
split($2, a, "/")
print a[1], iface
}'
}
for lighthouse in $(ls lighthouses/*)
do
ip=$(cat "${lighthouse}" | head -n1)
ports=(`cat "${infopath}" | head -n1`)
for iface in eno2 usb0
do
while true; do
# Get the ip:iface mapping for binding
iface_inets=`get_iface_inets`
inet=$(echo "${iface_inets}" | grep ${iface} | cut -f1 -d' ')
if [[ ! -z ${inet} ]]; then
autossh -NTR \*:${ports[0]}:localhost:22 -oStrictHostKeyChecking=accept-new -oExitOnForwardFailure=yes -oBatchMode=yes -b ${inet} stagecast@${ip} || true
else
echo "Cannot bind to interface ${iface}. Retrying in 1 minute."
fi
sleep ${AUTOSSH_POLL} # try to reconnect even if the underlying ssh command failed
done &
ports=("${ports[@]:1}")
done
done
wait