From d36a79d5672f92e05f45bfa33fae1ea091f0f2a6 Mon Sep 17 00:00:00 2001
From: pierreozoux <pierre@ozoux.net>
Date: Wed, 18 Feb 2015 17:26:15 +0000
Subject: [PATCH] Adds start to provision script, closes #23

---
 scripts/provision.sh | 25 ++++++++++++++++++++++---
 tests/test.sh        |  6 +-----
 2 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/scripts/provision.sh b/scripts/provision.sh
index 9d7c216..f8c37e3 100755
--- a/scripts/provision.sh
+++ b/scripts/provision.sh
@@ -6,6 +6,7 @@
 #  - Generates the TLS certificate associated
 #  - Configures the DNS
 #  - Configures the mail forwarding
+#  - Starts the application
 #
 # Version 0.0.2
 #
@@ -31,10 +32,11 @@ read -r -d '' usage <<-'EOF'
   -e   [arg] Email of the user of the application. Required.
   -u   [arg] URL to process. Required.
   -f   [arg] Certificate file to use.
-  -g         Generate the necessary certificate.
-  -b         Buy the associated domain name.
-  -c         Configure DNS on Namecheap.
+  -g         Generates the necessary certificate.
+  -b         Buys the associated domain name.
+  -c         Configures DNS on Namecheap.
   -d         Enables debug mode
+  -s         Starts the application
   -h         This page
 EOF
 
@@ -248,6 +250,21 @@ function configure_dns () {
 
 }
 
+function start_application () {
+  case "${arg_a}" in
+  "static" )
+    service_file="static"
+    ;;
+  * )
+    service_file="lamp"
+    ;;
+  esac
+
+  # Enable and start application (Sorry Systemd)
+  systemctl enable ${service_file}@${arg_u}
+  systemctl start ${service_file}@${arg_u}
+}
+
 function _fmt ()      {
   local color_ok="\x1b[32m"
   local color_bad="\x1b[31m"
@@ -382,5 +399,7 @@ scaffold
 [ ${arg_g} -eq 1 ] && generate_certificate
 [ ! -z "${arg_f}" ] && provision_certificate
 [ ${arg_c} -eq 1 ] && configure_dns
+[ ${arg_s} -eq 1 ] && start_application
+
 
 exit 0
diff --git a/tests/test.sh b/tests/test.sh
index 6700810..dbb7451 100755
--- a/tests/test.sh
+++ b/tests/test.sh
@@ -3,15 +3,11 @@
 image=$1
 
 # prepare data
-/data/indiehosters/scripts/provision.sh -e test@test.org -a $image -u $image.test -f /data/indiehosters/tests/unsecure-certs/indiehosters.dev.pem
+/data/indiehosters/scripts/provision.sh -s -e test@test.org -a $image -u $image.test -f /data/indiehosters/tests/unsecure-certs/indiehosters.dev.pem
 
 if [ "$image" == "static" ]; then
-  systemctl start $image@$image.test
-  systemctl enable $image@$image.test
   sleep 30
 else
-  systemctl start lamp@$image.test
-  systemctl enable lamp@$image.test
   sleep 60
 fi
 
-- 
GitLab