Skip to content

Commit

Permalink
Rewrite autosource as function to avoid subshell isolation
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonrhodes committed Oct 25, 2024
1 parent 83a87b1 commit 7405df4
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 22 deletions.
19 changes: 0 additions & 19 deletions scripts/rca-demo/autosource.sh

This file was deleted.

3 changes: 2 additions & 1 deletion scripts/rca-demo/create-release-annotation
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#!/bin/bash

SCRIPTS_DIR=$(dirname "${BASH_SOURCE[0]}")
$SCRIPTS_DIR/autosource.sh

set -a
source $SCRIPTS_DIR/shared.sh
set +a

autosource

if [ -z "${KIBANA_URL}" ]; then
die "You must set KIBANA_URL to a valid Kibana URL"
fi
Expand Down
3 changes: 2 additions & 1 deletion scripts/rca-demo/post-setup
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#!/bin/bash

SCRIPTS_DIR=$(dirname "${BASH_SOURCE[0]}")
$SCRIPTS_DIR/autosource.sh

set -a
source $SCRIPTS_DIR/shared.sh
set +a

autosource

create_data_view () {
ID=$1
INDICES=$2
Expand Down
3 changes: 2 additions & 1 deletion scripts/rca-demo/setup
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#!/bin/bash

SCRIPTS_DIR=$(dirname "${BASH_SOURCE[0]}")
$SCRIPTS_DIR/autosource.sh

set -a
source $SCRIPTS_DIR/shared.sh
set +a

autosource

APP_NAME=my-otel-demo

title "Checking environment for $APP_NAME..."
Expand Down
16 changes: 16 additions & 0 deletions scripts/rca-demo/shared.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,20 @@ warn () {
die () {
echo -e "${BRed}ERROR: $1${Color_Off}"
exit 1
}

autosource () {
SCRIPTS_DIR=$(dirname "${BASH_SOURCE[0]}")
LOAD_ENV_FILE_PATH=$SCRIPTS_DIR/.env

if [ -n "${ENV_FILE_PATH}" ]; then
LOAD_ENV_FILE_PATH=$ENV_FILE_PATH
fi

if [ -f $LOAD_ENV_FILE_PATH ]; then
title "Sourcing environment variables from $LOAD_ENV_FILE_PATH"
source $LOAD_ENV_FILE_PATH
else
warn "Environment variables file not found at $LOAD_ENV_FILE_PATH"
fi
}

0 comments on commit 7405df4

Please sign in to comment.