From a74c10c5aaf152e771c6901196ab55a89637d8c8 Mon Sep 17 00:00:00 2001 From: bucde Date: Mon, 13 Sep 2021 12:03:17 +0200 Subject: [PATCH] feat: add option to use existing .env file --- setup | 51 +++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 14 deletions(-) diff --git a/setup b/setup index cc22a9b..5689796 100755 --- a/setup +++ b/setup @@ -4,34 +4,57 @@ echo '####################################################################' echo '# docker_postgres_setup_script #' echo '# Dennis Buchhorn - bucde@b-eit.de #' echo '####################################################################' +echo '# WARNING: password is plain text input! #' +echo '# #' +echo "# Config will be saved in '.env' file. #" +echo '# (everything in plain text, even the password) #' +#echo '# #' +echo '####################################################################' echo '' +CONFIG_EXISTS='false' +KEEP_CONFIG='' + POSTGRES_VERSION='' POSTGRES_HOST_IP_ADDRESS='' POSTGRES_HOST_PORT='' POSTGRES_ADMIN_USER='' POSTGRES_ADMIN_PASSWORD='' -POSTGRES_SHARED_HOSTING='y' +POSTGRES_SHARED_HOSTING='' -read -p 'Enter postgres version which should be used: ' POSTGRES_VERSION -read -p 'Enter host (vm) ip address on which postgres should be accessible: ' POSTGRES_HOST_IP_ADDRESS -read -p 'Enter host (vm) port on which postgres should be accessible: ' POSTGRES_HOST_PORT -read -p 'Enter admin user name for postgres: ' POSTGRES_ADMIN_USER -read -p 'Enter admin password for postgres: ' POSTGRES_ADMIN_PASSWORD +if [ -f ".env" ]; then + CONFIG_EXISTS='true' + read -p "Config file '.env' already exists! Would you like to use this? (y/n)" KEEP_CONFIG +fi -read -p 'Would you like to modify postgres rights for shared hosting? (y/n)' POSTGRES_SHARED_HOSTING +if [ $CONFIG_EXISTS == 'false' ] || [ $KEEP_CONFIG == 'n' ]; then + read -p 'Enter postgres version which should be used: ' POSTGRES_VERSION + read -p 'Enter host (vm) ip address on which postgres should be accessible: ' POSTGRES_HOST_IP_ADDRESS + read -p 'Enter host (vm) port on which postgres should be accessible: ' POSTGRES_HOST_PORT + read -p 'Enter admin user name for postgres: ' POSTGRES_ADMIN_USER + read -p 'Enter admin password for postgres: ' POSTGRES_ADMIN_PASSWORD -touch .env -echo "POSTGRES_VERSION="$POSTGRES_VERSION >> .env -echo "POSTGRES_HOST_IP_ADDRESS="$POSTGRES_HOST_IP_ADDRESS >> .env -echo "POSTGRES_HOST_PORT="$POSTGRES_HOST_PORT >> .env -echo "POSTGRES_ADMIN_USER="$POSTGRES_ADMIN_USER >> .env -echo "POSTGRES_ADMIN_PASSWORD="$POSTGRES_ADMIN_PASSWORD >> .env + rm -f .env + touch .env + echo "POSTGRES_VERSION="$POSTGRES_VERSION >> .env + echo "POSTGRES_HOST_IP_ADDRESS="$POSTGRES_HOST_IP_ADDRESS >> .env + echo "POSTGRES_HOST_PORT="$POSTGRES_HOST_PORT >> .env + echo "POSTGRES_ADMIN_USER="$POSTGRES_ADMIN_USER >> .env + echo "POSTGRES_ADMIN_PASSWORD="$POSTGRES_ADMIN_PASSWORD >> .env +else + while read line; do + if [[ $line == *"POSTGRES_ADMIN_USER="* ]]; then + POSTGRES_ADMIN_USER=$(echo $line | cut -c 21-) + fi + done < ".env" +fi + +read -p 'Would you like to modify postgres rights for shared hosting? (y/n)' POSTGRES_SHARED_HOSTING docker-compose up -d -echo 'Wait a few seconds ...' +echo 'Wait a few seconds for the container to spin up ...' sleep 5