Skip to content

Commit

Permalink
Fix sr3_ssh, add sr3_scp
Browse files Browse the repository at this point in the history
  • Loading branch information
reidsunderland committed Dec 1, 2023
1 parent 8b8ae01 commit bce19ae
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
39 changes: 39 additions & 0 deletions bin/sr3_scp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

# shellcheck source=./bin/sr3_utils
source "${BASH_SOURCE%/*}/sr3_utils"

if [[ $# == 0 ]]; then
echo '[ERROR] no destination given'
echo 'Usage: sr3_scp destination_server:remotepath localpath'
exit 2
fi

# sets git_tld and pump_name
sr3_get_git_path_pump_name

echo "Data Pump Name: ${pump_name}."

# Use ssh user config file (pumpname_ssh_config) if present
ssh_user_config="${git_tld}/_dsh_config/${pump_name}_ssh_config"
ssh_args=""
if [ -e "${ssh_user_config}" ]; then
ssh_args="${ssh_args} -F${ssh_user_config}"
else
echo "[WARNING] ${ssh_user_config} doesn't exist, sr3_scp will not do anything different than normal scp."
fi

# ssh-agent environment variables are required when proxying the SSH connection through a jump server using `ssh-add`
unset_ssh_agent=false
if [ -e "${ssh_user_config}" ] && { [ -z "${SSH_AUTH_SOCK}" ] || [ -z "${SSH_AGENT_PID}" ]; } && grep -q "ssh-add" "${ssh_user_config}"; then
eval "$(ssh-agent -s)" > /dev/null
unset_ssh_agent=true
fi

# shellcheck disable=SC2086,SC2029
scp ${ssh_args} "$@"

# Clean up ssh-agent
if [ "${unset_ssh_agent}" = "true" ] && [ -n "${SSH_AGENT_PID}" ]; then
eval "$(ssh-agent -k)" > /dev/null
fi
2 changes: 1 addition & 1 deletion bin/sr3_ssh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ if [ -e "${ssh_user_config}" ] && { [ -z "${SSH_AUTH_SOCK}" ] || [ -z "${SSH_AGE
fi

# shellcheck disable=SC2086,SC2029
ssh ${ssh_args} "$*"
ssh ${ssh_args} "$@"

# Clean up ssh-agent
if [ "${unset_ssh_agent}" = "true" ] && [ -n "${SSH_AGENT_PID}" ]; then
Expand Down

0 comments on commit bce19ae

Please sign in to comment.