From f0305a61534ebeb4ba87c2ff90ae73cbc7719b05 Mon Sep 17 00:00:00 2001 From: Zachary Lentz Date: Wed, 27 Mar 2024 11:14:46 -0700 Subject: [PATCH] ENH: bring paths into sourceable script, always cd to appease ansible --- scripts/bootstrap_plc.sh | 5 ++--- scripts/paths.sh | 18 ++++++++++++++++++ scripts/provision_plc.sh | 2 +- scripts/update_admin_pass.sh | 3 +-- 4 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 scripts/paths.sh diff --git a/scripts/bootstrap_plc.sh b/scripts/bootstrap_plc.sh index 289fa81..9231b91 100755 --- a/scripts/bootstrap_plc.sh +++ b/scripts/bootstrap_plc.sh @@ -23,11 +23,10 @@ HOSTNAME="${1}" shift USERNAME="${PLC_USERNAME:=Administrator}" + THIS_SCRIPT="$(realpath "${0}")" THIS_DIR="$(dirname "${THIS_SCRIPT}")" -ANSIBLE_ROOT="$(realpath "${THIS_DIR}/..")" -INVENTORY_PATH="${ANSIBLE_ROOT}/inventory/plcs.yaml" -SSH_CONFIG="${ANSIBLE_ROOT}/ssh_config" +source "${THIS_DIR}"/paths.sh # Use the correct python env source "${THIS_DIR}"/activate_python.sh diff --git a/scripts/paths.sh b/scripts/paths.sh new file mode 100644 index 0000000..46fd047 --- /dev/null +++ b/scripts/paths.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# Sourceable script to set common vars for the various scripts. +# This sets a bunch of environment variables related to known paths +# and puts us into the ansible directory for the duration of the +# encapsulating script. +set -e + +THIS_SCRIPT="$(realpath "${BASH_SOURCE[0]}")" +THIS_DIR="$(dirname "${THIS_SCRIPT}")" + +ANSIBLE_ROOT="$(realpath "${THIS_DIR}/..")" +export ANSIBLE_ROOT +INVENTORY_PATH="${ANSIBLE_ROOT}/inventory/plcs.yaml" +export INVENTORY_PATH +SSH_CONFIG="${ANSIBLE_ROOT}/ssh_config" +export SSH_CONFIG + +cd "${ANSIBLE_ROOT}" diff --git a/scripts/provision_plc.sh b/scripts/provision_plc.sh index 2590515..2cf1669 100755 --- a/scripts/provision_plc.sh +++ b/scripts/provision_plc.sh @@ -22,7 +22,7 @@ shift THIS_SCRIPT="$(realpath "${0}")" THIS_DIR="$(dirname "${THIS_SCRIPT}")" -ANSIBLE_ROOT="$(realpath "${THIS_DIR}/..")" +source "${THIS_DIR}"/paths.sh # Use the correct python env source "${THIS_DIR}"/activate_python.sh diff --git a/scripts/update_admin_pass.sh b/scripts/update_admin_pass.sh index 356b881..09203ff 100755 --- a/scripts/update_admin_pass.sh +++ b/scripts/update_admin_pass.sh @@ -21,8 +21,7 @@ fi USERNAME="${PLC_USERNAME:=Administrator}" THIS_SCRIPT="$(realpath "${0}")" THIS_DIR="$(dirname "${THIS_SCRIPT}")" -ANSIBLE_ROOT="$(realpath "${THIS_DIR}/..")" -SSH_CONFIG="${ANSIBLE_ROOT}/ssh_config" +source "${THIS_DIR}"/paths.sh # Register the ssh key with the ssh agent if needed source "${THIS_DIR}/ssh_agent_helper.sh"