2023-07-20 20:49:06 +00:00
|
|
|
#####################################################################
|
|
|
|
|
|
|
|
DEPENDENCIES+=()
|
|
|
|
REQUIRED_ENV+=()
|
|
|
|
|
|
|
|
#####################################################################
|
|
|
|
|
|
|
|
PARSE_CONNECTION() {
|
|
|
|
[ ! $CONNECTION ] && [ ! $REMOTE_NAME ] && {
|
|
|
|
ERROR 'cannot parse connection without specifying CONNECTION or REMOTE_NAME'
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
[ $REMOTE_NAME ] && CONNECTION=$(GET_CONNECTION $REMOTE_NAME)
|
|
|
|
|
|
|
|
[ ! $CONNECTION ] && {
|
|
|
|
ERROR "no such connection with name '$REMOTE_NAME'"
|
|
|
|
}
|
|
|
|
|
|
|
|
local CONNECTION_DETAILS=$(echo $CONNECTION | sed 's/|/ /g;')
|
|
|
|
|
2023-11-11 14:16:28 +00:00
|
|
|
REMOTE_ID=$(echo $CONNECTION_DETAILS | awk '{print $1;}')
|
|
|
|
REMOTE_NAME=$(echo $CONNECTION_DETAILS | awk '{print $2;}')
|
|
|
|
REMOTE_HOST=$(echo $CONNECTION_DETAILS | awk '{print $3;}')
|
|
|
|
REMOTE_ARGS+=($(echo $CONNECTION_DETAILS | awk '{$1=$2=$3="";}1'))
|
2023-07-20 20:49:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GET_CONNECTIONS() {
|
|
|
|
(
|
2023-11-11 14:16:28 +00:00
|
|
|
echo '0 | localhost | localhost'
|
|
|
|
echo "0 | $(hostnamectl --static) | localhost"
|
2023-07-20 20:49:06 +00:00
|
|
|
sed -n 's/#.*//;s/ \+$//;/./p' "$REMOTE_CONNECTIONS_FILE"
|
|
|
|
) | sort -u
|
|
|
|
}
|
|
|
|
|
|
|
|
GET_CONNECTION() {
|
|
|
|
[ ! $1 ] && return 1
|
2023-11-11 14:16:28 +00:00
|
|
|
GET_CONNECTIONS | grep "^[0-9]\+ *| *$1 *|" | head -n1
|
2023-07-20 20:49:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GET_CONNECTION_NAMES() {
|
|
|
|
echo ($(GET_CONNECTIONS | awk '{print $1;}'))
|
|
|
|
}
|
|
|
|
|
|
|
|
IS_VALID_CONNECTION_NAME() {
|
|
|
|
GET_CONNECTION $1 | grep -q '|'
|
|
|
|
}
|