diff --git a/bin/drun b/bin/drun index 679552b..97d45d2 100644 --- a/bin/drun +++ b/bin/drun @@ -5,7 +5,7 @@ source $ENV_DIR/bin/denv_msg drun() { if [ $# -lt 1 ]; then denv_error_msg "Verwendung: drun [system] " - return 1 + return; fi local SYSTEMS_CONFIG="$ENV_DIR/.systems" @@ -24,13 +24,13 @@ drun() { if [ -z "$SYSTEM_PATH" ]; then # You are NOT in a configured system directory (though in a subdirectory of dev-env/systems). denv_error_msg "$CURRENT_DIRECTORY is not a configured dev-env system path.\nPlease register the system in $ENV_DIR/.systems, navigate to a registered system, or provide a system identifer as the first parameter of drun." - return 1 + return; else # You are in a configured system directory SYSTEM_IDENTIFIER=$(grep "$ASSUMED_SYSTEM_PATH" "$SYSTEMS_CONFIG" | cut -d' ' -f1) fi else denv_error_msg "$CURRENT_DIRECTORY is not a subdirectory of $ENV_DIR/systems.\nPlease navigate to a configured system, or provide a system identifer as the first parameter of drun." - return 1 + return; fi else # First Parameter is a valid system identifier @@ -45,49 +45,32 @@ drun() { # Set .env variables if a file exist if [[ ! -f "$DOCKER_COMPOSE_FILE" ]]; then denv_error_msg "$DOCKER_COMPOSE_FILE was not found. Have you run init yet?" - return 1 + return; fi denv_info_msg "[$SYSTEM_IDENTIFIER]: $DOCKER_EXEC_COMMAND" - if [[ -f "$SYSTEM_ENV_FILE" ]] ; then - export $(grep -v '^#' "$SYSTEM_ENV_FILE" | xargs) - fi - APP_CONTAINER=$(docker compose -f "$DOCKER_COMPOSE_FILE" config --services | grep 'app') - if [[ -z "$APP_CONTAINER" ]] ; then - denv_error_msg "App Container not found in '$DOCKER_COMPOSE_FILE'" - else + if [[ ! -z "$APP_CONTAINER" ]] ; then denv_info_msg "App Container: '$APP_CONTAINER'" + CONTAINER_ID=$(docker ps -qf "name=$APP_CONTAINER") + + if [[ -t 0 && -t 1 ]]; then + if [[ -f "$SYSTEM_ENV_FILE" ]] ; then + export $(grep -v '^#' "$SYSTEM_ENV_FILE" | xargs) + fi + + denv_echo_msg "docker exec -it" + docker exec -it "$CONTAINER_ID" $DOCKER_EXEC_COMMAND + + # Unset .env variables if a file exist + if [[ -f "$SYSTEM_ENV_FILE" ]] ; then + unset $(grep -v '^#' "$SYSTEM_ENV_FILE" | sed -E 's/(.*)=.*/\1/' | xargs) + fi + else + denv_echo_msg "docker compose" + docker exec "$CONTAINER_ID" $DOCKER_EXEC_COMMAND + fi fi - - - if [[ -t 0 && -t 1 ]]; then - denv_echo_msg "docker compose -it" - docker compose -f "$DOCKER_COMPOSE_FILE" exec -it $APP_CONTAINER $DOCKER_EXEC_COMMAND - else - denv_echo_msg "docker compose" - docker compose -f "$DOCKER_COMPOSE_FILE" exec -T $APP_CONTAINER $DOCKER_EXEC_COMMAND - fi - - # Unset .env variables if a file exist - if [[ -f "$SYSTEM_ENV_FILE" ]] ; then - unset $(grep -v '^#' "$SYSTEM_ENV_FILE" | sed -E 's/(.*)=.*/\1/' | xargs) - fi -} - - - -_drun_completion() { - local cur prev opts - COMPREPLY=() - cur="${COMP_WORDS[COMP_CWORD]}" - prev="${COMP_WORDS[COMP_CWORD-1]}" - opts="start stop restart status" - - COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) - return 0 -} - -complete -F _drun_completion drun \ No newline at end of file +} \ No newline at end of file diff --git a/build b/build index 602141c..e9fe8f0 100755 --- a/build +++ b/build @@ -3,7 +3,7 @@ ENV_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) source $ENV_DIR/bin/denv_msg -denv_info_msg "Executing build dev-env" +denv_info_msg "[dev-env]: build" docker compose -f "$ENV_DIR/docker/docker-compose.yml" build echo "" diff --git a/down b/down index aafcaf2..7213670 100755 --- a/down +++ b/down @@ -7,5 +7,5 @@ source $ENV_DIR/bin/denv_msg $ENV_DIR/script/foreachSystem/dcom down echo "" -denv_info_msg "Executing down dev-env" +denv_info_msg "[dev-env]: down" docker compose -f "$ENV_DIR/docker/docker-compose.yml" down \ No newline at end of file diff --git a/script/foreachSystem/runScript b/script/foreachSystem/runScript index 7092059..8f58c9c 100755 --- a/script/foreachSystem/runScript +++ b/script/foreachSystem/runScript @@ -1,7 +1,7 @@ #!/bin/bash -COMMAND="$@" ENV_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )/../.." &> /dev/null && pwd ) CONFIG_FILE="$ENV_DIR/.systems" +COMMAND="$@" source $ENV_DIR/bin/denv_msg @@ -20,19 +20,18 @@ while IFS=' ' read -r IDENTIFIER DIRECTORY GIT; do continue fi - denv_info_msg "[$IDENTIFIER]: $COMMAND" SYSTEM_SCRIPT_DIRECTORY=$(realpath "$ENV_DIR/systems/$DIRECTORY/bin/script") - COMMAND_PATH="$SYSTEM_SCRIPT_DIRECTORY/$COMMAND"; + COMMAND_PATH="$SYSTEM_SCRIPT_DIRECTORY/$COMMAND" # Check if system directory already exists if [ ! -f "$COMMAND_PATH" ]; then - denv_error_msg "$COMMAND_PATH not found." - exit 1 - else - denv_echo_msg "Executing $COMMAND..." - $COMMAND_PATH + denv_error_msg "$COMMAND_PATH not found." + continue fi - denv_info_msg "System $IDENTIFIER done" - echo "" + denv_info_msg "[$IDENTIFIER]: $COMMAND" + $COMMAND_PATH + denv_success_msg "[$IDENTIFIER]: $COMMAND completed successfully" + echo "" + done < "$CONFIG_FILE" diff --git a/stop b/stop index e5d424e..a7e24df 100755 --- a/stop +++ b/stop @@ -6,5 +6,5 @@ source $ENV_DIR/bin/denv_msg $ENV_DIR/script/foreachSystem/dcom stop echo "" -denv_info_msg "Executing stop dev-env" +denv_info_msg "[dev-env] stop" docker compose -f "$ENV_DIR/docker/docker-compose.yml" stop \ No newline at end of file diff --git a/up b/up index 544e06e..4a6d59a 100755 --- a/up +++ b/up @@ -3,7 +3,7 @@ ENV_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) source $ENV_DIR/bin/denv_msg -denv_info_msg "Executing up -d dev-env" +denv_info_msg "[dev-env]: up -d" docker compose -f "$ENV_DIR/docker/docker-compose.yml" up -d echo ""