Skip to content

Commit 6f90ef3

Browse files
authored
Merge pull request #532 from t3h2mas/feature/external-db
Allow for external DB
2 parents 5ee7049 + 738f820 commit 6f90ef3

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

entrypoint_scripts/common/dojo-shared-resources.sh

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -225,30 +225,45 @@ function ensure_mysql_application_db() {
225225
stty echo
226226
read -p "Database name (should NOT exist): " DBNAME
227227
else
228-
# Set the root password for mysql - install has it blank
229-
mysql -uroot -e "SET PASSWORD = PASSWORD('Cu3zehoh7eegoogohdoh1the');"
230-
# Default values for a automated Docker install
231-
echo "Setting default values for MySQL install"
232-
SQLHOST="localhost"
233-
SQLPORT="3306"
234-
SQLUSER="root"
235-
SQLPWD="Cu3zehoh7eegoogohdoh1the"
236-
DBNAME="dojodb"
228+
# Default values for a automated Docker install if not provided
229+
echo "Setting values for MySQL install"
230+
if [ -z "$SQLHOST" ]; then
231+
SQLHOST="localhost"
232+
fi
233+
if [ -z "$SQLPORT" ]; then
234+
SQLPORT="3306"
235+
fi
236+
if [ -z "$SQLUSER" ]; then
237+
SQLUSER="root"
238+
fi
239+
if [ -z "$SQLPWD" ]; then
240+
SQLPWD="Cu3zehoh7eegoogohdoh1the"
241+
fi
242+
if [ -z "$DBNAME" ]; then
243+
DBNAME="dojodb"
244+
fi
237245
fi
238246

239247
if mysql -fs --protocol=TCP -h "$SQLHOST" -P "$SQLPORT" -u"$SQLUSER" -p"$SQLPWD" "$DBNAME" >/dev/null 2>&1 </dev/null; then
240248
echo "Database $DBNAME already exists!"
241249
echo
242-
read -p "Drop database $DBNAME? [Y/n] " DELETE
250+
if [ "$AUTO_DOCKER" == "yes" ]; then
251+
if [ -z "$FLUSHDB" ]; then
252+
DELETE="yes"
253+
else
254+
DELETE="$FLUSHDB"
255+
fi
256+
else
257+
read -p "Drop database $DBNAME? [Y/n] " DELETE
258+
fi
243259
if [[ ! $DELETE =~ ^[nN]$ ]]; then
244260
mysqladmin -f --protocol=TCP --host="$SQLHOST" --port="$SQLPORT" --user="$SQLUSER" --password="$SQLPWD" drop "$DBNAME"
245261
mysqladmin --protocol=TCP --host="$SQLHOST" --port="$SQLPORT" --user="$SQLUSER" --password="$SQLPWD" create "$DBNAME"
246-
else
247-
echo "Error! Must supply an empty database to proceed."
248-
echo
249-
ensure_mysql_application_db
250262
fi
251263
else
264+
# Set the root password for mysql - install has it blank
265+
mysql -uroot -e "SET PASSWORD = PASSWORD('${SQLPWD}');"
266+
252267
if mysqladmin --protocol=TCP --host="$SQLHOST" --port="$SQLPORT" --user="$SQLUSER" --password="$SQLPWD" create $DBNAME; then
253268
echo "Created database $DBNAME."
254269
else

0 commit comments

Comments
 (0)