sshuttle/hack/exec-sshuttle

74 lines
1.5 KiB
Plaintext
Raw Normal View History

2024-01-01 11:21:22 +01:00
#!/usr/bin/env bash
set -e
function with_set_x() {
set -x
"$@"
{
ec=$?
set +x
return $ec
} 2>/dev/null
}
ssh_cmd='ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'
args=()
while [[ $# -gt 0 ]]; do
arg=$1
shift
case "$arg" in
-v)
ssh_cmd+='-v'
;;
--copy-id)
ssh_copy_id=true
continue
;;
--sshuttle-bin=*)
sshuttle_bin="${arg#*=}"
continue
;;
-*)
;;
*)
if [[ -z "$node" ]]; then
node=$arg
continue
fi
;;
esac
args+=("$arg")
done
2024-01-01 11:21:22 +01:00
2024-01-02 05:16:22 +01:00
port="2222"
2024-01-01 11:21:22 +01:00
user="test:test"
if [[ $node == node-* ]]; then
host=$("$(dirname "$0")/test-bed" get-ip "$node")
index=${node#node-}
args+=("10.55.$index.0/24")
else
host=$node
fi
if [[ "${args[$(( ${#args[@]} - 1 ))]}" != *.* && "${args[$(( ${#args[@]} - 1 ))]}" != *:* ]]; then
echo "No subnet specified. Using -N" >&2
args+=('-N')
fi
2024-01-01 11:21:22 +01:00
if ! command -v sshpass >/dev/null; then
echo "sshpass is not found. You might have to manually enter ssh password: 'test'" >&2
user=${user%:*}
2024-01-01 11:21:22 +01:00
fi
if [[ $ssh_copy_id == true ]]; then
echo "Trying to make it passwordless" >&2
with_set_x ssh-copy-id -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p "$port" "$user@$host"
2024-01-01 11:21:22 +01:00
fi
sshuttle_bin=${sshuttle_bin:-"$(dirname "$0")/../run"}
2024-01-01 11:21:22 +01:00
set -x
exec "${sshuttle_bin}" -r "$user@$host:$port" --ssh-cmd "$ssh_cmd" "${args[@]}"