Skip to content

Commit 7573f21

Browse files
committed
2.1.7 Fix regression in Bash 5.2
1 parent 65d56e4 commit 7573f21

File tree

1 file changed

+19
-28
lines changed

1 file changed

+19
-28
lines changed

ssh-oci-bastion.sh

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
set -e
33
set -o pipefail
44

5-
readonly VER=2.1.6
5+
readonly VER=2.1.7
66

77
# Remove the longest `*/` prefix
88
readonly SCRIPT_NAME_WITH_EXT="${0##*/}"
@@ -50,7 +50,7 @@ ENVIRONMENT
5050
* \`OCI_INSTANCE_OCID\`, e.g., \`ocid1.instance.oc1.iad.xx\`
5151
* \`OCI_BASTION_OCID\`, e.g., \`ocid1.bastion.oc1.iad.xx\`
5252
* For \`host_user\` SSH sessions only:
53-
* \`OCI_INSTANCE\`, Internal FQDN or Private IP e.g., \`kharkiv.subxxx.main.oraclevcn.com\`
53+
* \`OCI_INSTANCE\`, Internal FQDN or Private IP e.g., \`host.example.com\`
5454
5555
* One of the following SSH public keys in \`~/.ssh/\`: \`id_rsa.pub\`, \`id_dsa.pub\`, \`id_ecdsa.pub\`,
5656
\`id_ed25519.pub\`, or \`id_xmss.pub\`. If there are multiple keys the first one found in this order will be used.
@@ -78,10 +78,9 @@ while getopts np:o:h OPT; do
7878
;;
7979
p)
8080
port="$OPTARG"
81-
#ports+=("$OPTARG")
8281
;;
8382
o)
84-
readonly PROFILE_OPT="--profile $OPTARG"
83+
readonly PROFILE_OPT=(--profile "$OPTARG")
8584
;;
8685
*) # -h or `?`: an unknown option
8786
usage
@@ -149,21 +148,17 @@ if [[ $port ]]; then
149148
# `--wait-interval-seconds`: state check interval (defaults to 30 seconds).
150149
# `--ssh-public-key-file` is required
151150
# `--target-private-ip` "${OCI_INSTANCE}"
152-
# shellcheck disable=SC2086 # $PROFILE_OPT is a two-word CLI option
153-
session_ocid=$(
154-
time (# `time` prints to stderr so it does not interfere with the pipe
155-
oci bastion session create-port-forwarding $PROFILE_OPT --bastion-id "$OCI_BASTION_OCID" \
156-
--target-resource-id "$OCI_INSTANCE_OCID" --target-port "$port" --session-ttl $MAX_TTL \
157-
--ssh-public-key-file $SSH_PUB_KEY --wait-for-state SUCCEEDED --wait-for-state FAILED \
158-
--wait-interval-seconds $CHECK_INTERVAL_SEC \
159-
| jq --raw-output '.data.resources[0].identifier'
160-
printf "It took:" >&2
161-
)
151+
time session_ocid=$(
152+
oci bastion session create-port-forwarding "${PROFILE_OPT[@]}" --bastion-id "$OCI_BASTION_OCID" \
153+
--target-resource-id "$OCI_INSTANCE_OCID" --target-port "$port" --session-ttl $MAX_TTL \
154+
--ssh-public-key-file $SSH_PUB_KEY --wait-for-state SUCCEEDED --wait-for-state FAILED \
155+
--wait-interval-seconds $CHECK_INTERVAL_SEC \
156+
| jq --raw-output '.data.resources[0].identifier'
157+
printf "It took:" >&2
162158
)
163159
echo "Created the bastion port forwarding session: $session_ocid"
164160

165-
# shellcheck disable=SC2086 # $PROFILE_OPT is a two-word CLI option
166-
ssh_command=$(oci bastion session get $PROFILE_OPT --session-id "$session_ocid" \
161+
ssh_command=$(oci bastion session get "${PROFILE_OPT[@]}" --session-id "$session_ocid" \
167162
| jq --raw-output '.data["ssh-metadata"].command')
168163
# Result: `ssh -i <privateKey> -N -L <localPort>:{HOST_IP}:5432 -p 22 [email protected]`
169164
# Remove the placeholder
@@ -188,21 +183,17 @@ if [[ $HOST_USER ]]; then
188183
# `--session-ttl`: session duration in seconds (defaults to 30 minutes, maximum is 3 hours).
189184
# `--wait-interval-seconds`: state check interval (defaults to 30 seconds).
190185
# `--ssh-public-key-file` is required
191-
# shellcheck disable=SC2086 # $PROFILE_OPT is a two-word CLI option
192-
session_ocid=$(
193-
time (# `time` prints to stderr so it does not interfere with the pipe
194-
oci bastion session create-managed-ssh $PROFILE_OPT --bastion-id "$OCI_BASTION_OCID" \
195-
--target-resource-id "$OCI_INSTANCE_OCID" --target-os-username "$HOST_USER" --session-ttl $MAX_TTL \
196-
--ssh-public-key-file $SSH_PUB_KEY --wait-for-state SUCCEEDED --wait-for-state FAILED \
197-
--wait-interval-seconds $CHECK_INTERVAL_SEC \
198-
| jq --raw-output '.data.resources[0].identifier'
199-
printf "It took:" >&2
200-
)
186+
time session_ocid=$(
187+
oci bastion session create-managed-ssh "${PROFILE_OPT[@]}" --bastion-id "$OCI_BASTION_OCID" \
188+
--target-resource-id "$OCI_INSTANCE_OCID" --target-os-username "$HOST_USER" --session-ttl $MAX_TTL \
189+
--ssh-public-key-file $SSH_PUB_KEY --wait-for-state SUCCEEDED --wait-for-state FAILED \
190+
--wait-interval-seconds $CHECK_INTERVAL_SEC \
191+
| jq --raw-output '.data.resources[0].identifier'
192+
printf "It took:" >&2
201193
)
202194
echo "Created the bastion session: $session_ocid"
203195

204-
# shellcheck disable=SC2086 # $PROFILE_OPT is a two-word CLI option
205-
ssh_command=$(oci bastion session get $PROFILE_OPT --session-id "$session_ocid" \
196+
ssh_command=$(oci bastion session get "${PROFILE_OPT[@]}" --session-id "$session_ocid" \
206197
| jq --raw-output '.data["ssh-metadata"].command')
207198
# Result: `ssh -i <privateKey> -o ProxyCommand=\"ssh -i <privateKey> -W %h:%p -p 22
208199
# [email protected]\" -p 22 {HOST_USER}@{HOST_IP}`

0 commit comments

Comments
 (0)