update exec-sshuttle script

This commit is contained in:
nom3ad 2024-04-14 12:40:46 +05:30 committed by Brian May
parent 6b8e402367
commit c4255a23f0
2 changed files with 70 additions and 32 deletions

View File

@ -4,7 +4,7 @@
test-bed up -d # start containers test-bed up -d # start containers
exec-sshuttle <node-id> [--copy-id] [--server-py=2.7|3.6|3.8] [--client-py=2.7|3.6|3.8] [--sshuttle-bin=/path/to/sshuttle] [sshuttle-args...] exec-sshuttle <node-id> [--copy-id] [--server-py=2.7|3.6|3.8] [--client-py=2.7|3.6|3.8] [--sshuttle-bin=/path/to/sshuttle] [sshuttle-args...]
# --copy-id -> optionally do ssh-copy-id to make it passwordless # --copy-id -> optionally do ssh-copy-id to make it passwordless for future runs
# --sshuttle-bin -> use another sshuttle binary instead of one from dev setup # --sshuttle-bin -> use another sshuttle binary instead of one from dev setup
# --server-py -> Python version to use in server. (manged by pyenv) # --server-py -> Python version to use in server. (manged by pyenv)
# --client-py -> Python version to use in client (manged by pyenv) # --client-py -> Python version to use in client (manged by pyenv)
@ -17,3 +17,5 @@ exec-tool iperf3 node-1 # measure throughput to node-1
run-benchmark node-1 --client-py=3.10 run-benchmark node-1 --client-py=3.10
``` ```
<https://learn.microsoft.com/en-us/windows-server/administration/openssh/openssh_server_configuration#configuring-the-default-shell-for-openssh-in-windows>

View File

@ -1,6 +1,8 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -e set -e
export MSYS_NO_PATHCONV=1
function with_set_x() { function with_set_x() {
set -x set -x
"$@" "$@"
@ -18,75 +20,109 @@ function log() {
ssh_cmd='ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null' ssh_cmd='ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'
ssh_copy_id=false ssh_copy_id=false
args=() args=()
subnet_args=()
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]; do
arg=$1 arg=$1
shift shift
case "$arg" in case "$arg" in
-v) -v|-vv*)
ssh_cmd+='-v' ssh_cmd+=" -v"
args+=("$arg")
;; ;;
-r) -r)
args+=("$arg" "$1") args+=("-r" "$1")
shift shift
continue
;; ;;
--copy-id) --copy-id)
ssh_copy_id=true ssh_copy_id=true
continue
;; ;;
--server-py=*) --server-py=*)
server_pyenv_ver="${arg#*=}" server_pyenv_ver="${arg#*=}"
continue
;; ;;
--client-py=*) --client-py=*)
client_pyenv_ver="${arg#*=}" client_pyenv_ver="${arg#*=}"
continue
;; ;;
-6) -6)
ipv6_only=true ipv6_only=true
continue
;; ;;
--sshuttle-bin=*) --sshuttle-bin=*)
sshuttle_bin="${arg#*=}" sshuttle_bin="${arg#*=}"
continue
;; ;;
-*) ;; -N|*/*)
subnet_args+=("$arg")
;;
-*)
args+=("$arg")
;;
*) *)
if [[ -z "$node" ]]; then if [[ -z "$target" ]]; then
node=$arg target=$arg
continue else
args+=("$arg")
fi fi
;; ;;
esac esac
args+=("$arg")
done done
if [[ ${#subnet_args[@]} -eq 0 ]]; then
subnet_args=("-N")
fi
if [[ $target == node-* ]]; then
log "Target is a a test-bed node"
port="2222" port="2222"
user="test:test" user_part="test:test"
host=$("$(dirname "$0")/test-bed" get-ip "$target")
if [[ $node == node-* ]]; then index=${target#node-}
pycmd="/pyenv/shims/python"
ssh_cmd+=" -o SetEnv=PYENV_VERSION=${server_pyenv_ver:-'3'}"
args=("--python=$pycmd" "${args[@]}")
host=$("$(dirname "$0")/test-bed" get-ip "$node")
index=${node#node-}
if [[ $ipv6_only == true ]]; then if [[ $ipv6_only == true ]]; then
args+=("2001:0DB8::/112") args+=("2001:0DB8::/112")
else else
args+=("10.55.$index.0/24") args+=("10.55.$index.0/24")
fi fi
else target="$user_part@$host:$port"
host=$node
fi
if ! command -v sshpass >/dev/null; then if ! command -v sshpass >/dev/null; then
log "sshpass is not found. You might have to manually enter ssh password: 'test'" log "sshpass is not found. You might have to manually enter ssh password: 'test'"
user=${user%:*} fi
if [[ -z $server_pyenv_ver ]]; then
log "server-py argumwnt is not specified. Setting it to 3.8"
server_pyenv_ver="3.8"
fi
fi
if [[ -n $server_pyenv_ver ]]; then
log "Would pass PYENV_VERRSION=$server_pyenv_ver to server. pyenv is required on server to make it work"
pycmd="/pyenv/shims/python"
ssh_cmd+=" -o SetEnv=PYENV_VERSION=${server_pyenv_ver:-'3'}"
args=("--python=$pycmd" "${args[@]}")
fi fi
if [[ $ssh_copy_id == true ]]; then if [[ $ssh_copy_id == true ]]; then
log "Trying to make it passwordless" log "Trying to make it passwordless"
with_set_x ssh-copy-id -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p "$port" "$user@$host" if [[ $target == *@* ]]; then
user_part="${target%%@*}"
host_part="${target#*@}"
else
user_part="$(whoami)"
host_part="$target"
fi
if [[ $host_part == *:* ]]; then
host="${host_part%:*}"
port="${host_part#*:}"
else
host="$host_part"
port="22"
fi
if [[ $user_part == *:* ]]; then
user="${user_part%:*}"
password="${user_part#*:}"
else
user="$user_part"
password=""
fi
cmd=(ssh-copy-id -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p "$port" "$user@$host")
if [[ -n $password ]] && command -v sshpass >/dev/null; then
cmd=(sshpass -p "$password" "${cmd[@]}")
fi
with_set_x "${cmd[@]}"
fi fi
if [[ -z $sshuttle_bin || "$sshuttle_bin" == dev ]]; then if [[ -z $sshuttle_bin || "$sshuttle_bin" == dev ]]; then
@ -115,9 +151,9 @@ if [[ " ${args[*]} " != *" --ssh-cmd "* ]]; then
fi fi
if [[ " ${args[*]} " != *" -r "* ]]; then if [[ " ${args[*]} " != *" -r "* ]]; then
args=("-r" "$user@$host:$port" "${args[@]}") args=("-r" "$target" "${args[@]}")
fi fi
set -x set -x
"${sshuttle_cmd[@]}" --version "${sshuttle_cmd[@]}" --version
exec "${sshuttle_cmd[@]}" "${args[@]}" exec "${sshuttle_cmd[@]}" "${args[@]}" "${subnet_args[@]}"