Mercurial > public > ssdt-docker
comparison prod/setup.sh @ 234:2ae65177f74e
DEP-14: copy pilot scripts to prod
author | smith@nwoca.org |
---|---|
date | Wed, 10 Jan 2018 00:44:05 +0000 |
parents | pilot/setup.sh@10c139726e68 |
children | 1f0ff7540734 |
comparison
equal
deleted
inserted
replaced
233:3133ce001603 | 234:2ae65177f74e |
---|---|
1 #!/bin/bash | |
2 # Sets up a new district project based on SSDT default configuration in the current working directory. | |
3 # | |
4 # Usage: | |
5 # | |
6 # /data/preview/sampletown $ /ssdt/compose2/preview/setup.sh [usas,usps...] | |
7 # | |
8 # Will create a docker-compose.yml and .env file with default settings. | |
9 # | |
10 # | |
11 source "$(dirname "${BASH_SOURCE[0]}")/../scripts/.functions.sh" | |
12 | |
13 md5calc() { | |
14 md5sum ${1} ; | |
15 } | |
16 | |
17 md5verify() { | |
18 md5sum -c --status ${1} ; | |
19 } | |
20 | |
21 genDBHash() { | |
22 echo $(date +%s%N | sha256sum | base64 | head -c 32 ; echo) | |
23 } | |
24 | |
25 base=$(dirname "${BASH_SOURCE[0]}") | |
26 default_name=$(basename $PWD) | |
27 | |
28 args="$1$2" | |
29 | |
30 usas="" | |
31 usps="" | |
32 | |
33 if [ "$args" == "" ] || [ -z "${args##*usas*}" ] | |
34 then | |
35 usas=1 | |
36 fi | |
37 | |
38 if [ "$args" == "" ] || [ -z "${args##*usps*}" ] | |
39 then | |
40 usps=1 | |
41 fi | |
42 | |
43 echo "Preparing '$(basename $PWD)' with default USxS configuration" | |
44 | |
45 touch .env | |
46 source .env | |
47 | |
48 if [ "$COMPOSE_PROJECT_NAME" == "" ] | |
49 then | |
50 read -e -p "Enter project name: <${default_name}> " answer | |
51 project_name=${answer:-$default_name} | |
52 echo "COMPOSE_PROJECT_NAME=${project_name}" >> .env | |
53 echo "set project name in .env file" | |
54 source .env | |
55 fi | |
56 | |
57 if [ ! -e "docker-compose.yml" ] | |
58 then | |
59 create="OK" | |
60 elif [ -e ".docker-compose.md5" ]; then | |
61 md5verify ./.docker-compose.md5 && create="OK" | |
62 fi | |
63 | |
64 if [ "$create" == "OK" ] | |
65 then | |
66 echo "# **** DO NOT MODIFY THIS FILE. ****" > ./docker-compose.yml | |
67 echo "# Place customizations in docker-compose.override.yml and .env" >> ./docker-compose.yml | |
68 echo "version: \"3.3\"" >> ./docker-compose.yml | |
69 echo "services:" >> ./docker-compose.yml | |
70 | |
71 [ ! "$usas" == "" ] && cat $base/usas-services.yml >> ./docker-compose.yml | |
72 echo "" >> ./docker-compose.yml | |
73 | |
74 [ ! "$usps" == "" ] && cat $base/usps-services.yml >> ./docker-compose.yml | |
75 echo "" >> ./docker-compose.yml | |
76 | |
77 echo "volumes:" >> ./docker-compose.yml | |
78 | |
79 if [ ! "$usas" == "" ] | |
80 then | |
81 echo " usasdata:" >> ./docker-compose.yml | |
82 [ "$USAS_DB_PASSWORD" == "" ] && echo "USAS_DB_PASSWORD=$(genDBHash)" >> ./.env | |
83 fi | |
84 | |
85 if [ ! "$usps" == "" ] | |
86 then | |
87 echo " uspsdata:" >> ./docker-compose.yml | |
88 [ "$USPS_DB_PASSWORD" == "" ] && echo "USPS_DB_PASSWORD=$(genDBHash)" >> ./.env | |
89 fi | |
90 | |
91 echo "" >> ./docker-compose.yml | |
92 | |
93 md5calc ./docker-compose.yml > .docker-compose.md5 | |
94 | |
95 echo "created docker-compose.yml" | |
96 | |
97 else | |
98 echo " | |
99 | |
100 Error! docker-compose.yml file has been modified or checksum missing. Can not auto-apply update(s). | |
101 Move customizations to docker-compose.override.yml then delete the docker-compose.yml | |
102 " | |
103 fi | |
104 | |
105 if [ ! -e "docker-compose.override.yml" ] | |
106 then | |
107 echo 'version: "3.3"' >> docker-compose.override.yml | |
108 fi | |
109 | |
110 if [ "$USAS_APPLICATIONID" == "" ] | |
111 then | |
112 read -e -p "Generate USAS and USPS integration config? <Y/n> " answer | |
113 case $answer in | |
114 y | Y | yes | YES ) answer="y";; | |
115 n | N | no | NO ) answer="n";; | |
116 *) answer="y" | |
117 esac | |
118 if [ "$answer" == "y" ] | |
119 then | |
120 usas_id=${COMPOSE_PROJECT_NAME}-usas | |
121 usas_key=$(openssl rand -hex 32) | |
122 usps_id=${COMPOSE_PROJECT_NAME}-usps | |
123 usps_key=$(openssl rand -hex 32) | |
124 echo "USAS_APPLICATIONID=${usas_id}" >> .env | |
125 echo "USAS_APIKEY=$usas_key" >> .env | |
126 echo "USPS_APPLICATIONID=${usps_id}" >> .env | |
127 echo "USPS_APIKEY=$usps_key" >> .env | |
128 echo "Created integration API keys. Enable integration modules after applications start" | |
129 fi | |
130 fi | |
131 | |
132 if [ "$USAS_APP_HOST" == "" ] | |
133 then | |
134 echo "USAS_APP_HOST=usasapp-svr" >> .env | |
135 fi | |
136 | |
137 if [ "$USPS_APP_HOST" == "" ] | |
138 then | |
139 echo "USPS_APP_HOST=uspsapp-svr" >> .env | |
140 fi | |
141 | |
142 echo "Review or create a docker-compose.override.yml for custom settings." | |
143 |