From 607b31b79163528902f250d50490705b8f5a3239 Mon Sep 17 00:00:00 2001
From: David Trattnig <david.trattnig@o94.at>
Date: Wed, 1 Apr 2020 21:26:50 +0200
Subject: [PATCH] Simplified installation.

---
 contrib/aura-clock/package.json   |  2 +-
 install.sh                        | 34 +++++++++++++++++++++---
 script/init-db-mariadb.sh         | 44 +++++++++++++++++++++++++++++++
 script/install-opam-packages.sh   |  2 ++
 script/install-system-packages.sh |  5 ++++
 5 files changed, 83 insertions(+), 4 deletions(-)
 create mode 100644 script/init-db-mariadb.sh
 create mode 100644 script/install-opam-packages.sh
 create mode 100644 script/install-system-packages.sh

diff --git a/contrib/aura-clock/package.json b/contrib/aura-clock/package.json
index d2022a2d..d30952b4 100644
--- a/contrib/aura-clock/package.json
+++ b/contrib/aura-clock/package.json
@@ -6,7 +6,7 @@
     "email": "david.trattnig@subsquare.at",
     "url": "https://subsquare.at"
   },
-  "license" : "AGPL-3.0-only",
+  "license": "AGPL-3.0-only",
   "homepage": "https://gitlab.servus.at/aura/meta",
   "repository": {
     "type": "git",
diff --git a/install.sh b/install.sh
index 6d0ebadc..fbbf9a4b 100755
--- a/install.sh
+++ b/install.sh
@@ -15,8 +15,14 @@ if [ $mode == "prod" ]; then
     echo "[Installing AURA ENGINE for Production]"
 fi
 
+echo "Installation System Packages ..."
+./script/install-system-packages.sh
 
-# Production 
+echo "Installation OPAM Packages ..."
+./script/install-opam-packages.sh
+
+
+# Development 
 
 if [ $mode == "dev" ]; then
 
@@ -62,7 +68,29 @@ echo "Create local Logs Folder ..."
 mkdir -p logs
 
 echo "Installing Web Application Packages ..."
-./install-web.sh
+./script/install-web.sh
 
 echo "Installing Python Requirements ..."
-python3.7 $(which pip3) install -r requirements.txt
\ No newline at end of file
+python3.7 $(which pip3) install -r requirements.txt
+
+echo "Setting up database ..."
+echo 
+echo "Which database system do you want to use? (Press '1' or '2')"
+echo "  [1] MariaDB"
+echo "  [2] Other / Manually"
+echo
+
+while true; do
+read -rsn1 input
+if [ "$input" = "1" ]; then
+    echo "Creating DB for MariaDB ..."
+    LOCKFILE_DB=/etc/aura/engine/.install.mariadb.lock
+    sudo sh ./script/init-db-mariadb.sh
+fi
+if [ "$input" = "2" ]; then
+    echo "Manual database setup selected."
+fi
+done
+
+echo 
+echo "+++ Installation of AURA Engine finished! +++"
\ No newline at end of file
diff --git a/script/init-db-mariadb.sh b/script/init-db-mariadb.sh
new file mode 100644
index 00000000..bde0b39f
--- /dev/null
+++ b/script/init-db-mariadb.sh
@@ -0,0 +1,44 @@
+ #!/bin/sh
+
+# Check if databases are already set-up
+if test -f "$LOCKFILE_DB"; then
+  echo "Aura Engine Databases are already existing! Skipping..."
+else
+  # Create random password
+  PASS_ENGINE="$(openssl rand -base64 24)"
+
+  # Create databases and users
+  echo "--- SETTING UP DATABASE AND USERS ---"
+  echo "Please enter the MySQL/MariaDB root password!"
+  stty -echo
+  printf "Password: "
+  read rootpasswd
+  stty echo
+  printf "\n"
+  echo "---"
+  
+  echo "Creating database for Aura Engine..."
+  mysql -uroot -p${rootpasswd} -e "CREATE DATABASE aura_engine CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
+  mysql -uroot -p${rootpasswd} -e "CREATE USER 'aura'@'localhost' IDENTIFIED BY '${PASS_ENGINE}';"
+  mysql -uroot -p${rootpasswd} -e "GRANT ALL PRIVILEGES ON aura_engine.* TO 'aura'@'localhost';"
+  mysql -uroot -p${rootpasswd} -e "FLUSH PRIVILEGES;"
+  echo "Done."
+  
+  echo "Installing MySQL/MariaDB Libraries..."
+  apt-get install mariadb-server libmariadbclient-dev
+  echo "Done."
+  
+  echo
+  echo
+  echo "Please note your database credentials for the next configuration steps:"
+  echo "-----------------------------------------------------------------------"
+  echo " Database: 'aura_engine'"
+  echo " User:     'aura'"
+  echo " Password: '${PASS_ENGINE}'"
+  echo "-----------------------------------------------------------------------"
+  echo
+
+
+  # Create lockfile to avoid accidential re-creation of the database
+  touch $LOCKFILE_DB
+fi
\ No newline at end of file
diff --git a/script/install-opam-packages.sh b/script/install-opam-packages.sh
new file mode 100644
index 00000000..0c6c70c1
--- /dev/null
+++ b/script/install-opam-packages.sh
@@ -0,0 +1,2 @@
+opam depext fdkaac flac opus pulseaudio bjack alsa
+opam install fdkaac flac opus pulseaudio bjack alsa
diff --git a/script/install-system-packages.sh b/script/install-system-packages.sh
new file mode 100644
index 00000000..263d0efe
--- /dev/null
+++ b/script/install-system-packages.sh
@@ -0,0 +1,5 @@
+sudo apt install -y \
+    supervisor \
+    redis-server \
+    libsndfile1 ffmpeg \
+    quelcom \
\ No newline at end of file
-- 
GitLab