From 6d8dff97e8f226cd68d427057d31f8e2e85e26fc Mon Sep 17 00:00:00 2001 From: Mihai Date: Mon, 16 Oct 2023 20:16:11 -0400 Subject: [PATCH 1/3] replace just one variable --- setup_env.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/setup_env.sh b/setup_env.sh index fb435a0..06a3623 100755 --- a/setup_env.sh +++ b/setup_env.sh @@ -179,4 +179,10 @@ if $COMPETITION; then cat env/env.time >>.env fi +# If PORTS=true, replace $ETH_PORT in the generated .env file +source env/env.ports +if $PORTS; then + sed -i "s/\$ETH_PORT/$ETH_PORT/g" .env +fi + echo "Environment filed created at .env" From 901c6401aea0ec996b88f503d5c8009cc8d473f7 Mon Sep 17 00:00:00 2001 From: Mihai Date: Mon, 16 Oct 2023 21:51:35 -0400 Subject: [PATCH 2/3] replace all the variables --- env/env.common | 4 +++- env/env.frontend | 2 +- env/env.ports | 2 +- env/env.postgres | 2 +- setup_env.sh | 33 ++++++++++++++++++++++++++++++--- 5 files changed, 36 insertions(+), 7 deletions(-) diff --git a/env/env.common b/env/env.common index 43d5aaa..16c193b 100644 --- a/env/env.common +++ b/env/env.common @@ -1,4 +1,6 @@ -# Networking configuration +# Networking configuration. +# These addresses are for INSIDE DOCKER communication ONLY. +# do NOT change these based on your custom local setup, MIHAI. ARTIFACTS_URI=http://artifacts:8080 RPC_URI=http://ethereum:8545 DATABASE_API_URI=http://database-api-server:5002 diff --git a/env/env.frontend b/env/env.frontend index 9267a87..bf6ea01 100644 --- a/env/env.frontend +++ b/env/env.frontend @@ -1,5 +1,5 @@ # The endpoints and chain id used by the UI -UI_RPC_URL=http://localhost:8545 +UI_RPC_URL=http://localhost:ETH_PORT UI_ADDRESSES_URL=http://localhost:8080 UI_CHAIN_ID=42069 diff --git a/env/env.ports b/env/env.ports index a399695..f103f5b 100644 --- a/env/env.ports +++ b/env/env.ports @@ -1,5 +1,5 @@ # The ports that should be opened if the --ports option is used. -ETH_PORT=8545 +ETH_PORT=8546 ARTIFACT_PORT=8080 UI_PORT=5173 USERNAME_REGISTER_PORT=5002 diff --git a/env/env.postgres b/env/env.postgres index 4249d7f..d4f99d0 100644 --- a/env/env.postgres +++ b/env/env.postgres @@ -1,5 +1,5 @@ POSTGRES_USER=admin POSTGRES_PASSWORD=password POSTGRES_DB=postgres_db -POSTGRES_HOST="db" +POSTGRES_HOST=db POSTGRES_PORT=5432 diff --git a/setup_env.sh b/setup_env.sh index 06a3623..2cbbfe8 100755 --- a/setup_env.sh +++ b/setup_env.sh @@ -179,10 +179,37 @@ if $COMPETITION; then cat env/env.time >>.env fi -# If PORTS=true, replace $ETH_PORT in the generated .env file -source env/env.ports +# source: https://chat.openai.com/share/ebaf2531-b46c-4aed-aaa6-1e1400a5fd8f if $PORTS; then - sed -i "s/\$ETH_PORT/$ETH_PORT/g" .env + while IFS='=' read -r var value; do + if [[ ! $var =~ ^# ]]; then + changed=false + declared_change=false + temp_file=$(mktemp) + while IFS= read -r line; do + original_line="$line" + # Check if the line contains the variable but doesn't start with it + if [[ "$line" == *"$var"* ]] && [[ ! "$line" == "$var="* ]]; then + line="${line//$var/$value}" # Replace all occurrences of $var with $value + if [ "$original_line" != "$line" ]; then + if [ "$declared_change" = false ]; then + echo "Setting $var to $value:" + declared_change=true + fi + echo " $original_line" + echo " -> $line" + changed=true # Add this line + fi + fi + echo "$line" >> "$temp_file" + done < .env + if [ "$changed" = true ]; then + mv "$temp_file" .env # Replace the original .env file with the modified one + else + rm "$temp_file" # Remove the temporary file if no changes were made + fi + fi + done < env/env.ports fi echo "Environment filed created at .env" From 7e8b7999c1a3e905fbe04ef75955953ab005364a Mon Sep 17 00:00:00 2001 From: Mihai Date: Mon, 16 Oct 2023 22:02:29 -0400 Subject: [PATCH 3/3] reset to default port --- env/env.ports | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/env/env.ports b/env/env.ports index f103f5b..a399695 100644 --- a/env/env.ports +++ b/env/env.ports @@ -1,5 +1,5 @@ # The ports that should be opened if the --ports option is used. -ETH_PORT=8546 +ETH_PORT=8545 ARTIFACT_PORT=8080 UI_PORT=5173 USERNAME_REGISTER_PORT=5002