This commit is contained in:
Flo 2024-12-21 02:03:07 +01:00
parent b28b069884
commit 25a29caf5b
5 changed files with 16 additions and 82 deletions

View File

@ -1,72 +0,0 @@
#!/bin/bash
denvexec() {
if [ $# -lt 1 ]; then
echo "Verwendung: denvexec <docker command>"
return 1
fi
local DOCKER_COMMAND="$@"
local ENV_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )/.." &> /dev/null && pwd )
echo ""
echo "Directory: ${ENV_DIR}"
#MAC
if [[ "$OSTYPE" == "darwin"* ]]; then
docker compose -f "${ENV_DIR}/docker/docker-compose-mac.yml" $DOCKER_COMMAND
echo "done"
#LINUX
elif [[ "$OSTYPE" == "linux-gnu" ]]; then
docker compose -f "${ENV_DIR}/docker/docker-compose.yml" $DOCKER_COMMAND
echo "done"
else
echo "Dieses Skript wird auf deinem Gerät nicht unterstützt"
exit 1
fi
}
dexec() {
if [ $# -lt 2 ]; then
echo "Verwendung: dexec <system> <docker command>"
return 1
fi
local systemPart="${1%-*}" # before "-" e.g. auth / bee / etc
local typePart="${1##*-}" # after "-" e.g. backend / frontend
local SYSTEM_DIR="$typePart/$systemPart"
shift # removes first argument
local DOCKER_COMMAND="$@"
local ENV_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )/.." &> /dev/null && pwd )
echo ""
echo "Directory: ${ENV_DIR}/systems/${SYSTEM_DIR}"
local DOT_ENV_PATH="${ENV_DIR}/systems/${SYSTEM_DIR}/.env"
#SET ENV VARIABLES FROM .ENV
if [ -e "$DOT_ENV_PATH" ]; then
export $(grep -v '^#' "$DOT_ENV_PATH" | xargs)
fi
#MAC
if [[ "$OSTYPE" == "darwin"* ]]; then
docker compose -f "${ENV_DIR}/systems/${SYSTEM_DIR}/docker/docker-compose-mac.yml" $DOCKER_COMMAND
echo "done"
#LINUX
elif [[ "$OSTYPE" == "linux-gnu" ]]; then
docker compose -f "${ENV_DIR}/systems/${SYSTEM_DIR}/docker/docker-compose.yml" $DOCKER_COMMAND
echo "done"
else
echo "Dieses Skript wird auf deinem Gerät nicht unterstützt"
exit 1
fi
#UNSET ENV VARIABLES FROM .ENV
if [ -e "$DOT_ENV_PATH" ]; then
unset $(grep -v '^#' "$DOT_ENV_PATH" | sed -E 's/(.*)=.*/\1/' | xargs)
fi
}

2
init
View File

@ -9,9 +9,11 @@ fi
# Update .profile
$ENV_DIR/script/update_profile
echo ""
# Clone all systems.
$ENV_DIR/script/clone
echo ""
# Run init for all systems
./script/foreachSystem init

View File

@ -11,6 +11,8 @@ if [ ! -f "$CONFIG_FILE" ]; then
exit 1
fi
denv_info_msg "[dev-env]: Execute $COMMAND foreach System"
# Iterate through all lines in .systems configuration
while IFS=' ' read -r IDENTIFIER DIRECTORY GIT; do
# Skip comments and emtpy lines
@ -27,7 +29,10 @@ while IFS=' ' read -r IDENTIFIER DIRECTORY GIT; do
denv_error_msg "$COMMAND_PATH not found."
exit 1
else
denv_echo_msg "Executing $COMMAND_PATH..."
denv_echo_msg "Executing $COMMAND..."
$COMMAND_PATH
fi
denv_info_msg "System $IDENTIFIER done"
echo ""
done < "$CONFIG_FILE"

View File

@ -1,6 +1,8 @@
#!/bin/bash
ENV_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )/.." &> /dev/null && pwd )
source $ENV_DIR/bin/denv_msg
PROFILE_FILE="$HOME/.profile"
TEMPLATE_FILE="$ENV_DIR/.profile"
@ -10,25 +12,25 @@ END_MARKER="#DEV ENV SETUP END"
# Check if template file exists
if [ ! -f "$TEMPLATE_FILE" ]; then
echo "[DEV-ENV]: Template file '$TEMPLATE_FILE' does not exist. Skip updating .profile."
denv_error_msg "[dev-env]: Template file '$TEMPLATE_FILE' does not exist. Skip updating .profile."
exit 1
fi
TEMPLATE_CONTENT=$(<"$TEMPLATE_FILE")
echo "[DEV-ENV]: Update $PROFILE_FILE"
denv_info_msg "[dev-env]: Update $PROFILE_FILE"
# Check if start marker already exists in profile file
if grep -q "$START_MARKER" "$PROFILE_FILE"; then
echo "[DEV-ENV]: Section already exists. Update contents..."
denv_echo_msg "[dev-env]: Section already exists. Update contents..."
# Remove contents between start and end marker
sed -i "/$START_MARKER/,/$END_MARKER/d" "$PROFILE_FILE"
else
echo "[DEV-ENV]: Section does not exists. Adding contents..."
denv_echo_msg "[dev-env]: Section does not exists. Adding contents..."
fi
# Add contents
echo -e "\n$START_MARKER\n$TEMPLATE_CONTENT\n$END_MARKER" >> "$PROFILE_FILE"
echo "[DEV-ENV]: Successfully updated $PROFILE_FILE"
denv_success_msg "[dev-env]: Successfully updated $PROFILE_FILE"

5
up
View File

@ -1,10 +1,7 @@
#!/bin/bash
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source $SCRIPT_DIR/bin/denv
source $SCRIPT_DIR/bin/dexec
source $SCRIPT_DIR/bin/drun
denvexec up -d
docker compose -f "$SCRIPT_DIR/docker/docker-compose.yml" up -d
$SCRIPT_DIR/bin/script/foreachSystem up -d