Skip to content

Commit

Permalink
ENH: move ssh keygen to ssh helper, define SSH_KEY_FILENAME in exactl…
Browse files Browse the repository at this point in the history
…y one place
  • Loading branch information
ZLLentz committed Mar 13, 2024
1 parent 8b37bbb commit f361b87
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 13 deletions.
9 changes: 0 additions & 9 deletions scripts/bootstrap_plc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ if [ ! -x ansible-playbook ]; then
source /cds/group/pcds/pyps/conda/venvs/ansible/bin/activate
fi

SSH_KEY_FILENAME="${HOME}/.ssh/tcbsd_key_rsa"

USERNAME="${PLC_USERNAME:=Administrator}"
THIS_SCRIPT="$(realpath "${0}")"
THIS_DIR="$(dirname "${THIS_SCRIPT}")"
Expand All @@ -52,13 +50,6 @@ else
echo "${VARS_PATH} already exists, skipping creation."
fi

# Create an ssh key, if it does not already exist
if [ ! -f "${SSH_KEY_FILENAME}" ]; then
echo "Generating your PLC Ansible SSH Key at ${SSH_KEY_FILENAME}."
echo "Please encrypt this with the TCBSD Admin password!."
ssh-keygen -t rsa -f "${SSH_KEY_FILENAME}"
fi

# Register the ssh key with the ssh agent if needed
source "${THIS_DIR}/ssh_agent_helper.sh"

Expand Down
2 changes: 0 additions & 2 deletions scripts/provision_plc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ fi
TARGET="${1}"
shift

SSH_KEY_FILENAME="${HOME}/.ssh/tcbsd_key_rsa"

THIS_SCRIPT="$(realpath "${0}")"
THIS_DIR="$(dirname "${THIS_SCRIPT}")"
ANSIBLE_ROOT="$(realpath "${THIS_DIR}/..")"
Expand Down
8 changes: 8 additions & 0 deletions scripts/ssh_agent_helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# source ssh_agent_helper.sh

SSH_KEY_FILENAME="${HOME}/.ssh/tcbsd_key_rsa"
export SSH_KEY_FILENAME

HELPER_STARTED_AGENT="NO"
export HELPER_STARTED_AGENT
Expand All @@ -28,6 +29,13 @@ ssh_agent_helper_cleanup() {
}
export ssh_agent_helper_cleanup

# Create an ssh key, if it does not already exist
if [ ! -f "${SSH_KEY_FILENAME}" ]; then
echo "Generating your PLC Ansible SSH Key at ${SSH_KEY_FILENAME}."
echo "Please encrypt this with the TCBSD Admin password!."
ssh-keygen -t rsa -f "${SSH_KEY_FILENAME}"
fi

# Multipurpose check: return code is 1 if the command fails, 2 if cannot connect to agent.
# I'm not sure if need to differentiate between these cases
if PUBKEYS="$(ssh-add -L)"; then
Expand Down
2 changes: 0 additions & 2 deletions scripts/update_admin_pass.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ if [ -z "${1}" ]; then
exit 1
fi

SSH_KEY_FILENAME="${HOME}/.ssh/tcbsd_key_rsa"

USERNAME="${PLC_USERNAME:=Administrator}"
THIS_SCRIPT="$(realpath "${0}")"
THIS_DIR="$(dirname "${THIS_SCRIPT}")"
Expand Down

0 comments on commit f361b87

Please sign in to comment.