Skip to content

Commit

Permalink
ENH: bring paths into sourceable script, always cd to appease ansible
Browse files Browse the repository at this point in the history
  • Loading branch information
ZLLentz committed Mar 27, 2024
1 parent b03718c commit f0305a6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
5 changes: 2 additions & 3 deletions scripts/bootstrap_plc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions scripts/paths.sh
Original file line number Diff line number Diff line change
@@ -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}"
2 changes: 1 addition & 1 deletion scripts/provision_plc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions scripts/update_admin_pass.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit f0305a6

Please sign in to comment.