From f5adf98bd67ecb8871d211e5bc244b0b35a2c74e Mon Sep 17 00:00:00 2001 From: Marcin Wilk Date: Thu, 25 Jul 2024 09:28:08 +0000 Subject: [PATCH] Fix the script when sourced from zsh When the novarc file is sourced from the Zsh, it fails due to a few Bash specifics: - $BASH_SOURCE - does not exist in Zsh - readarray - does not exist in Zsh Resolves issue #176 Signed-off-by: Marcin Wilk --- openstack/novarc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) mode change 100644 => 100755 openstack/novarc diff --git a/openstack/novarc b/openstack/novarc old mode 100644 new mode 100755 index 697c975a..0d2e211a --- a/openstack/novarc +++ b/openstack/novarc @@ -1,10 +1,13 @@ #!/bin/bash -eu +# This script can be sourced from both Bash and Zsh shells. +# When updating please make sure not to use either Bash +# or Zsh specific features! juju_status_json_cache=`mktemp` cleanup () { rm -rf $juju_status_json_cache; } trap cleanup EXIT KILL -scriptdir=$(readlink --canonicalize $(dirname ${BASH_SOURCE})) +scriptdir=$(readlink --canonicalize $(dirname ${BASH_SOURCE[0]-$0})) # cache juju status juju status --format=json > $juju_status_json_cache @@ -25,7 +28,7 @@ if [ -n "`juju config keystone ssl_cert`" ]; then elif ((`jq -r '.applications[]| select(."charm-name"=="vault")' $juju_status_json_cache| wc -l`)); then # Vault-based ssl if `jq -r '.applications.vault.relations.certificates[]' $juju_status_json_cache| grep -q keystone`; then - readarray -t VAULT_STATUS < <(juju status vault --format=json | jq -r '.applications.vault.units."vault/0"."workload-status" | .current,.message') + VAULT_STATUS=( $(juju status vault --format=json | jq -r '.applications.vault.units."vault/0"."workload-status" | .current,.message') ) if [[ "${VAULT_STATUS[0]}" == "blocked" && "${VAULT_STATUS[1]}" == "Vault needs to be initialized" ]]; then read -p "$(cat <<-END This deployment is using vault-based ssl certificates @@ -57,7 +60,7 @@ unset _OS_PARAMS # If user was specified use it if [[ $# -gt 1 && $1 = --service ]]; then RELATION_ID=$(juju run --unit $2/leader -- relation-ids identity-service | cut -d : -f 2) - readarray -t CREDENTIALS < <(juju run --unit $2/leader -- relation-get --relation ${RELATION_ID} --format json - keystone/0) + CREDENTIALS=( $(juju run --unit $2/leader -- relation-get --relation ${RELATION_ID} --format json - keystone/0) ) export OS_USERNAME=$(echo ${CREDENTIALS} | jq --raw-output .service_username) export OS_USER_DOMAIN_NAME=$(echo ${CREDENTIALS} | jq --raw-output .service_domain) @@ -73,7 +76,7 @@ else # if the admin password is not set in the configuration, then it's read # from the leader databag. _CONFIG_PASSWD="$(juju config keystone admin-password| awk '{print tolower($0)}')" - if [ "${_CONFIG_PASSWD}" == "none" ] || [ "${_CONFIG_PASSWD}" == "" ]; then + if [[ "${_CONFIG_PASSWD}" == "none" ]] || [[ "${_CONFIG_PASSWD}" == "" ]]; then export OS_PASSWORD=$(juju run -u keystone/leader leader-get admin_passwd) else export OS_PASSWORD="$(juju config keystone admin-password)"