From ad5fcbc11d68d9aaadc5ef3027eead0d57c2e304 Mon Sep 17 00:00:00 2001
From: Armin Co <armin.co@hs-bochum.de>
Date: Sun, 25 Oct 2020 19:45:09 +0100
Subject: [PATCH] Refactoring configuration.

---
 compose_files_conf.sh      | 28 -------------
 config.sh                  | 57 ++++++++++++++++++++++++++
 configure_once.sh          | 82 ++++++++------------------------------
 tools/start_containers.sh  |  4 +-
 tools/stop_containers.sh   |  4 +-
 tools/update_containers.sh | 16 +++++---
 6 files changed, 86 insertions(+), 105 deletions(-)
 delete mode 100755 compose_files_conf.sh
 create mode 100755 config.sh

diff --git a/compose_files_conf.sh b/compose_files_conf.sh
deleted file mode 100755
index 4fabc7a..0000000
--- a/compose_files_conf.sh
+++ /dev/null
@@ -1,28 +0,0 @@
-#!/bin/bash
-
-# Get the path to all docker-compose files
-# with the "-f" flag.
-
-# Comment the services out that you do not want to use.
-
-
-# Variable that holds all docker-compose files.
-# This is the main compose file which includes letsencrypt
-# for your auto generated certificates. Don not remove!
-docker_compose_files=" -f docker-compose.base.yml "
-
-# noVNC - Screen sharing with VNC
-# docker_compose_files+=" -f ./novnc/docker-compose.yml "
-
-# letsencrypt
-docker_compose_files+=" -f letsencrypt-webserver/docker-compose.yml "
-
-# jitsi
-docker_compose_files+=" -f jitsi/docker-compose.yml "
-
-# mumble
-#docker_compose_files+=" -f ./build-mumble-web/docker-compose.production.yml"
-
-
-# "return" the string
-echo "$docker_compose_files"
\ No newline at end of file
diff --git a/config.sh b/config.sh
new file mode 100755
index 0000000..7098ee9
--- /dev/null
+++ b/config.sh
@@ -0,0 +1,57 @@
+#!/bin/bash
+
+# Get the path to all docker-compose files
+# with the "-f" flag.
+
+## YOUR SETTINGS
+## Configure domains and letsencrypt
+#
+DOMAIN=armin-co.de
+SUB_DOMAINS=""
+MAIL=test@armin-co.de
+
+USE_JITSI="true"
+USE_NO_VNC="false"
+USE_MUMBLE="false"
+
+# Git
+GIT_URL="https://gitlab.cvh-server.de/aco/"
+
+
+# Variable that holds all docker-compose files.
+# This is the main compose file. Don not remove!
+# Required for unified a unified path layout.
+base_compose_file=" -f docker-compose.base.yml "
+DOCKER_COMPOSE_FILES=$base_compose_file
+
+# Letsencrypt
+letsencrypt_compose_file=" -f letsencrypt-webserver/docker-compose.yml "
+DOCKER_COMPOSE_FILES+=$letsencrypt_compose_file
+LETSENCRYPT_DIR=letsencrypt-webserver
+LETSENCRYPT_URL="$GIT_URL$LETSENCRYPT_DIR".git
+
+# Jitsi
+JITSI_DIR=jitsi-auto-config
+JITSI_URL="$GIT_URL$JITSI_DIR".git
+if [$USE_JITSI = "true"]; then
+jitsi_compose_file=" -f jitsi/docker-compose.yml "
+DOCKER_COMPOSE_FILES+=$jitsi_compose_file
+SUB_DOMAINS+="jitsi,"
+fi
+
+# noVNC - Screen sharing with VNC
+NOVNC_DIR=novnc
+NOVNC_URL="$GIT_URL$NOVNC_DIR".git
+if [$USE_NO_VNC = "true"]; then
+novnc_compose_file=" -f ./novnc/docker-compose.yml "
+DOCKER_COMPOSE_FILES+=$novnc_compose_file
+fi
+
+# Mumble
+MUMBLE_DIR=build-mumble-web
+MUMBLE_URL=https://github.com/Johni0702/mumble-web.git
+if [$USE_MUMBLE = "true"]; then
+mumble_compose_file=" -f ./build-mumble-web/docker-compose.production.yml"
+DOCKER_COMPOSE_FILES+=$mumble_compose_file
+SUB_DOMAINS+="mumble-web"
+fi
\ No newline at end of file
diff --git a/configure_once.sh b/configure_once.sh
index 6aedf93..5ca0085 100755
--- a/configure_once.sh
+++ b/configure_once.sh
@@ -1,77 +1,33 @@
 #!/bin/bash
 
-
-## YOUR SETTINGS
-## Configure domains and letsencrypt
-#
-domain=armin-co.de
-sub_domains=mumble,mumble-web,jitsi
-mail=test@armin-co.de
-
-
-
-# git
-git_url="https://gitlab.cvh-server.de/aco/"
-
-## Mumble
-#
-mumble_dir=build-mumble-web
-mumble_url="$git_url$mumble_dir".git
-
-## Jitsi
-#
-jitsi_dir=jitsi-auto-config
-jitsi_url="$git_url$jitsi_dir".git
-
-
-## letsencrypt
-#
-le_dir=letsencrypt-webserver
-le_url="$git_url$le_dir".git
-
-## noVNC
-#
-novnc_dir=novnc
-novnc_url="$git_url$novnc_dir".git
-
-
-# Do not request new certificates while developing
-dbg_delete_letsencrypt=false
-
+source config.sh
 
 # Remove all existing repositories
 # and configurations.
