2024-04-13 16:57:22 -06:00
|
|
|
#####################################################################
|
|
|
|
|
|
|
|
DEPENDENCIES+=(yq)
|
|
|
|
|
|
|
|
#####################################################################
|
|
|
|
|
2025-02-19 21:58:02 -07:00
|
|
|
${scwryptsmodule}.get-connection-string() {
|
2024-04-13 16:57:22 -06:00
|
|
|
local REMOTE_NAME="$1"
|
2025-02-19 21:58:02 -07:00
|
|
|
[ $(remote.config.query-connection .sessions.$REMOTE_NAME.host) ] \
|
|
|
|
|| echo.error "no such connection $REMOTE_NAME exists" \
|
2024-04-13 16:57:22 -06:00
|
|
|
|| return 1
|
|
|
|
|
2025-02-19 21:58:02 -07:00
|
|
|
local CONNECTION_HOST=$(remote.config.query-connection .sessions.$REMOTE_NAME.host)
|
2024-04-13 16:57:22 -06:00
|
|
|
[ $CONNECTION_HOST ] \
|
2025-02-19 21:58:02 -07:00
|
|
|
|| echo.error "connection $REMOTE_NAME is misconfigured; missing 'host' field" \
|
2024-04-13 16:57:22 -06:00
|
|
|
|| return 1
|
|
|
|
|
2025-02-19 21:58:02 -07:00
|
|
|
local CONNECTION_USER=$(remote.config.query-connection .sessions.$REMOTE_NAME.user)
|
|
|
|
[ $CONNECTION_USER ] || CONNECTION_USER=$(remote.config.query-connection .default.user)
|
2024-04-13 16:57:22 -06:00
|
|
|
|
|
|
|
[ $CONNECTION_USER ] \
|
|
|
|
&& CONNECTION_STRING="${CONNECTION_USER}@${CONNECTION_HOST}" \
|
|
|
|
|| CONNECTION_STRING="$CONNECTION_HOST" \
|
|
|
|
;
|
|
|
|
|
|
|
|
echo $CONNECTION_STRING
|
|
|
|
}
|
|
|
|
|
2025-02-19 21:58:02 -07:00
|
|
|
${scwryptsmodule}.get-ssh-args() {
|
2024-04-13 16:57:22 -06:00
|
|
|
local REMOTE_NAME
|
|
|
|
local TYPE=ssh
|
|
|
|
local USE_TTY=true
|
|
|
|
|
|
|
|
while [[ $# -gt 0 ]]
|
|
|
|
do
|
|
|
|
case $1 in
|
2025-02-19 21:58:02 -07:00
|
|
|
( -t | --type ) TYPE=$2; shift 1 ;;
|
|
|
|
( --use-tty ) USE_TTY=$2; shift 1 ;;
|
2024-04-13 16:57:22 -06:00
|
|
|
|
2025-02-19 21:58:02 -07:00
|
|
|
( --no-tty ) USE_TTY=false ;;
|
2024-04-13 16:57:22 -06:00
|
|
|
|
2025-02-19 21:58:02 -07:00
|
|
|
( * )
|
|
|
|
[ $REMOTE_NAME ] && { echo.error "too many args :c"; return 1; }
|
2024-04-13 16:57:22 -06:00
|
|
|
REMOTE_NAME=$1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift 1
|
|
|
|
done
|
|
|
|
|
|
|
|
local ARGS=()
|
|
|
|
[ $REMOTE_NAME ] || {
|
|
|
|
echo "${ARGS[@]}"
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2025-02-19 21:58:02 -07:00
|
|
|
local PORT=$(remote.config.query-connection .sessions.$REMOTE_NAME.port)
|
2024-04-13 16:57:22 -06:00
|
|
|
|
|
|
|
[ $PORT ] && {
|
|
|
|
case $TYPE in
|
2025-02-19 21:58:02 -07:00
|
|
|
( ssh | xserver | tmux ) ARGS+=(-p $PORT) ;;
|
|
|
|
( scp ) ARGS+=(-P $PORT) ;; # not really in use, just a sample
|
|
|
|
( * )
|
|
|
|
WARNING "
|
2024-04-13 16:57:22 -06:00
|
|
|
port is specified, but I'm not sure whether to use '-p' or '-P'
|
|
|
|
|
|
|
|
if this command fails, try adding your --type to the appropriate
|
2025-02-19 21:58:02 -07:00
|
|
|
list in '$(scwrypts.config.group remote root)/lib/config.module.zsh'
|
2024-04-13 16:57:22 -06:00
|
|
|
"
|
|
|
|
ARGS+=(-p $PORT)
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2025-05-25 12:27:44 -06:00
|
|
|
ARGS+=($(remote.config.query-connection .sessions.$REMOTE_NAME.$TYPE.args))
|
|
|
|
echo.debug "REMOTE_NAME : ${REMOTE_NAME}\nARGS : ${ARGS}\nSESSION : .session.$REMOTE_NAME.$TYPE.args"
|
2024-04-13 16:57:22 -06:00
|
|
|
|
|
|
|
[[ $USE_TTY =~ true ]] && ARGS+=(-t)
|
|
|
|
|
|
|
|
echo "${ARGS[@]}"
|
|
|
|
}
|
|
|
|
|
|
|
|
#####################################################################
|
|
|
|
|
2025-02-19 21:58:02 -07:00
|
|
|
${scwryptsmodule}.query-connection() {
|
|
|
|
utils.yq -oy -r $@ "$REMOTE_CONNECTIONS_FILE" \
|
2024-04-13 16:57:22 -06:00
|
|
|
| grep -v ^null$
|
|
|
|
}
|
|
|
|
|
2025-02-19 21:58:02 -07:00
|
|
|
${scwryptsmodule}.query-connection-with-fallback() {
|
2024-04-13 16:57:22 -06:00
|
|
|
while [[ $# -gt 0 ]] && [ ! $QUERY_RESULT ]
|
|
|
|
do
|
|
|
|
case $1 in
|
2025-02-19 21:58:02 -07:00
|
|
|
( .* ) QUERY_RESULT=$(remote.config.query-connection $1) ;;
|
|
|
|
( * ) QUERY_RESULT="$1" ;; # allows raw default value
|
2024-04-13 16:57:22 -06:00
|
|
|
esac
|
|
|
|
shift 1
|
|
|
|
done
|
|
|
|
|
|
|
|
echo $QUERY_RESULT
|
|
|
|
}
|