Skip to content

Commit

Permalink
Merge pull request #532 from t3h2mas/feature/external-db
Browse files Browse the repository at this point in the history
Allow for external DB
  • Loading branch information
aaronweaver authored Apr 4, 2018
2 parents 5ee7049 + 738f820 commit 6f90ef3
Showing 1 changed file with 29 additions and 14 deletions.
43 changes: 29 additions & 14 deletions entrypoint_scripts/common/dojo-shared-resources.sh
Original file line number Diff line number Diff line change
Expand Up @@ -225,30 +225,45 @@ function ensure_mysql_application_db() {
stty echo
read -p "Database name (should NOT exist): " DBNAME
else
# Set the root password for mysql - install has it blank
mysql -uroot -e "SET PASSWORD = PASSWORD('Cu3zehoh7eegoogohdoh1the');"
# Default values for a automated Docker install
echo "Setting default values for MySQL install"
SQLHOST="localhost"
SQLPORT="3306"
SQLUSER="root"
SQLPWD="Cu3zehoh7eegoogohdoh1the"
DBNAME="dojodb"
# Default values for a automated Docker install if not provided
echo "Setting values for MySQL install"
if [ -z "$SQLHOST" ]; then
SQLHOST="localhost"
fi
if [ -z "$SQLPORT" ]; then
SQLPORT="3306"
fi
if [ -z "$SQLUSER" ]; then
SQLUSER="root"
fi
if [ -z "$SQLPWD" ]; then
SQLPWD="Cu3zehoh7eegoogohdoh1the"
fi
if [ -z "$DBNAME" ]; then
DBNAME="dojodb"
fi
fi

if mysql -fs --protocol=TCP -h "$SQLHOST" -P "$SQLPORT" -u"$SQLUSER" -p"$SQLPWD" "$DBNAME" >/dev/null 2>&1 </dev/null; then
echo "Database $DBNAME already exists!"
echo
read -p "Drop database $DBNAME? [Y/n] " DELETE
if [ "$AUTO_DOCKER" == "yes" ]; then
if [ -z "$FLUSHDB" ]; then
DELETE="yes"
else
DELETE="$FLUSHDB"
fi
else
read -p "Drop database $DBNAME? [Y/n] " DELETE
fi
if [[ ! $DELETE =~ ^[nN]$ ]]; then
mysqladmin -f --protocol=TCP --host="$SQLHOST" --port="$SQLPORT" --user="$SQLUSER" --password="$SQLPWD" drop "$DBNAME"
mysqladmin --protocol=TCP --host="$SQLHOST" --port="$SQLPORT" --user="$SQLUSER" --password="$SQLPWD" create "$DBNAME"
else
echo "Error! Must supply an empty database to proceed."
echo
ensure_mysql_application_db
fi
else
# Set the root password for mysql - install has it blank
mysql -uroot -e "SET PASSWORD = PASSWORD('${SQLPWD}');"

if mysqladmin --protocol=TCP --host="$SQLHOST" --port="$SQLPORT" --user="$SQLUSER" --password="$SQLPWD" create $DBNAME; then
echo "Created database $DBNAME."
else
Expand Down

0 comments on commit 6f90ef3

Please sign in to comment.