Skip to content

Commit

Permalink
swancustomenvs: Check if env exists at first
Browse files Browse the repository at this point in the history
There's no need for running part of the script if the an environment was created already.
  • Loading branch information
rodrigo-sobral authored and etejedor committed Sep 19, 2024
1 parent c18c71e commit c45e625
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions SwanCustomEnvironments/swancustomenvironments/scripts/makenv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
# This script allows to create an environment to use in notebooks and terminals. The environment contains the packages from a provided repository.


# Check if an environment already exists in the session, avoiding multiple environments
CURRENT_ENV_NAME=$(find "/home/$USER" -type d -name "*_env" | head -n 1 | cut -d '/' -f4)
CURRENT_REPO_PATH=$(tail -n 1 "/home/$USER/.bash_profile" | cut -d ' ' -f2)
if [ -n "${CURRENT_ENV_NAME}" ]; then
_log "ENVIRONMENT_ALREADY_EXISTS:${CURRENT_ENV_NAME}"
_log "REPO_PATH:${CURRENT_REPO_PATH#$HOME}"
exit 1
fi

LOG_FILE=/tmp/makenv.log # File to keep a backlog of this script output
GIT_HOME="$HOME/SWAN_projects" # Path where git repositories are stored

Expand Down Expand Up @@ -174,15 +183,6 @@ if [ ! -f "${REQ_PATH}" ]; then
exit 1
fi

# Check if an environment already exists in the session, avoiding multiple environments
CURRENT_ENV_NAME=$(find "/home/$USER" -type d -name "*_env" | head -n 1 | cut -d '/' -f4)
CURRENT_REPO_PATH=$(tail -n 1 "/home/$USER/.bash_profile" | cut -d ' ' -f2)
if [ -n "${CURRENT_ENV_NAME}" ]; then
_log "ENVIRONMENT_ALREADY_EXISTS:${CURRENT_ENV_NAME}"
_log "REPO_PATH:${CURRENT_REPO_PATH#$HOME}"
exit 1
fi

if [ -n "${BUILDER_VERSION}" ]; then
_log "Creating environment ${ENV_NAME} using ${BUILDER} (${BUILDER_VERSION})..."
else
Expand Down

0 comments on commit c45e625

Please sign in to comment.