Browse Source

feat: update to new configuration

master
bucde 3 years ago
parent
commit
aa7c062b33
2 changed files with 55 additions and 16 deletions
  1. +1
    -1
      docker-compose.yml
  2. +54
    -15
      setup

+ 1
- 1
docker-compose.yml View File

@ -1,7 +1,7 @@
version: "3.4"
services:
postgres:
container_name: postgres
container_name: ${POSTGRES_CONTAINER_NAME:-postgres}
image: postgres:${POSTGRES_VERSION:-latest}
restart: unless-stopped
ports:


+ 54
- 15
setup View File

@ -6,15 +6,21 @@ 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 "# Config will be saved in 'config' file. #"
echo "# (everything in plain text, even the password) #"
#echo "# #"
echo "####################################################################"
echo ""
DATE=$(date +'%y%m%d%H%M%S')
CONFIG_EXISTS="false"
KEEP_CONFIG=""
USE_EXISTING_CONFIG=""
DELETE_CONFIG=""
POSTGRES_PROJECT_NAME="postgres_${DATE}"
POSTGRES_PROJECT_NAME_SUFFIX=""
POSTGRES_CONTAINER_NAME="${POSTGRES_PROJECT_NAME}_db"
POSTGRES_VERSION=""
POSTGRES_HOST_IP_ADDRESS=""
POSTGRES_HOST_PORT=""
@ -23,40 +29,65 @@ POSTGRES_ADMIN_PASSWORD=""
POSTGRES_SHARED_HOSTING=""
if [ -f ".env" ]; then
read -p "Enter postgres project name suffix (leave empty for none): " POSTGRES_PROJECT_NAME_SUFFIX
if [ -n "$POSTGRES_PROJECT_NAME_SUFFIX" ]; then
POSTGRES_PROJECT_NAME="${POSTGRES_PROJECT_NAME}_${POSTGRES_PROJECT_NAME_SUFFIX}"
POSTGRES_CONTAINER_NAME="${POSTGRES_CONTAINER_NAME}_${POSTGRES_PROJECT_NAME_SUFFIX}"
fi
rm -f .env
touch .env
echo "COMPOSE_PROJECT_NAME="$POSTGRES_PROJECT_NAME >> .env
echo "POSTGRES_CONTAINER_NAME="$POSTGRES_CONTAINER_NAME >> .env
if [ -f "config" ]; then
CONFIG_EXISTS="true"
read -p "Config file '.env' already exists! Would you like to use this? (y/n)" KEEP_CONFIG
read -p "Config file 'config' already exists! Would you like to use this? (y/n)" USE_EXISTING_CONFIG
fi
if [ $CONFIG_EXISTS == "false" ] || [ $KEEP_CONFIG == "n" ]; then
if [ $CONFIG_EXISTS == "false" ] || [ $USE_EXISTING_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
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
rm -f config
touch config
echo "POSTGRES_VERSION="$POSTGRES_VERSION >> config
echo "POSTGRES_HOST_IP_ADDRESS="$POSTGRES_HOST_IP_ADDRESS >> config
echo "POSTGRES_HOST_PORT="$POSTGRES_HOST_PORT >> config
echo "POSTGRES_ADMIN_USER="$POSTGRES_ADMIN_USER >> config
echo "POSTGRES_ADMIN_PASSWORD="$POSTGRES_ADMIN_PASSWORD >> config
echo "Config file 'config' created!"
else
echo "Use existing config file 'config'!"
while read line; do
if [[ $line == *"POSTGRES_ADMIN_USER="* ]]; then
POSTGRES_ADMIN_USER=$(echo $line | cut -c 21-)
fi
done < ".env"
done < "config"
fi
cat "config" >> ".env"
read -p "Should the config file 'config' be deleted after creating the container? (y/n)" DELETE_CONFIG
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 for the container to spin up ..."
echo -n "Wait until postgres is ready ..."
sleep 5
while ! docker exec $POSTGRES_CONTAINER_NAME pg_isready; do
echo -n "."
sleep 1
done
echo -e "\nPostgres is ready!"
if [ $POSTGRES_SHARED_HOSTING == "y" ]; then
rm -f tmp
@ -78,4 +109,12 @@ if [ $POSTGRES_SHARED_HOSTING == "y" ]; then
rm -f tmp
fi
if [ $DELETE_CONFIG == "y" ]; then
rm -f config
echo "Config file 'config' deleted!"
fi
rm -f .env
echo "Done!"

Loading…
Cancel
Save