Mercurial > public > ssdt-docker
view prod/setup.sh @ 331:c40a6fa09bed
changing protection on new file
author | aldrich |
---|---|
date | Wed, 15 Jan 2020 11:24:01 -0500 |
parents | 1f0ff7540734 |
children | e36bf4191e25 |
line wrap: on
line source
#!/bin/bash # Sets up a new district project based on SSDT default configuration in the current working directory. # # Usage: # # /data/preview/sampletown $ /ssdt/compose2/preview/setup.sh [usas,usps...] # # Will create a docker-compose.yml and .env file with default settings. # # Updated December 2019 to generate random admin passwords source "$(dirname "${BASH_SOURCE[0]}")/../scripts/.functions.sh" md5calc() { md5sum ${1} ; } md5verify() { md5sum -c --status ${1} ; } genDBHash() { echo $(date +%s%N | sha256sum | base64 | head -c 32 ; echo) } base=$(dirname "${BASH_SOURCE[0]}") default_name=$(basename $PWD) args="$1$2" usas="" usps="" if [ "$args" == "" ] || [ -z "${args##*usas*}" ] then usas=1 fi if [ "$args" == "" ] || [ -z "${args##*usps*}" ] then usps=1 fi echo "Preparing '$(basename $PWD)' with default USxS configuration" touch .env source .env if [ "$COMPOSE_PROJECT_NAME" == "" ] then read -e -p "Enter project name: <${default_name}> " answer project_name=${answer:-$default_name} echo "COMPOSE_PROJECT_NAME=${project_name}" >> .env echo "set project name in .env file" source .env fi if [ ! -e "docker-compose.yml" ] then create="OK" elif [ -e ".docker-compose.md5" ]; then md5verify ./.docker-compose.md5 && create="OK" fi if [ "$create" == "OK" ] then echo "# **** DO NOT MODIFY THIS FILE. ****" > ./docker-compose.yml echo "# Place customizations in docker-compose.override.yml and .env" >> ./docker-compose.yml echo "version: \"3.3\"" >> ./docker-compose.yml echo "services:" >> ./docker-compose.yml [ ! "$usas" == "" ] && cat $base/usas-services.yml >> ./docker-compose.yml echo "" >> ./docker-compose.yml [ ! "$usps" == "" ] && cat $base/usps-services.yml >> ./docker-compose.yml echo "" >> ./docker-compose.yml echo "volumes:" >> ./docker-compose.yml if [ ! "$usas" == "" ] then echo " usasdata:" >> ./docker-compose.yml [ "$USAS_DB_PASSWORD" == "" ] && echo "USAS_DB_PASSWORD=$(genDBHash)" >> ./.env [ "$USAS_ADMIN_PASSWORD" == "" ] && echo "USAS_ADMIN_PASSWORD=$(genDBHash)" >> ./.env fi if [ ! "$usps" == "" ] then echo " uspsdata:" >> ./docker-compose.yml [ "$USPS_DB_PASSWORD" == "" ] && echo "USPS_DB_PASSWORD=$(genDBHash)" >> ./.env [ "$USPS_ADMIN_PASSWORD" == "" ] && echo "USPS_ADMIN_PASSWORD=$(genDBHash)" >> ./.env fi echo "" >> ./docker-compose.yml md5calc ./docker-compose.yml > .docker-compose.md5 echo "created docker-compose.yml" else echo " Error! docker-compose.yml file has been modified or checksum missing. Can not auto-apply update(s). Move customizations to docker-compose.override.yml then delete the docker-compose.yml " fi ##Only creates a docker-compose.override.yml if one does not already exist. if [ ! -e "docker-compose.override.yml" ] then echo 'version: "3.3"' >> docker-compose.override.yml echo 'services:' >> docker-compose.override.yml ##usas admin components if [ ! "$usas" == "" ] then echo ' usasapp:' >> docker-compose.override.yml echo ' environment:' >> docker-compose.override.yml echo ' - APPLICATION_ADMIN_PASSWORD=${USAS_ADMIN_PASSWORD}' >> docker-compose.override.yml echo ' - APPLICATION_ADMIN_RESET=true' >> docker-compose.override.yml fi ##usps admin components if [ ! "$usps" == "" ] then echo ' uspsapp:' >> docker-compose.override.yml echo ' environment:' >> docker-compose.override.yml echo ' - APPLICATION_ADMIN_PASSWORD=${USPS_ADMIN_PASSWORD}' >> docker-compose.override.yml echo ' - APPLICATION_ADMIN_RESET=true' >> docker-compose.override.yml fi ##end of entire if statments for docker-compose.override.yml fi if [ "$USAS_APPLICATIONID" == "" ] then read -e -p "Generate USAS and USPS integration config? <Y/n> " answer case $answer in y | Y | yes | YES ) answer="y";; n | N | no | NO ) answer="n";; *) answer="y" esac if [ "$answer" == "y" ] then usas_id=${COMPOSE_PROJECT_NAME}-usas usas_key=$(openssl rand -hex 32) usps_id=${COMPOSE_PROJECT_NAME}-usps usps_key=$(openssl rand -hex 32) echo "USAS_APPLICATIONID=${usas_id}" >> .env echo "USAS_APIKEY=$usas_key" >> .env echo "USPS_APPLICATIONID=${usps_id}" >> .env echo "USPS_APIKEY=$usps_key" >> .env echo "Created integration API keys. Enable integration modules after applications start" fi fi if [ "$USAS_APP_HOST" == "" ] then echo "USAS_APP_HOST=usasapp-svr" >> .env fi if [ "$USPS_APP_HOST" == "" ] then echo "USPS_APP_HOST=uspsapp-svr" >> .env fi echo "Review or create a docker-compose.override.yml for custom settings."