-
Notifications
You must be signed in to change notification settings - Fork 8
/
init-proton.sh
executable file
·236 lines (202 loc) · 9.48 KB
/
init-proton.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#!/bin/bash
# BSD 3-Clause License
#
# Copyright (c) 2018, Pruthvi Kumar All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
# following conditions are met:
#
# Redistributions of source code must retain the above copyright notice, this list of conditions and the following
# disclaimer.
#
# Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided with the distribution.
#
# Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
## @Author: Pruthvi Kumar
## @Email: pruthvikumar.123@gmail.com
## @Desc: Script to check and set all vitals required by proton platform.!
echo -e "-------------------------------------------------------------------------------------------------------------------"
echo -e "\e[33m Validating PROTON vitals... \e[0m"
echo -e "-------------------------------------------------------------------------------------------------------------------"
if [[ -f .env ]]; then
# check if env contains all required variables.
eval "$(grep ^APP_NAME= .env)"
eval "$(grep ^APP_SUPPORT_EMAIL= .env)"
eval "$(grep ^PG_USERNAME= .env)"
eval "$(grep ^PG_PASSWORD= .env)"
eval "$(grep ^PG_TARGET_DB= .env)"
eval "$(grep ^PG_TARGET_PORT= .env)"
eval "$(grep ^REDIS_TARGET_PORT= .env)"
eval "$(grep ^PROTON_BIND_ADDRESS= .env)"
eval "$(grep ^PROTON_TARGET_PORT= .env)"
eval "$(grep ^PROTON_SQLITE_VOLUME_MOUNT= .env)"
eval "$(grep ^PROTON_POSTGRES_VOLUME_MOUNT= .env)"
eval "$(grep ^PROTON_REDIS_VOLUME_MOUNT= .env)"
eval "$(grep ^SENDGRID_API_KEY= .env)"
if [[ -z "$APP_NAME" ]]; then
while [[ -z "$APP_NAME" ]]
do
read -p "Please enter the name of your APP which PROTON needs to empower: " APP_NAME
done
fi
if [[ -z "$APP_SUPPORT_EMAIL" ]]; then
while [[ -z "$APP_SUPPORT_EMAIL" ]]
do
read -p "Please enter the email address of your support center/support person: " APP_SUPPORT_EMAIL
done
fi
if [[ -z "$PG_USERNAME" ]]; then
while [[ -z "$PG_USERNAME" ]]
do
read -p "PROTON is missing key environment var - PG_USERNAME. \
By default, PROTON ships with support for postgres. \
PG_USERNAME is the username that PROTON's postgres will use for login purposes.\
Please enter username for PROTON's postgres: " PG_USERNAME
done
fi
if [[ -z "$PG_PASSWORD" ]]; then
while [[ -z "$PG_PASSWORD" ]]
do
read -p "PROTON is missing key environment var - PG_PASSWORD. \
By default, PROTON ships with support for postgres. \
PG_PASSWORD is the password that PROTON's postgres will use for login purposes.\
Please enter password for PROTON's postgres: " PG_PASSWORD
done
fi
if [[ -z "$PG_TARGET_DB" ]]; then
PG_TARGET_DB=proton
fi
if [[ -z "$PG_TARGET_PORT" ]]; then
PG_TARGET_PORT=5432
fi
if [[ -z "$REDIS_TARGET_PORT" ]]; then
REDIS_TARGET_PORT=6379
fi
if [[ -z "$PROTON_BIND_ADDRESS" ]]; then
PROTON_BIND_ADDRESS=0.0.0.0
fi
if [[ -z "$PROTON_TARGET_PORT" ]]; then
PROTON_TARGET_PORT=3000
fi
if [[ -z "$PROTON_SQLITE_VOLUME_MOUNT" ]]; then
while [[ -z "$PROTON_SQLITE_VOLUME_MOUNT" ]]
do
read -p "PROTON is missing key environment var - PROTON_SQLITE_VOLUME_MOUNT. \
By default, PROTON ships with support for sqlite. \
PROTON_SQLITE_VOLUME_MOUNT is the location that PROTON's sqlite file will mount onto.\
Please enter the absolute location where PROTON's sqlite can mount onto: " PROTON_SQLITE_VOLUME_MOUNT
done
fi
if [[ -z "$PROTON_POSTGRES_VOLUME_MOUNT" ]]; then
while [[ -z "$PROTON_POSTGRES_VOLUME_MOUNT" ]]
do
read -p "PROTON is missing key environment var - PROTON_POSTGRES_VOLUME_MOUNT. \
By default, PROTON ships with support for postgres. \
PROTON_POSTGRES_VOLUME_MOUNT is the location that PROTON's postgres container will mount onto.\
Please enter the absolute location where PROTON's postgres can mount onto: " PROTON_POSTGRES_VOLUME_MOUNT
done
fi
if [[ -z "$PROTON_REDIS_VOLUME_MOUNT" ]]; then
while [[ -z "$PROTON_REDIS_VOLUME_MOUNT" ]]
do
read -p "PROTON is missing key environment var - PROTON_REDIS_VOLUME_MOUNT. \
By default, PROTON ships with cache support by incorporating Redis. \
PROTON_REDIS_VOLUME_MOUNT is the location that PROTON's redis container will mount onto.\
Please enter the absolute location where PROTON's redis can mount onto: " PROTON_REDIS_VOLUME_MOUNT
done
fi
if [[ -z "$SENDGRID_API_KEY" ]]; then
while [[ -z "$SENDGRID_API_KEY" ]]
do
read -p "PROTON ships with abilities to send emails. This is dependent on sendgrid. If you don't \
have a sendgrid account yet, please create a free account here - https://signup.sendgrid.com/ . Create \
an API key and paste that key here: " SENDGRID_API_KEY
done
fi
else
touch .env
PG_TARGET_DB=proton
PG_TARGET_PORT=5432
REDIS_TARGET_PORT=6379
PROTON_BIND_ADDRESS=0.0.0.0
PROTON_TARGET_PORT=3000
while [[ -z "$APP_NAME" ]]
do
read -p "Please enter the name of your APP which PROTON needs to empower: " APP_NAME
done
while [[ -z "$APP_SUPPORT_EMAIL" ]]
do
read -p "Please enter the email address of your support center/support person: " APP_SUPPORT_EMAIL
done
while [[ -z "$PG_USERNAME" ]]
do
read -p "By default, PROTON ships with support for postgres.\
PG_USERNAME is the username that PROTON's postgres will use for login purposes.\
Please enter username for PROTON's postgres: " PG_USERNAME
done
while [[ -z "$PG_PASSWORD" ]]
do
read -p "By default, PROTON ships with support for postgres. \
PG_PASSWORD is the password that PROTON's postgres will use for login purposes.\
Please enter password for PROTON's postgres: " PG_PASSWORD
done
while [[ -z "$PROTON_SQLITE_VOLUME_MOUNT" ]]
do
read -p "By default, PROTON ships with support for sqlite. \
PROTON_SQLITE_VOLUME_MOUNT is the location that PROTON's sqlite file will mount onto.\
Please enter the absolute location where PROTON's sqlite can mount onto: " PROTON_SQLITE_VOLUME_MOUNT
done
while [[ -z "$PROTON_POSTGRES_VOLUME_MOUNT" ]]
do
read -p "By default, PROTON ships with support for postgres. \
PROTON_POSTGRES_VOLUME_MOUNT is the location that PROTON's postgres container will mount onto.\
Please enter the absolute location where PROTON's postgres can mount onto: " PROTON_POSTGRES_VOLUME_MOUNT
done
while [[ -z "$PROTON_REDIS_VOLUME_MOUNT" ]]
do
read -p "By default, PROTON ships with cache support by incorporating Redis. \
PROTON_REDIS_VOLUME_MOUNT is the location that PROTON's redis container will mount onto.\
Please enter the absolute location where PROTON's redis can mount onto: " PROTON_REDIS_VOLUME_MOUNT
done
while [[ -z "$SENDGRID_API_KEY" ]]
do
read -p "PROTON ships with abilities to send emails. This is dependent on sendgrid. If you don't \
have a sendgrid account yet, please create a free account here - https://signup.sendgrid.com/ . Create \
an API key and paste that key here: " SENDGRID_API_KEY
done
fi
cat << EOF > .env
# PS: ANY CHANGES HERE WILL AFFECT BUILD PROCESS.
# PS: DO NOT DELETE ANY VARIABLES OR RENAME THEM. PROTON'S CONTAINERS RELY ON THESE VARIABLES.
APP_NAME=$APP_NAME
APP_SUPPORT_EMAIL=$APP_SUPPORT_EMAIL
PG_USERNAME=$PG_USERNAME
PG_PASSWORD=$PG_PASSWORD
PG_TARGET_DB=$PG_TARGET_DB
PG_TARGET_PORT=$PG_TARGET_PORT
REDIS_TARGET_PORT=$REDIS_TARGET_PORT
PROTON_BIND_ADDRESS=$PROTON_BIND_ADDRESS
PROTON_TARGET_PORT=$PROTON_TARGET_PORT
PROTON_SQLITE_VOLUME_MOUNT=$PROTON_SQLITE_VOLUME_MOUNT
PROTON_POSTGRES_VOLUME_MOUNT=$PROTON_POSTGRES_VOLUME_MOUNT
PROTON_REDIS_VOLUME_MOUNT=$PROTON_REDIS_VOLUME_MOUNT
SENDGRID_API_KEY=$SENDGRID_API_KEY
EOF
# configuring SQLITE mount path for the PROTON container.
mkdir -p ./proton_vars
rm -f ./proton_vars/proton_sqlite_config.txt
touch ./proton_vars/proton_sqlite_config.txt
echo "/PROTON/proton-db/proton-sqlite.db" >> ./proton_vars/proton_sqlite_config.txt
echo -e "-------------------------------------------------------------------------------------------------------------------"
echo -e "\e[33m PROTON has all vitals checked and set. \e[0m"
echo -e "-------------------------------------------------------------------------------------------------------------------"