From 5852c79f103ea6b5968c83428a2122a7c5731997 Mon Sep 17 00:00:00 2001 From: Flo Date: Sun, 25 May 2025 22:21:05 +0200 Subject: [PATCH] master: aua changes --- .gitignore | 4 +- README.md | 100 ++++++++++++++++++++++++++------- bin/dcom | 16 +++--- bin/denv | 18 +++++- bin/denv_msg | 27 --------- bin/drun | 27 ++++----- bin/git | 24 +++++++- bin/messages | 38 +++++++++++++ bin/ssh | 37 ++++++------ build | 5 +- down | 28 ++++++--- info | 19 ++++++- init | 26 ++++++--- prune | 21 +++++++ script/clone | 20 +++---- script/foreachSystem/dcom | 6 +- script/foreachSystem/runScript | 15 +++-- script/update_profile | 9 ++- script/write_aliases | 4 +- stop | 9 ++- up | 10 +++- 21 files changed, 313 insertions(+), 150 deletions(-) delete mode 100644 bin/denv_msg create mode 100644 bin/messages create mode 100755 prune diff --git a/.gitignore b/.gitignore index 1e485cf..11c9a38 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,6 @@ var/ .firstRun .aliases -.systems \ No newline at end of file +.systems +.idea +.DS_Store \ No newline at end of file diff --git a/README.md b/README.md index fc63bab..481d539 100644 --- a/README.md +++ b/README.md @@ -1,28 +1,90 @@ -# Stack-Up dev-env +# AuA24 dev-env ## Introduction -This project is the development environment of all stack-up projects. -It simplifies handling different docker-enabled applications and their maintenance. +This project is the development environment of the **AuA24 Dashboard**. +It's purpose is to simplify the handling, maintenance and development of docker-enabled applications (systems). + ## Installation - Create a .systems file bases on .systems.example: `cp .systems.example .systems` - Enter all systems in the created file `nano .systems` -- run `./init`. Init will: - - update `.aliases` file, which enables you to switch between your systems easily via `goto-` - - updates `.profile` to use the updated aliases, enables the dev-env binaries (denv, drun, dcom, ...) and add some utility functions - - clones all systems defined in `.systems` - - calls the `bin/script/init` script for all cloned systems. -- Perform init actions on systems +- Run `./init` +- Perform initial actions on systems. +This might include... + - changing variables in your `.env` files, adjusting the `docker/docker-compose.yml` if necessary + - adding file(s) to the system (e.g. the `weblate.token`) - `./up` to start your containers - up will also run all the `bin/script/firstRun` scripts, if the `.firstRun` marker is missing + ## Usage -After the installation was performed successfully and you've sourced your ~/.profile file, you'll have access to the following utilities: -- denv - - without a parameter, navigates to the development environment - - if a parameter is specified, denv will try to execute the passed script in the dev-env base folder -- drun - - executes a command on the app container of a system -- dcom - - executes a docker compose command. - - without a parameter, for the system of the current directory - - with a parameter, for the supplied system-id \ No newline at end of file +After the installation was performed successfully and you've sourced your ~/.profile file, you'll have access to the following utilities + +### Binaries +#### denv +> Syntax: `denv [script]` +> - Without a passed script, navigates to the development environment. +> - If `script` is passed, denv will try to execute the specified script in the dev-env base folder. + +#### drun +> Syntax: `drun [system-identifier] ` +> - Executes a command on the 'app'-container of a system. (e.g. `backend-app` for `backend`) +> - If a system-identifier is passed, the specified command will be executed on the 'app'-container for the passed system-identifier. +> - If no system-identifier is passed, `drun` will try to identify the system by the folder you're currently in. + +#### dcom +> Syntax: `dcom [system-identifier] ` +> - Executes a `docker compose` command for a specific system +> - If a `system-identifier` is passed, the `command` will be for the `docker/docker-compose.yml` file of the passed `system-identifier`. +> - If no `system-identifier` is passed, `dcom` will try to identify the system by the folder you're currently in. + +### Scripts +All these scripts are available in the dev-env base directory. +They may be called by either just executing them in the command line when you're in the dev-env base directory `./script` or by using the `denv` binary from any place: `denv script` +#### build +> Builds the images, which are used to start up docker containers +> - Executes `docker compose build` for the dev-env +> - Then executes `dcom build` for each system + +#### down +> Stops all running containers and removes them afterwards. +> This may lead to loss of data. +> - Executes `docker compose down` for the dev-env +> - Then executes `dcom down` for each system + +#### info +> Displays information about the dev-env +> - Full path to the environment +> - An overview over all installed systems... +> - Identifier +> - Path relative to the dev-env +> - Currently checked out branch +> - An indicator whether there are uncommitted changes on the branch + +#### init +> Initializes the development environment. +> It should skip unnecessary steps, in case the dev-env is already initialized. +> - Creates certificates used by traefik to enable TLS (HTTPS) +> - Creates access keys `~/.ssh/personal_bitbucket_access_key` and `~/.ssh/bitbucket_access_key` used for connecting a container with git +> - Updates `.aliases` file, which enables you to switch between your systems easily via `goto-` +> - Updates `.profile` to use the updated aliases, enables the dev-env binaries (`denv`, `drun`, `dcom`, ...) and add some utility functions +> - Clones all systems defined in `.systems` +> - Calls the `./bin/script/init` script for each cloned system + +#### prune +> Removes all containers and images from docker. This also includes all data saved on databases. +> After confirmation... +> - Stops all running docker containers +> - Remove all containers and images + +#### stop +> Stops all running containers. +> - Executes `docker compose stop` for the dev-env +> - Then executes `dcom stop` for each system + +#### up +> Starts all running containers. +> - Executes `docker compose up -d` for the dev-env +> - Then executes `dcom up -d` for each system + +#### update +> Calls the `bin/script/update` script for each system \ No newline at end of file diff --git a/bin/dcom b/bin/dcom index e7cce27..0828dbf 100644 --- a/bin/dcom +++ b/bin/dcom @@ -1,10 +1,10 @@ #!/bin/bash ENV_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )/.." &> /dev/null && pwd ) -source $ENV_DIR/bin/denv_msg +source $ENV_DIR/bin/messages -dcom() { +function dcom() { if [ $# -lt 1 ]; then - denv_error_msg "Verwendung: dcom [system] " + errormsg "Usage: dcom [system] " return 1 fi @@ -23,13 +23,13 @@ dcom() { SYSTEM_PATH=$(grep "$ASSUMED_SYSTEM_PATH" "$SYSTEMS_CONFIG" | cut -d' ' -f2) 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 dcom." + errormsg "$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 dcom." return 1 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 dcom." + errormsg "$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 dcom." return 1 fi @@ -44,11 +44,11 @@ dcom() { # 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?" + errormsg "$DOCKER_COMPOSE_FILE was not found. Have you run init yet?" return 1 fi - denv_info_msg "[$SYSTEM_IDENTIFIER]: $DOCKER_COMPOSE_COMMAND" + infomsg "[$SYSTEM_IDENTIFIER]: $DOCKER_COMPOSE_COMMAND" if [[ -f "$SYSTEM_ENV_FILE" ]] ; then export $(grep -v '^#' "$SYSTEM_ENV_FILE" | xargs) @@ -62,7 +62,7 @@ dcom() { fi } -_dcom_completion() { +function _dcom_completion() { local SYSTEMS_CONFIG="$ENV_DIR/.systems" local cur prev opts COMPREPLY=() diff --git a/bin/denv b/bin/denv index de7e322..e94d0c7 100644 --- a/bin/denv +++ b/bin/denv @@ -1,10 +1,24 @@ #!/bin/bash ENV_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )/../" &> /dev/null && pwd ) -denv() { +function denv() { if [ ! -z $1 ] ; then $ENV_DIR/$1 else cd $ENV_DIR fi -} \ No newline at end of file +} + +_denv_completion() { + local cur prev opts + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + + opts=$(find "$ENV_DIR" -maxdepth 1 -type f -executable -printf "%f\n") + + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + return 0 +} + +complete -F _denv_completion denv \ No newline at end of file diff --git a/bin/denv_msg b/bin/denv_msg deleted file mode 100644 index c400276..0000000 --- a/bin/denv_msg +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash -RESET='\033[0m' -Black='\033[0;30m' -Red='\033[0;31m' -Green='\033[0;32m' -Yellow='\033[0;33m' -Blue='\033[0;34m' -Purple='\033[0;35m' -Cyan='\033[0;36m' -White='\033[0;37m' - -denv_error_msg () { - echo -e "${Red}$@${RESET}" -} - -denv_success_msg () { - echo -e "${Green}$@${RESET}" - echo -e "" -} - -denv_info_msg () { - echo -e "${Cyan}$@${RESET}" -} - -denv_echo_msg () { - echo -e "${White}$@${RESET}" -} \ No newline at end of file diff --git a/bin/drun b/bin/drun index 5ef4219..2bf0e53 100644 --- a/bin/drun +++ b/bin/drun @@ -1,10 +1,10 @@ #!/bin/bash ENV_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )/.." &> /dev/null && pwd ) -source $ENV_DIR/bin/denv_msg +source $ENV_DIR/bin/messages -drun() { +function drun() { if [ $# -lt 1 ]; then - denv_error_msg "Verwendung: drun [system] " + errormsg "Usage: drun [system] " return; fi @@ -23,13 +23,13 @@ drun() { SYSTEM_PATH=$(grep "$ASSUMED_SYSTEM_PATH" "$SYSTEMS_CONFIG" | cut -d' ' -f2) 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." + errormsg "$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; 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." + errormsg "$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; fi @@ -44,7 +44,7 @@ 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?" + errormsg "$DOCKER_COMPOSE_FILE was not found. Have you run init yet?" return; fi @@ -54,22 +54,23 @@ drun() { fi APP_CONTAINER=$(docker compose -f "$DOCKER_COMPOSE_FILE" config --services | grep 'app') + if [[ ! -z "$APP_CONTAINER" ]] ; then - denv_info_msg "[$SYSTEM_IDENTIFIER]($APP_CONTAINER): $DOCKER_EXEC_COMMAND" - CONTAINER_ID=$(docker ps -qf "name=$APP_CONTAINER") + infomsg "[$SYSTEM_IDENTIFIER]($APP_CONTAINER): $DOCKER_EXEC_COMMAND" + CONTAINER_ID=$(docker ps -qf "name=docker-$APP_CONTAINER") if [ -z "$CONTAINER_ID" ]; then - denv_error_msg "No active container found for '$APP_CONTAINER'" + errormsg "No active container found for '$APP_CONTAINER'" return; fi if [[ -t 0 && -t 1 ]]; then - docker exec -it "$CONTAINER_ID" $DOCKER_EXEC_COMMAND + docker exec -it "$CONTAINER_ID" bash -ci "$DOCKER_EXEC_COMMAND" else - docker exec "$CONTAINER_ID" $DOCKER_EXEC_COMMAND + docker exec -t "$CONTAINER_ID" bash -ci "$DOCKER_EXEC_COMMAND" fi else - denv_error_msg "No 'app' container found in $DOCKER_COMPOSE_FILE" + errormsg "No 'app' container found in $DOCKER_COMPOSE_FILE" return; fi @@ -79,7 +80,7 @@ drun() { fi } -_drun_completion() { +function _drun_completion() { local SYSTEMS_CONFIG="$ENV_DIR/.systems" local cur prev opts COMPREPLY=() diff --git a/bin/git b/bin/git index 8560656..6d8cb82 100644 --- a/bin/git +++ b/bin/git @@ -1,8 +1,26 @@ #!/bin/bash -acp() { - git add . - git commit -m "$@" +function acp() { + git add -A + NAME=$(git branch | grep '*' | sed 's/* //') + git commit -a -m "$NAME: $1" git push } +function pd() { + git pull origin develop:develop +} + +function pdm() { + git pull origin develop:develop + git merge develop +} + +function pm() { + git pull origin master:master +} + +function pmm() { + git pull origin master:master + git merge master +} \ No newline at end of file diff --git a/bin/messages b/bin/messages new file mode 100644 index 0000000..a2fc2d3 --- /dev/null +++ b/bin/messages @@ -0,0 +1,38 @@ +ANSI_OPEN="\033[" + +function resetcolors { + echo -n -e "${ANSI_OPEN}0m" +} + +function importantmsg { + echo -e "${ANSI_OPEN}96m$1" + resetcolors +} + +function errormsg { + echo -e "${ANSI_OPEN}91m$1" + resetcolors +} + +function infomsg { + echo -e "${ANSI_OPEN}0m$1" + resetcolors +} + +function successmsg { + echo -e "${ANSI_OPEN}92m$1" + resetcolors +} + +function warnmsg { + echo -e "${ANSI_OPEN}93m$1" + resetcolors +} + +function hasNewLine { + test "$(tail -c 1 "$1" | wc -l)" -eq 0 && echo "NO" || echo "YES" +} + +function indent { + sed 's/^/ /'; +} diff --git a/bin/ssh b/bin/ssh index 9fbf6df..7751843 100644 --- a/bin/ssh +++ b/bin/ssh @@ -2,26 +2,21 @@ SSH_ENV="$HOME/.ssh/agent-environment" function dssh { - ADD_AGENT=0 + echo "Initialising new SSH agent..." + /usr/bin/ssh-agent | sed 's/^echo/#echo/' >"$SSH_ENV" + echo succeeded + chmod 600 "$SSH_ENV" + . "$SSH_ENV" >/dev/null + /usr/bin/ssh-add; - if [ -f "$SSH_ENV" ]; then - . "$SSH_ENV" >/dev/null - ps -ef | grep $SSH_AGENT_PID | grep ssh-agent$ >/dev/null || { - ADD_AGENT=1 - } - else - ADD_AGENT=1 - fi + ssh-add ~/.ssh/gitea_ssh +} - if [ $ADD_AGENT -eq 1 ]; then - echo "Initialising new SSH agent..." - /usr/bin/ssh-agent | sed 's/^echo/#echo/' >"$SSH_ENV" - echo succeeded - chmod 600 "$SSH_ENV" - . "$SSH_ENV" >/dev/null - else - echo "No agent necessary" - fi - - /usr/bin/ssh-add ~/.ssh/gitea_ssh -} \ No newline at end of file +if [ -f "$SSH_ENV" ]; then + . "$SSH_ENV" >/dev/null + ps -ef | grep $SSH_AGENT_PID | grep ssh-agent$ >/dev/null || { + dssh + } +else + dssh +fi diff --git a/build b/build index e9fe8f0..a7747fd 100755 --- a/build +++ b/build @@ -1,9 +1,8 @@ #!/bin/bash - ENV_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) -source $ENV_DIR/bin/denv_msg +source $ENV_DIR/bin/messages -denv_info_msg "[dev-env]: build" +infomsg "[dev-env]: Executing docker-compose build for dev-env" docker compose -f "$ENV_DIR/docker/docker-compose.yml" build echo "" diff --git a/down b/down index ea519ea..9a23c49 100755 --- a/down +++ b/down @@ -1,13 +1,27 @@ #!/bin/bash - ENV_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) -source $ENV_DIR/bin/denv_msg +source $ENV_DIR/bin/messages - -$ENV_DIR/script/foreachSystem/dcom down +warnmsg "This script will down docker containers (= stop & remove)" +warnmsg "This also deletes all data on the databases" +warnmsg "Do you want to continue? (y/n)" +read -p "Answer: " ANSWER echo "" -denv_info_msg "[dev-env]: down" -docker compose -f "$ENV_DIR/docker/docker-compose.yml" down +if [[ "$ANSWER" == "y" || "$ANSWER" == "Y" ]]; then + $ENV_DIR/script/foreachSystem/dcom down -docker ps + infomsg "[dev-env]: Executing docker-compose down for dev-env" + docker compose -f "$ENV_DIR/docker/docker-compose.yml" down + echo "" + + if [ -f "$ENV_DIR/.firstRun" ]; then + infomsg "[dev-env]: Removing firstRun marker" + rm "$ENV_DIR/.firstRun" + echo "" + fi + + docker ps +else + infomsg "[dev-env]: down cancelled" +fi diff --git a/info b/info index e63ea1a..ef2aed9 100755 --- a/info +++ b/info @@ -2,9 +2,9 @@ ENV_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) CONFIG_FILE="$ENV_DIR/.systems" -source $ENV_DIR/bin/denv_msg +source $ENV_DIR/bin/messages -denv_info_msg "[dev-env]: $ENV_DIR" +importantmsg "[dev-env]: $ENV_DIR" # Iterate through all lines in .systems configuration while IFS=' ' read -r IDENTIFIER DIRECTORY GIT; do @@ -12,5 +12,18 @@ while IFS=' ' read -r IDENTIFIER DIRECTORY GIT; do if [[ "$IDENTIFIER" =~ ^#.* ]] || [ -z "$IDENTIFIER" ]; then continue fi - denv_echo_msg "[$IDENTIFIER]: systems/$DIRECTORY" + + SYSTEM_PATH=$(realpath "$ENV_DIR/systems/$DIRECTORY") + BRANCH=$(git -C "$SYSTEM_PATH" rev-parse --abbrev-ref HEAD) + if [ -n "$(git -C "$SYSTEM_PATH" status --porcelain)" ]; then + CHANGES="(X)" + else + CHANGES="" + fi + + infomsg "[$IDENTIFIER]: ./systems/$DIRECTORY ${ANSI_OPEN}91m($BRANCH)${ANSI_OPEN}93m $CHANGES${ANSI_OPEN}0m" + done < "$CONFIG_FILE" + +echo "" +docker ps \ No newline at end of file diff --git a/init b/init index f426d93..3bd2a72 100755 --- a/init +++ b/init @@ -1,28 +1,38 @@ #!/bin/bash ENV_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) -source $ENV_DIR/bin/denv_msg +source $ENV_DIR/bin/messages # Check docker-compose.yml file if [ ! -f "$ENV_DIR/docker/docker-compose.yml" ] then cp "$ENV_DIR/docker/docker-compose.yml.dist" "$ENV_DIR/docker/docker-compose.yml" - denv_info_msg "[dev-env]: docker-compose.yml created" + infomsg "[dev-env]: docker-compose.yml created" +fi + +# Check .systems file +if [ ! -f "$ENV_DIR/.systems" ] +then + cp "$ENV_DIR/.systems.example" "$ENV_DIR/.systems" + infomsg "[dev-env]: .systems created" fi # Update .aliases -denv_info_msg "[dev-env]: Update dev-env/.aliases" +importantmsg "[dev-env]: Update dev-env/.aliases" $ENV_DIR/script/write_aliases -denv_success_msg "[dev-env]: Successfully updated dev-env/.aliases" +successmsg "[dev-env]: Update dev-env/.aliases done" +echo "" # Update .profile -denv_info_msg "[dev-env]: Update ~/.profile" +importantmsg "[dev-env]: Update ~/.profile" $ENV_DIR/script/update_profile -denv_success_msg "[dev-env]: Successfully updated ~/.profile" +successmsg "[dev-env]: Update ~/.profile done" +echo "" # Clone all systems. -denv_info_msg "[dev-env]: Clone systems" +importantmsg "[dev-env]: Clone systems" $ENV_DIR/script/clone -denv_success_msg "[dev-env]: Cloned systems" +successmsg "[dev-env]: Clone systems done" +echo "" # Run init for all systems $ENV_DIR/script/foreachSystem/runScript init diff --git a/prune b/prune new file mode 100755 index 0000000..8bb3d96 --- /dev/null +++ b/prune @@ -0,0 +1,21 @@ +#!/bin/bash +ENV_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +source $ENV_DIR/bin/messages + +warnmsg "This script will remove all docker containers and images" +warnmsg "All your data will be lost, and you will have a \"clean\" dev-env again" +warnmsg "Do you want to continue? (y/n)" +read -p "Answer: " ANSWER +echo "" + +if [[ "$ANSWER" == "y" || "$ANSWER" == "Y" ]]; then + infomsg "[dev-env]: Clearing docker" + docker rm -vf $(docker ps -aq) + docker rmi -f $(docker images -aq) + docker network prune -f + echo "" + + docker ps +else + infomsg "[dev-env]: prune cancelled" +fi \ No newline at end of file diff --git a/script/clone b/script/clone index dba46b3..c7617a1 100755 --- a/script/clone +++ b/script/clone @@ -1,11 +1,11 @@ #!/bin/bash ENV_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )/.." &> /dev/null && pwd ) CONFIG_FILE="$ENV_DIR/.systems" -source $ENV_DIR/bin/denv_msg +source $ENV_DIR/bin/messages # Check if .systems configuration exists if [ ! -f "$CONFIG_FILE" ]; then - denv_error_msg "$CONFIG_FILE not found." + errormsg "$CONFIG_FILE not found." exit 1 fi @@ -16,17 +16,15 @@ while IFS=' ' read -r IDENTIFIER DIRECTORY GIT; do continue fi - denv_info_msg "[$IDENTIFIER]" - - DIRECTORY="systems/$DIRECTORY" + SYSTEM_PATH="$ENV_DIR/systems/$DIRECTORY" + DIRECTORY="./systems/$DIRECTORY" # Check if system directory already exists - if [ ! -d "$DIRECTORY" ]; then - denv_info_msg "Clone into directory '$DIRECTORY'..." - git clone "$GIT" "$DIRECTORY" - denv_success_msg "Successfully cloned $IDENTIFIER" + if [ ! -d "$SYSTEM_PATH" ]; then + infomsg "[$IDENTIFIER] Clone into directory '$DIRECTORY'..." + git clone -b develop "$GIT" "$SYSTEM_PATH" + successmsg "Successfully cloned $IDENTIFIER" else - denv_echo_msg "Directory '$DIRECTORY' already exists. Skipping..." - echo "" + warnmsg "[$IDENTIFIER] Directory '$DIRECTORY' already exists. Skipping..." fi done < "$CONFIG_FILE" diff --git a/script/foreachSystem/dcom b/script/foreachSystem/dcom index 5236e3b..8863236 100755 --- a/script/foreachSystem/dcom +++ b/script/foreachSystem/dcom @@ -1,6 +1,6 @@ #!/bin/bash ENV_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )/../.." &> /dev/null && pwd ) -source $ENV_DIR/bin/denv_msg +source $ENV_DIR/bin/messages source $ENV_DIR/bin/dcom COMMAND="$@" @@ -8,11 +8,11 @@ CONFIG_FILE="$ENV_DIR/.systems" # Check if .systems configuration exists if [ ! -f "$CONFIG_FILE" ]; then - denv_error_msg "$CONFIG_FILE not found." + errormsg "$CONFIG_FILE not found." exit 1 fi -denv_info_msg "[dev-env]: Executing $COMMAND for all systems" +importantmsg "[dev-env]: Executing docker-compose $COMMAND for all systems" while IFS=' ' read -r IDENTIFIER DIRECTORY GIT; do # Iterate through all lines in .systems configuration if [[ "$IDENTIFIER" =~ ^#.* ]] || [ -z "$IDENTIFIER" ]; then # Skip comments and emtpy lines diff --git a/script/foreachSystem/runScript b/script/foreachSystem/runScript index 8c7579b..f9c5a1c 100755 --- a/script/foreachSystem/runScript +++ b/script/foreachSystem/runScript @@ -3,15 +3,15 @@ ENV_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )/../.." &> /dev/null && pwd CONFIG_FILE="$ENV_DIR/.systems" COMMAND="$@" -source $ENV_DIR/bin/denv_msg +source $ENV_DIR/bin/messages # Check if .systems configuration exists if [ ! -f "$CONFIG_FILE" ]; then - denv_error_msg "$CONFIG_FILE not found." + errormsg "$CONFIG_FILE not found." exit 1 fi -denv_info_msg "[dev-env]: Execute $COMMAND for all systems" +importantmsg "[dev-env]: Execute $COMMAND for all systems" # Iterate through all lines in .systems configuration while IFS=' ' read -r IDENTIFIER DIRECTORY GIT; do @@ -25,12 +25,15 @@ while IFS=' ' read -r IDENTIFIER DIRECTORY GIT; do # Check if system directory already exists if [ ! -f "$COMMAND_PATH" ]; then - denv_error_msg "$COMMAND_PATH not found." + errormsg "$COMMAND_PATH not found." continue fi - denv_info_msg "[$IDENTIFIER]: $COMMAND" + importantmsg "[$IDENTIFIER]: $COMMAND" $COMMAND_PATH - denv_success_msg "[$IDENTIFIER]: $COMMAND completed successfully" + successmsg "[$IDENTIFIER]: $COMMAND completed successfully" + echo "" done < "$CONFIG_FILE" + +successmsg "[dev-env]: Executed $COMMAND for all systems" \ No newline at end of file diff --git a/script/update_profile b/script/update_profile index 9d41dad..7c0ff68 100755 --- a/script/update_profile +++ b/script/update_profile @@ -1,7 +1,6 @@ #!/bin/bash ENV_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )/.." &> /dev/null && pwd ) - -source $ENV_DIR/bin/denv_msg +source $ENV_DIR/bin/messages PROFILE_FILE="$HOME/.profile" TEMPLATE_FILE="$ENV_DIR/.profile.template" @@ -12,7 +11,7 @@ END_MARKER="#DEV ENV SETUP END" # Check if template file exists if [ ! -f "$TEMPLATE_FILE" ]; then - denv_error_msg "[dev-env]: Template file '$TEMPLATE_FILE' does not exist. Skip updating .profile." + errormsg "[dev-env]: Template file '$TEMPLATE_FILE' does not exist. Skip updating .profile." exit 1 fi @@ -20,12 +19,12 @@ TEMPLATE_CONTENT=$(<"$TEMPLATE_FILE") # Check if start marker already exists in profile file if grep -q "$START_MARKER" "$PROFILE_FILE"; then - denv_echo_msg "[dev-env]: Section already exists. Update contents..." + warnmsg "[dev-env]: Section already exists. Update contents..." # Remove contents between start and end marker sed -i "/$START_MARKER/,/$END_MARKER/d" "$PROFILE_FILE" else - denv_echo_msg "[dev-env]: Section does not exists. Adding contents..." + infomsg "[dev-env]: Section does not exists. Adding contents..." fi ENV_DIR_STRING="# path\nDEV_ENV_PATH=$ENV_DIR\n" diff --git a/script/write_aliases b/script/write_aliases index 07c4990..9055e24 100755 --- a/script/write_aliases +++ b/script/write_aliases @@ -1,11 +1,11 @@ #!/bin/bash ENV_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )/.." &> /dev/null && pwd ) CONFIG_FILE="$ENV_DIR/.systems" -source $ENV_DIR/bin/denv_msg +source $ENV_DIR/bin/messages # Check if .systems configuration exists if [ ! -f "$CONFIG_FILE" ]; then - denv_error_msg "$CONFIG_FILE not found." + errormsg "$CONFIG_FILE not found." exit 1 fi diff --git a/stop b/stop index bb843f1..fb031e6 100755 --- a/stop +++ b/stop @@ -1,12 +1,11 @@ #!/bin/bash - ENV_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) -source $ENV_DIR/bin/denv_msg +source $ENV_DIR/bin/messages $ENV_DIR/script/foreachSystem/dcom stop + +infomsg "[dev-env]: Executing docker-compose stop for dev-env" +docker compose -f "$ENV_DIR/docker/docker-compose.yml" stop echo "" -denv_info_msg "[dev-env] stop" -docker compose -f "$ENV_DIR/docker/docker-compose.yml" stop - docker ps diff --git a/up b/up index fd4d207..823e0f6 100755 --- a/up +++ b/up @@ -1,15 +1,19 @@ #!/bin/bash - ENV_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) -source $ENV_DIR/bin/denv_msg +source $ENV_DIR/bin/messages -denv_info_msg "[dev-env]: up -d" +infomsg "[dev-env]: Executing docker-compose up -d for dev-env" docker compose -f "$ENV_DIR/docker/docker-compose.yml" up -d echo "" $ENV_DIR/script/foreachSystem/dcom up -d if [[ ! -f "$ENV_DIR/.firstRun" ]] ; then + # Setup databases for all systems + importantmsg "[dev-env]: Setup databases" + $ENV_DIR/script/create_databases + successmsg "[dev-env]: Setup databases done" + $ENV_DIR/script/foreachSystem/runScript firstRun touch "$ENV_DIR/.firstRun" fi