-function remove_all() {
+function remove_all_configs() {
     echo "Removing all previous configs..."
     git clean -fd
     git pull
-    rm -rf $mumble_dir $jitsi_dir $novnc_dir
-
-    if [$dbg_delete_letsencrypt = "true"]; then
-        rm -rf $le_dir
-    fi
-
+    rm -rf $MUMBLE_DIR $JITSI_DIR $NOVNC_DIR
     echo "Removed all repositories."
 }
 
-
 # Clone repositories
 function clone_repositories() {
-    git clone $mumble_url
-    git clone $jitsi_url
-    git clone $le_url
-    git clone $novnc_url
+    git clone $LETSENCRYPT_URL
+    git clone $JITSI_URL
+    git clone $NOVNC_URL
+    git clone $MUMBLE_URL
+    wait
 }
 
-
-
 function configure_letsencrypt() {
     echo ""
     echo "Setting your letsencrypt domain settings."
     echo ""
-    le_compose=$le_dir/docker-compose.yml
+    le_compose=$LETSENCRYPT_DIR/docker-compose.yml
     # Adds your domain to docker-compose
-    sed -i "s/your-domain.com/$domain/" $le_compose
+    sed -i "s/your-domain.com/$DOMAIN/" $le_compose
     # Adds the list of subdomains to use to docker-compose
     sed -i "s/your_subdomains/$sub_domains/" $le_compose
     # Add E-Mail address that will be used to notify you
@@ -79,10 +35,10 @@ function configure_letsencrypt() {
     sed -i "s/your_email/$mail/" $le_compose
     
     # For using not only your subdomains uncomment the following line.
-    # sed -i "s/- ONLY_SUBDOMAINS=true/- ONLY_SUBDOMAINS=false/" $le_dir
+    # sed -i "s/- ONLY_SUBDOMAINS=true/- ONLY_SUBDOMAINS=false/" $LETSENCRYPT_DIR
 
     # start once to generate directories and certificates
-    docker-compose -f $le_compose up -d && docker logs reverse-proxy && docker-compose -f $le_compose down
+    docker-compose $base_compose_file $letsencrypt_compose_file up -d && docker logs reverse_proxy && docker-compose $base_compose_file $letsencrypt_compose_file down
     echo ""
     echo "Done configuring LetsEncrypt and generating certificates."
 }
@@ -91,11 +47,11 @@ function configure_letsencrypt() {
 ## Configure Murmur (mumble server) and mumble-web
 #
 function configure_mumble() {
-    cd build-mumble-web
+    cd $MUMBLE_DIR
     git clone https://github.com/Johni0702/mumble-web.git
     cd ..
     mkdir murmur
-    cp $mumble_dir/murmur/mumble-server.ini murmur/mumble-server.ini
+    cp $MUMBLE_DIR/murmur/mumble-server.ini murmur/mumble-server.ini
     touch murmur/mumble-server.log
 }
 
@@ -107,18 +63,12 @@ echo "Starting configuration with cleaning up and pulling again."
 echo ""
 
 ./tools/stop_containers.sh
-remove_all
+remove_all_configs
 clone_repositories
 
-# configure letsencrypt
 configure_letsencrypt
-
-# configure mumble
 configure_mumble
 
-
 ./tools/stop_containers.sh
 
-## pull and update all images
-#
-# ./tools/update_containers.sh
\ No newline at end of file
+./tools/update_containers.sh
\ No newline at end of file
diff --git a/tools/start_containers.sh b/tools/start_containers.sh
index 6463d3a..214073c 100755
--- a/tools/start_containers.sh
+++ b/tools/start_containers.sh
@@ -1,7 +1,5 @@
 #!/bin/bash
 
 # start/restart all containers
-# compose_files=$(./compose_files_conf.sh)
-#
-source compose_files_conf.sh
+source config.sh
 docker-compose $docker_compose_files up -d
\ No newline at end of file
diff --git a/tools/stop_containers.sh b/tools/stop_containers.sh
index 3d319f1..e9dc112 100755
--- a/tools/stop_containers.sh
+++ b/tools/stop_containers.sh
@@ -1,6 +1,4 @@
 #!/bin/bash
 
-# compose_files=$(./compose_files_conf.sh)
-
-source compose_files_conf.sh
+source config.sh
 docker-compose $docker_compose_files down
\ No newline at end of file
diff --git a/tools/update_containers.sh b/tools/update_containers.sh
index c50731e..c61051d 100755
--- a/tools/update_containers.sh
+++ b/tools/update_containers.sh
@@ -2,17 +2,23 @@
 
 # Update and restart containers 
 
-source compose_files_conf.sh
-# compose_files=$(./compose_files_conf.sh)
+source config.sh
 
 echo "Pulling images"
 echo ""
+
 # pull updated images 
 docker-compose $docker_compose_files pull
 
 echo "Building images"
 echo ""
-# build new images if neccessary
-docker-compose -f build-mumble-web/docker-compose.production.yml build
-docker-compose -f novnc/docker-compose.yml build 
+
+# Build new images if neccessary
+if [$USE_MUMBLE = "true"]; then
+    docker-compose -f $mumble_compose_file build
+fi
+
+if [$USE_NOVNC = "true"]; then
+    docker-compose -f $novnc_compose_file build 
+fi
 
-- 
GitLab