toujours dans l'env

This commit is contained in:
batche
2023-01-02 22:43:09 +01:00
parent 74f17a18d6
commit 12b2ec8ce8
3 changed files with 63 additions and 65 deletions

View File

@@ -1,6 +1,7 @@
#! /usr/bin/env bash #! /usr/bin/env bash
ENV_FILE_DOCKER=./srcs/.env
ENV_FILE_SVELTE=./srcs/requirements/svelte/api_front/.env
# Function to generate passwords # Function to generate passwords
# #
@@ -12,32 +13,8 @@
echo $(openssl rand -base64 32 | tr "/" "_" ); echo $(openssl rand -base64 32 | tr "/" "_" );
} }
function make_env_for_docker_and_svelte
{
# This script is used to create a new environment for the project.
#
ENV_FILE_DOCKER=./srcs/.env
ENV_FILE_SVELTE=./srcs/requirements/svelte/api_front/.env
# Check for existing .env
if [ -f "$ENV_FILE_DOCKER" ]; then
echo "The file $ENV_FILE_DOCKER already exists. Do you want to overwrite it ? (y/n)"
OVERWRITE=""
# Ask to overwrite the .env files
while [ "$OVERWRITE" != "y" ] && [ "$OVERWRITE" != "n" ]; do
read -p "Enter your choice : " OVERWRITE
done
if [ "$OVERWRITE" = "y" ]; then
rm "$ENV_FILE_DOCKER" && rm "$ENV_FILE_SVELTE"
docker rmi -f postgres
else
cp "$ENV_FILE_DOCKER" "$ENV_FILE_SVELTE"
echo "The file $ENV_FILE_DOCKER and $ENV_FILE_SVELTE will not be overwritten. The script will exit."
exit 0
fi
fi
# Create a new environment for docker
echo "Creating a new environment for docker" echo "Creating a new environment for docker"
NODE_ENV="" NODE_ENV=""
# Ask if dev or prod environment # Ask if dev or prod environment
@@ -49,11 +26,9 @@
else else
echo "NODE_ENV=production" > "$ENV_FILE_DOCKER" echo "NODE_ENV=production" > "$ENV_FILE_DOCKER"
fi fi
# Env variables
read -p "Enter the name of the host like \"localhost\" : " PROJECT_HOST read -p "Enter the name of the host like \"localhost\" : " PROJECT_HOST
echo "WEBSITE_HOST=$PROJECT_HOST" >> "$ENV_FILE_DOCKER" echo "WEBSITE_HOST=$PROJECT_HOST" >> "$ENV_FILE_DOCKER"
echo "WEBSITE_PORT=8080" >> "$ENV_FILE_DOCKER" echo "WEBSITE_PORT=8080" >> "$ENV_FILE_DOCKER"
cp "$ENV_FILE_DOCKER" "$ENV_FILE_SVELTE"
echo "POSTGRES_USER=postgres" >> "$ENV_FILE_DOCKER" echo "POSTGRES_USER=postgres" >> "$ENV_FILE_DOCKER"
echo "#if change postgres pswd, do make destroy" >> "$ENV_FILE_DOCKER" echo "#if change postgres pswd, do make destroy" >> "$ENV_FILE_DOCKER"
echo "POSTGRES_PASSWORD=$(generate_password)" >> "$ENV_FILE_DOCKER" echo "POSTGRES_PASSWORD=$(generate_password)" >> "$ENV_FILE_DOCKER"
@@ -76,9 +51,34 @@
echo "PORT=3000" >> "$ENV_FILE_DOCKER" echo "PORT=3000" >> "$ENV_FILE_DOCKER"
echo "TWO_FACTOR_AUTHENTICATION_APP_NAME=Transcendance" >> "$ENV_FILE_DOCKER" echo "TWO_FACTOR_AUTHENTICATION_APP_NAME=Transcendance" >> "$ENV_FILE_DOCKER"
echo "TICKET_FOR_PLAYING_GAME_SECRET=$(generate_password)" >> "$ENV_FILE_DOCKER" echo "TICKET_FOR_PLAYING_GAME_SECRET=$(generate_password)" >> "$ENV_FILE_DOCKER"
sed 's/^WEBSITE_/PUBLIC_&/' "$ENV_FILE_DOCKER" | grep "PUBLIC_" > "$ENV_FILE_SVELTE"
}
function choose_options_and_process {
if [ -f "$ENV_FILE_DOCKER" ]; then
echo "The file $ENV_FILE_DOCKER already exists. Do you want to overwrite it ? (y/n)"
OVERWRITE=""
# Ask to overwrite the .env files
while [ "$OVERWRITE" != "y" ] && [ "$OVERWRITE" != "n" ]; do
read -p "Enter your choice : " OVERWRITE
done
if [ "$OVERWRITE" = "y" ]; then
rm "$ENV_FILE_DOCKER" && rm "$ENV_FILE_SVELTE"
docker rmi -f postgres
make_env_for_docker_and_svelte
else
if [ ! -f "$ENV_FILE_SVELTE" ]; then
sed 's/^WEBSITE_/PUBLIC_&/' "$ENV_FILE_DOCKER" | grep "PUBLIC_" > "$ENV_FILE_SVELTE"
fi
echo "The file $ENV_FILE_DOCKER will not be overwritten. The script will exit."
exit 0
fi
fi
}
# Create a new environment for docker
choose_options_and_process
# it's finished !
#
echo "The environment has been created successfully. You can now wait for the docker to build the project." echo "The environment has been created successfully. You can now wait for the docker to build the project."

View File

@@ -8,3 +8,4 @@
!api_front/*.json !api_front/*.json
!api_front/*.html !api_front/*.html
!api_front/*.lock !api_front/*.lock
!api_front/.env

View File

@@ -1,3 +0,0 @@
export const Domain = "transcendance";
export const Port = "8080";
export const PortIo = Port;