From 4f53c9da7394f54264764acba3f29aad1d9a8ec8 Mon Sep 17 00:00:00 2001
From: Tomas Plesnik <plesnik@ics.muni.cz>
Date: Wed, 12 Mar 2014 17:02:34 +0100
Subject: [PATCH] pridana funkce pro update warden-server adresare a update
 konfiguracnich souboru

---
 src/warden-server/sh/update.sh | 51 ++++++++++++++++++++++++++++------
 1 file changed, 43 insertions(+), 8 deletions(-)

diff --git a/src/warden-server/sh/update.sh b/src/warden-server/sh/update.sh
index da38de6..5dd3586 100755
--- a/src/warden-server/sh/update.sh
+++ b/src/warden-server/sh/update.sh
@@ -16,6 +16,7 @@ usage()
 {
 	echo "Usage: ${0##*/} -d <directory> [-hV]"
 	echo "-d <directory>            destination directory of Warden server"
+	echo "-s <directory>            directory for symlinks to Warden server control scripts (optional)"
 	echo "-h                        print this help"
 	echo "-V                        print script version number and exit"
 	echo
@@ -144,7 +145,16 @@ backup()
 updateWardenDir()
 { 
 	echo -n "Updating Warden server ... "
+        for file in $(<"$manifest")
+        do
+		cp "$file" "${basedir}/$file" 2> "$err" || errClean
+        done
+	echo "OK"
+}
+
 
+getConfValue() {
+	perl -e "require \"$1\"; print \"\$$2\";"
 }
 
 
@@ -210,9 +220,9 @@ etc="${basedir}/etc"
 server_conf="${etc}/warden-server.conf"
 apache_conf="${etc}/warden-apache.conf"
 watchdog_conf="${etc}/warden-watchdog.conf"
-server_conf_tmpl="${dirname}/etc/warden-server.conf.tmpl"
-apache_conf_tmpl="${dirname}/etc/warden-apache.conf.tmpl"
-watchdog_conf_tmpl="${dirname}/etc/warden-watchdog.conf.tmpl"
+server_conf_tmpl="${dirname}/etc/warden-server.conf.tmpl.update"
+apache_conf_tmpl="${dirname}/etc/warden-apache.conf.tmpl.update"
+watchdog_conf_tmpl="${dirname}/etc/warden-watchdog.conf.tmpl.update"
 package_version=$(<"${dirname}/etc/package_version")
 manifest="${dirname}/doc/MANIFEST"
 
@@ -241,15 +251,35 @@ backup
 # make warden server directory
 updateWardenDir
 
-# create server configuration file
+# update server configuration file
 echo -n "Updating Warden server configuration file ... "
+syslog=$(getConfValue "$server_conf" SYSLOG)
+syslog_verbose=$(getConfValue "$server_conf" SYSLOG_VERBOSE)
+syslog_facility=$(getConfValue "$server_conf" SYSLOG_FACILITY)
+db_name=$(getConfValue "$server_conf" DB_NAME)
+db_user=$(getConfValue "$server_conf" DB_USER)
+db_pass=$(getConfValue "$server_conf" DB_PASS)
+db_host=$(getConfValue "$server_conf" DB_HOST)
+max_events_limit=$(getConfValue "$server_conf" MAX_EVENTS_LIMIT)
 doTemplate \
-        _BASEDIR_       "$basedir" \
+        _BASEDIR_		"$basedir" \
+        _SYSLOG_		"$syslog" \
+        _SYSLOG_VERBOSE_	"$syslog_verbose" \
+        _SYSLOG_FACILITY_	"$syslog_facility" \
+        _DB_NAME_		"$db_name" \
+        _DB_USER_		"$db_user" \
+        _DB_PASS_		"$db_pass" \
+        _DB_HOST_		"$db_host" \
+        _MAX_EVENTS_LIMIT_	"$max_events_limit" \
         < $server_conf_tmpl \
         > $server_conf && echo "OK" || errClean
 
-# create Apache configuration file
+# update Apache configuration file
 echo -n "Updating Apache configuration file ... "
+cert_file=$(getConfValue "$apache_conf" CERT_FILE)
+key_file=$(getConfValue "$apache_conf" KEY_FILE)
+ca_file=$(getConfValue "$apache_conf" CA_FILE)
+lib=$(getConfValue "$apache_conf" LIB)
 doTemplate \
         _CERT_FILE_     "$cert_file" \
         _KEY_FILE_      "$key_file" \
@@ -258,10 +288,15 @@ doTemplate \
         < $apache_conf_tmpl \
         > $apache_conf && echo "OK" || errClean
 
-# create wardenWatchdog configuration file
+# update wardenWatchdog configuration file
 echo -n "Updating Warden Watchdog configuration file ... "
+hostname=$(getConfValue "$watchdog_conf" HOSTNAME)
+email_subject=$(getConfValue "$watchdog_conf" EMAIL_SUBJECT)
+email_server_conf=$(getConfValue "$watchdog_conf" EMAIL_SERVER_CONF)
 doTemplate \
-        _HOSTNAME_      "$hostname" \
+        _HOSTNAME_		"$hostname" \
+        _EMAIL_SUBJECT_		"$email_subject" \
+        _EMAIL_SERVER_CONF_	"$email_server_conf" \
         < $watchdog_conf_tmpl \
         > $watchdog_conf && echo "OK" || errClean
 
-- 
GitLab