summaryrefslogtreecommitdiff
path: root/build/configure.sh
diff options
context:
space:
mode:
authorGeorgios Andreadis <g.andreadis@student.tudelft.nl>2017-09-23 23:36:55 +0200
committerGeorgios Andreadis <g.andreadis@student.tudelft.nl>2017-09-23 23:36:55 +0200
commit25ea7072fd24ebc4367fb854bd4ec8b3d778b5ab (patch)
treec26693a14a2fc0566521d12d9a2b2f97e4451e03 /build/configure.sh
parent12ce92b9aa4afa5c9a476c186b4bd924e3398f5b (diff)
Move to MariaDB
Diffstat (limited to 'build/configure.sh')
-rwxr-xr-xbuild/configure.sh33
1 files changed, 27 insertions, 6 deletions
diff --git a/build/configure.sh b/build/configure.sh
index fa1c8f96..5193e14f 100755
--- a/build/configure.sh
+++ b/build/configure.sh
@@ -1,8 +1,29 @@
-if [ ! -f "$1/opendc.db" ]; then
- sqlite3 "$1/opendc.db" < ./database/schema.sql
- sqlite3 "$1/opendc.db" < ./database/test.sql
+if [ -z "$MYSQL_DATABASE" ]; then
+ echo "MYSQL_DATABASE environment variable not specified"
+ exit 1
fi
-# ignore non ASCII characters
-LC_CTYPE=C
-LANG=C
+if [ -z "$MYSQL_USER" ]; then
+ echo "MYSQL_USER environment variable not specified"
+ exit 1
+fi
+
+if [ -z "$MYSQL_PASSWORD" ]; then
+ echo "MYSQL_PASSWORD environment variable not specified"
+ exit 1
+fi
+
+MYSQL_COMMAND="mysql -h mariadb -u $MYSQL_USER --password=$MYSQL_PASSWORD"
+
+until eval $MYSQL_COMMAND -e ";" ; do
+ echo "MariaDB is unavailable - sleeping"
+ sleep 1
+done
+
+NUM_TABLES=$(eval "$MYSQL_COMMAND -B --disable-column-names \"SELECT count(*) FROM information_schema.tables WHERE table_schema='$MYSQL_DATABASE';\"")
+
+# Check if database is empty
+if [ "$NUM_TABLES" -eq 0 ]; then
+ eval $MYSQL_COMMAND "$MYSQL_DATABASE" < ./database/schema.sql
+ eval $MYSQL_COMMAND "$MYSQL_DATABASE" < ./database/test.sql
+fi