mirror of
https://github.com/DictXiong/dotfiles.git
synced 2026-01-10 04:27:48 +08:00
feat(riot): sshr for ssh -R
This commit is contained in:
parent
426e97c10e
commit
c86cc85e24
33
scripts/riot
33
scripts/riot
@ -195,20 +195,26 @@ run_ssh()
|
|||||||
# sshl
|
# sshl
|
||||||
run_sshl()
|
run_sshl()
|
||||||
{
|
{
|
||||||
is_port() {
|
local arg left right localsock access
|
||||||
if [[ "$1" =~ ^[1-9][0-9]*$ && $1 -gt 1 && $1 -lt 65535 ]]; then return 0; else return 1; fi
|
local res="${1//[^:]}"
|
||||||
}
|
local lorr="-L"
|
||||||
res="${1//[^:]}"
|
if [[ "${FUNCNAME[1]}" == "run_sshr" ]]; then
|
||||||
|
lorr="-R"
|
||||||
|
fi
|
||||||
if [[ ${#res} -eq 2 ]]; then
|
if [[ ${#res} -eq 2 ]]; then
|
||||||
arg="$1"
|
arg="$1"
|
||||||
elif [[ ${#res} -eq 0 ]]; then
|
elif [[ ${#res} -eq 0 ]]; then
|
||||||
arg="$(get_free_port):localhost:$1"
|
if [[ "$lorr" == "-R" ]]; then
|
||||||
|
arg="$1"
|
||||||
|
else
|
||||||
|
arg="$(get_free_port):localhost:$1"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
left=${1%%:*}
|
left=${1%%:*}
|
||||||
right=${1##*:}
|
right=${1##*:}
|
||||||
if is_port "$left"; then
|
if check_port "$left"; then
|
||||||
arg="$1"
|
arg="$1"
|
||||||
elif is_port "$right"; then
|
elif check_port "$right"; then
|
||||||
arg="$(get_free_port):$1"
|
arg="$(get_free_port):$1"
|
||||||
else
|
else
|
||||||
arg="$1"
|
arg="$1"
|
||||||
@ -220,13 +226,19 @@ run_sshl()
|
|||||||
else
|
else
|
||||||
access="localhost:${arg%%:*}"
|
access="localhost:${arg%%:*}"
|
||||||
fi
|
fi
|
||||||
SSH_OPTIONS+=("-NC" "-L" "$arg")
|
SSH_OPTIONS+=("-NC" "$lorr" "$arg")
|
||||||
prepare_ssh_cmd ssh
|
prepare_ssh_cmd ssh
|
||||||
print_cmd
|
print_cmd
|
||||||
fmt_note " > please access $access"
|
fmt_note " > please access $access"
|
||||||
eval_or_echo
|
eval_or_echo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# sshr
|
||||||
|
run_sshr()
|
||||||
|
{
|
||||||
|
run_sshl "$1"
|
||||||
|
}
|
||||||
|
|
||||||
# sshd
|
# sshd
|
||||||
run_sshd()
|
run_sshd()
|
||||||
{
|
{
|
||||||
@ -389,6 +401,11 @@ router() {
|
|||||||
test "${#positional[@]}" -eq 3 || fmt_fatal "sshl requires exactly one argument"
|
test "${#positional[@]}" -eq 3 || fmt_fatal "sshl requires exactly one argument"
|
||||||
run_sshl "${positional[2]}"
|
run_sshl "${positional[2]}"
|
||||||
;;
|
;;
|
||||||
|
sshr )
|
||||||
|
test -n "${positional[2]}" || fmt_fatal "no target address provided"
|
||||||
|
test "${#positional[@]}" -eq 3 || fmt_fatal "sshr requires exactly one argument"
|
||||||
|
run_sshr "${positional[2]}"
|
||||||
|
;;
|
||||||
sshd )
|
sshd )
|
||||||
test "${#positional[@]}" -le 3 || fmt_fatal "sshd requires one or no arguments"
|
test "${#positional[@]}" -le 3 || fmt_fatal "sshd requires one or no arguments"
|
||||||
if [[ "${#positional[@]}" -eq 3 ]]; then
|
if [[ "${#positional[@]}" -eq 3 ]]; then
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user