File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -65,27 +65,37 @@ declare -a SSH_ARGS=()
65
65
# It populates the SSH_ARGS array with arguments for reuse.
66
66
ssh_remote () {
67
67
local ssh_addr=" $1 "
68
+ local target port
69
+ # Split out the port component, if exists
70
+ if [[ " $ssh_addr " =~ ^([^:]+)(:([0-9]+))? $ ]]; then
71
+ target=" ${BASH_REMATCH[1]} "
72
+ port=" ${BASH_REMATCH[3]:- 22} " # Default port is 22 if not specified
73
+ else
74
+ error " Invalid SSH address format. Expected format: [USER@]HOST[:PORT]"
75
+ fi
76
+
68
77
local ssh_opts=(
69
78
-o ControlMaster=auto
70
79
# Unique control socket path for this invocation.
71
80
-o " ControlPath=/tmp/docker-pussh-$$ .sock"
72
81
# The connection will be automatically terminated after 1 minute of inactivity.
73
82
-o ControlPersist=1m
74
83
-o ConnectTimeout=15
84
+ -p " ${port} "
75
85
)
76
86
# Add SSH key option if provided.
77
87
if [ -n " $SSH_KEY " ]; then
78
88
ssh_opts+=(-i " $SSH_KEY " )
79
89
fi
80
90
81
91
# Establish ControlMaster connection in the background.
82
- if ! ssh " ${ssh_opts[@]} " -f -N " $ssh_addr " ; then
92
+ if ! ssh " ${ssh_opts[@]} " -f -N " ${target} " ; then
83
93
error " Failed to connect to remote host via SSH: $ssh_addr "
84
94
fi
85
95
86
96
# Populate SSH_ARGS array for reuse in all subsequent commands.
87
97
SSH_ARGS=(" ${ssh_opts[@]} " )
88
- SSH_ARGS+=(" $ssh_addr " )
98
+ SSH_ARGS+=(" ${target} " )
89
99
}
90
100
91
101
# sudo prefix for remote docker commands. It's set to "sudo" if the remote user is not root and requires sudo
You can’t perform that action at this time.
0 commit comments