Introducing teleport helpers
This commit is contained in:
parent
f224a3c4b7
commit
2f4f2dbb66
6 changed files with 141 additions and 0 deletions
48
_src.posix/private_dot_local/bin/executable_tssh-with-tunnel
Normal file
48
_src.posix/private_dot_local/bin/executable_tssh-with-tunnel
Normal file
|
@ -0,0 +1,48 @@
|
|||
#! /usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
SCRIPT_NAME="${0##*/}"
|
||||
usage() {
|
||||
printf '%s\n' \
|
||||
'Open a tunnel to the VMS external IP' \
|
||||
'' \
|
||||
'Usage:' \
|
||||
" ${SCRIPT_NAME} <search> [ssh args...]" \
|
||||
'' \
|
||||
'Env manipulators:' \
|
||||
' LOCAL_PORT default is 8443' \
|
||||
' TARGET_PORT default is 443' \
|
||||
' SSHUSER default is vastdata' \
|
||||
' VMS default is auto-detected' \
|
||||
''
|
||||
exit 2
|
||||
}
|
||||
|
||||
if [[ $# -eq 0 ]]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
LOCAL_PORT="${LOCAL_PORT:-8443}"
|
||||
TARGET_PORT="${TARGET_PORT:-443}"
|
||||
SEARCH="$1"
|
||||
SSHUSER="${SSHUSER:-vastdata}"
|
||||
|
||||
TARGET="${SSHUSER}@$(tsh-get "$SEARCH" "$SSHUSER")"
|
||||
|
||||
VMS="${VMS:-"$(awk '$5 { split($4, cidr, "/"); print cidr[1] }' <(tsh ssh "${TARGET}" bash -l <<SSHEOF
|
||||
VMS="\$(clush -g cnodes 'docker ps | grep vast_vms | grep -v grep' 2>/dev/null | cut -d':' -f1)" \
|
||||
&& clush -w "\$VMS" ip -4 -br a
|
||||
SSHEOF
|
||||
))"}"
|
||||
|
||||
TUNNEL="-L ${LOCAL_PORT}:${VMS}:${TARGET_PORT}"
|
||||
|
||||
RUN="${RUN:-}"
|
||||
if [[ -z "$RUN" && -n "$(command -v zellij)" ]]; then
|
||||
RUN="zellij run --floating --pinned 'true' --name '${SCRIPT_NAME} ${SEARCH}: ${TUNNEL} ${TARGET}' --"
|
||||
fi
|
||||
|
||||
printf "Executing: %s ...\n" "tsh ssh ${TUNNEL} ${TARGET} ${*:2}" >&2
|
||||
eval "${RUN} tsh ssh ${TUNNEL} '${TARGET}' ${*:2}"
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue