From f361b87903948b22c99fc4faf9a4c0bd7eff367f Mon Sep 17 00:00:00 2001 From: Zachary Lentz Date: Wed, 13 Mar 2024 16:47:13 -0700 Subject: [PATCH] ENH: move ssh keygen to ssh helper, define SSH_KEY_FILENAME in exactly one place --- scripts/bootstrap_plc.sh | 9 --------- scripts/provision_plc.sh | 2 -- scripts/ssh_agent_helper.sh | 8 ++++++++ scripts/update_admin_pass.sh | 2 -- 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/scripts/bootstrap_plc.sh b/scripts/bootstrap_plc.sh index b8bc0d0..0d5bd7b 100755 --- a/scripts/bootstrap_plc.sh +++ b/scripts/bootstrap_plc.sh @@ -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}")" @@ -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" diff --git a/scripts/provision_plc.sh b/scripts/provision_plc.sh index 8768c53..6356e81 100755 --- a/scripts/provision_plc.sh +++ b/scripts/provision_plc.sh @@ -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}/..")" diff --git a/scripts/ssh_agent_helper.sh b/scripts/ssh_agent_helper.sh index d3c4a01..8c4ff29 100755 --- a/scripts/ssh_agent_helper.sh +++ b/scripts/ssh_agent_helper.sh @@ -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 @@ -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 diff --git a/scripts/update_admin_pass.sh b/scripts/update_admin_pass.sh index 0bc6c55..1b2eb63 100755 --- a/scripts/update_admin_pass.sh +++ b/scripts/update_admin_pass.sh @@ -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}")"