mirror of
https://github.com/sshuttle/sshuttle.git
synced 2024-11-24 00:44:07 +01:00
Update exec-sshuttle script and related files
This commit is contained in:
parent
db9ec36fac
commit
371258991f
@ -3,6 +3,8 @@
|
||||
```bash
|
||||
test-bed up -d # start containers
|
||||
|
||||
exec-sshuttle <node> [--copy-id] [--shuttle-bin=/path/to/sshttle] [sshuttle-args...]
|
||||
|
||||
exec-sshuttle node-1 # start sshuttle to connect to node-1
|
||||
|
||||
exec-tool curl node-1 # curl to nginx instance running on node1 via IP that is only reachable via sshuttle
|
||||
|
@ -1,29 +1,73 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
node=$1
|
||||
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
|
||||
|
||||
if [[ ! $node =~ [1-9]+ ]]; then
|
||||
echo "node argument missing. should be '1' , '2' etc"
|
||||
exit 2
|
||||
fi
|
||||
shift
|
||||
|
||||
port="2222"
|
||||
subnet_args="-N"
|
||||
host=$("$(dirname "$0")/test-bed" get-ip "$node")
|
||||
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
|
||||
|
||||
if ! command -v sshpass >/dev/null; then
|
||||
echo "sshpass is not found. You have to manually enter ssh password: 'test'" >&2
|
||||
user="test"
|
||||
fi
|
||||
ssh_cmd='ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'
|
||||
|
||||
if [[ "$*" =~ -v ]]; then
|
||||
ssh_cmd+='-v'
|
||||
echo "sshpass is not found. You might have to manually enter ssh password: 'test'" >&2
|
||||
user=${user%:*}
|
||||
fi
|
||||
|
||||
SSHUTTLE_BIN=${SSHUTTLE_BIN:-"$(dirname "$0")/../run"}
|
||||
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"
|
||||
fi
|
||||
|
||||
sshuttle_bin=${sshuttle_bin:-"$(dirname "$0")/../run"}
|
||||
set -x
|
||||
exec "${SSHUTTLE_BIN}" -r "$user@$host:$port" --ssh-cmd "$ssh_cmd" "$@" $subnet_args
|
||||
exec "${sshuttle_bin}" -r "$user@$host:$port" --ssh-cmd "$ssh_cmd" "${args[@]}"
|
||||
|
@ -5,8 +5,13 @@ tool=${1?:"tool argument missing. should be one of iperf3,ping,curl,ab"}
|
||||
node=${2?:"node argument missing. should be 'node-1' , 'node-2' etc"}
|
||||
shift 2
|
||||
|
||||
index=${node#node-}
|
||||
ip="10.55.$index.77"
|
||||
if [[ $node == node-* ]]; then
|
||||
index=${node#node-}
|
||||
host="10.55.$index.77"
|
||||
else
|
||||
host=$node
|
||||
fi
|
||||
|
||||
connect_timeout_sec=3
|
||||
|
||||
function with_set_x() {
|
||||
@ -21,19 +26,22 @@ function with_set_x() {
|
||||
|
||||
case "$tool" in
|
||||
ping)
|
||||
with_set_x exec ping -W $connect_timeout_sec "$@" "$ip"
|
||||
with_set_x exec ping -W $connect_timeout_sec "$@" "$host"
|
||||
;;
|
||||
iperf3)
|
||||
port=5001
|
||||
with_set_x exec iperf3 --client "$ip" --port=$port --connect-timeout=$((connect_timeout_sec * 1000)) "$@"
|
||||
with_set_x exec iperf3 --client "$host" --port=$port --connect-timeout=$((connect_timeout_sec * 1000)) "$@"
|
||||
;;
|
||||
curl)
|
||||
port=8080
|
||||
with_set_x exec curl "http://$ip:$port/" -v --connect-timeout $connect_timeout_sec "$@"
|
||||
with_set_x exec curl "http://$host:$port/" -v --connect-timeout $connect_timeout_sec "$@"
|
||||
;;
|
||||
ab)
|
||||
port=8080
|
||||
with_set_x exec ab -n 100 -c 20 -s $connect_timeout_sec "$@" "http://$ip:$port/"
|
||||
if [[ " $*" != *" -n "* && " $*" != *" -c "* ]]; then
|
||||
set -- -n 500 -c 50 "$@"
|
||||
fi
|
||||
with_set_x exec ab -s $connect_timeout_sec "$@" "http://$host:$port/"
|
||||
;;
|
||||
*)
|
||||
echo "Unknown tool: $tool" >&2
|
||||
|
@ -16,11 +16,12 @@ function with_set_x() {
|
||||
|
||||
benchmark() {
|
||||
local sshuttle_bin="${1?:}"
|
||||
local node="${2:-'node-1'}"
|
||||
echo -e "\n======== Benchmarking sshuttle: $sshuttle_bin ========"
|
||||
if [[ "$sshuttle_bin" == dev ]]; then
|
||||
sshuttle_bin="../run"
|
||||
fi
|
||||
SSHUTTLE_BIN=$sshuttle_bin ./exec-sshuttle 1 --listen 55771 &
|
||||
./exec-sshuttle "$node" --sshuttle-bin="$sshuttle_bin" --listen 55771 &
|
||||
sshuttle_pid=$!
|
||||
trap 'kill -0 $sshuttle_pid &>/dev/null && kill -15 $sshuttle_pid' EXIT
|
||||
while ! nc -z localhost 55771; do sleep 0.1; done
|
||||
@ -33,6 +34,6 @@ benchmark() {
|
||||
if [[ "$1" ]]; then
|
||||
benchmark "$1"
|
||||
else
|
||||
benchmark "${SSHUTTLE_BIN:-/bin/sshuttle}"
|
||||
benchmark dev
|
||||
benchmark "${SSHUTTLE_BIN:-/bin/sshuttle}" node-1
|
||||
benchmark dev node-1
|
||||
fi
|
||||
|
@ -5,5 +5,5 @@ cd "$(dirname "$0")/.."
|
||||
export PYTHONPATH=.
|
||||
|
||||
set -x
|
||||
python -m flake8 sshuttle tests
|
||||
python -m pytest .
|
||||
python -m flake8 .
|
||||
|
Loading…
Reference in New Issue
Block a user