Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the script when sourced from zsh #208

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions openstack/novarc
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)"
Expand Down
Loading