From ae3688b1662ce60d2e13862bb40ccdbc92859aeb Mon Sep 17 00:00:00 2001 From: Nick Yeoman Date: Tue, 19 Dec 2023 12:41:14 -0800 Subject: [PATCH] added env generator, removed .env --- .env | 8 -------- bin/generate_env.sh | 48 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 8 deletions(-) delete mode 100644 .env create mode 100644 bin/generate_env.sh diff --git a/.env b/.env deleted file mode 100644 index 49aa505..0000000 --- a/.env +++ /dev/null @@ -1,8 +0,0 @@ -NETWORKNAME= -MYSQL_ROOT_PASSWORD= -MYSQL_USER= -MYSQL_PASSWORD= -MYSQL_DATABASE= -MYSQL_USER= -MYSQL_PASSWORD= -MYSQL_DATABASE= diff --git a/bin/generate_env.sh b/bin/generate_env.sh new file mode 100644 index 0000000..c378629 --- /dev/null +++ b/bin/generate_env.sh @@ -0,0 +1,48 @@ +#!/bin/bash + +ENV_FILE=".env" + +# Function to generate a random alphanumeric password of a given length +generate_password() { + tr -dc 'a-zA-Z0-9' < /dev/urandom | head -c "${1:-12}" +} + +# Function to prompt for a value if not set as a parameter +prompt_for_value() { + read -p "$1: " value + echo "$value" +} + +# Set $PROJECTNAME if not provided as a parameter +PROJECTNAME=${1:-$(prompt_for_value "Enter PROJECTNAME")} + +cat < $ENV_FILE +# Docker +NETWORKNAME=${PROJECTNAME}_web + +# MySQL +MYSQL_ROOT_PASSWORD=$(generate_password) +MYSQL_USER=u$(echo $PROJECTNAME | tr '[:upper:]' '[:lower:]') +MYSQL_PASSWORD=$(generate_password) +MYSQL_DATABASE=db_$(echo $PROJECTNAME | tr '[:upper:]' '[:lower:]') + +# GITEA +GITEA_API_URL=REPLACEME +ACCESS_TOKEN=REPLACEME + +# Joomla +EMAIL=noreply@example.com +JOOMLA_USER="John Doe" +JOOMLA_USERNAME=admin +# Passwords must be 12 characters long (admin-password) +JOOMLA_PASSWORD=$(generate_password) + +# SMTP +SMTP_USER=null +SMTP_PASS=null +SMTP_HOST='mailhog' +SMTP_SECURITY='None' +SMTP_PORT=1025 +EOF + +echo "Generated $ENV_FILE with randomly generated passwords and customized PROJECTNAME."