From c31e0667170091488cfdaf1f4b7c576546832e11 Mon Sep 17 00:00:00 2001
From: Sébastien Lesaint <sebastien.lesaint@sonarsource.com>
Date: Mon, 3 Aug 2015 15:05:20 +0200
Subject: [SCRIPTS] add support for patches to start.sh

use seperate start and stop to avoid unpredictable errors when applying patches on a live SQ instance
---
 scripts/property_utils.sh | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)
 create mode 100755 scripts/property_utils.sh

(limited to 'scripts/property_utils.sh')

diff --git a/scripts/property_utils.sh b/scripts/property_utils.sh
new file mode 100755
index 00000000000..43c7dcb2085
--- /dev/null
+++ b/scripts/property_utils.sh
@@ -0,0 +1,43 @@
+#!/bin/bash
+###############################
+# exposes library functions to modify properties in a property 
+#
+# TODO function append_property
+#
+###############################
+
+set -euo pipefail
+
+if [[ "$OSTYPE" == "darwin"* ]]; then
+  SED_DISABLE_BACKUP=" ''"
+else
+  SED_DISABLE_BACKUP=""
+fi
+
+function cnt_lines() {
+  FILE=$1
+  cat $1 | wc -l
+}
+
+function set_property() {
+  PROPERTY=$1
+  VALUE=$2
+  FILE=$3
+
+  # uncomment below to help debug calls to set_property
+  # echo "setting property $PROPERTY to value $VALUE in $FILE"
+
+  # delete line of specified property
+  LINE_COUNT=$(cnt_lines $FILE)
+  REGEXP="${1//\./\\\.}\s*="
+  sed -i $SED_DISABLE_BACKUP "/${REGEXP}/d" $FILE
+
+  # add property if at least one line deleted
+  NEW_LINE_COUNT=$(cnt_lines $FILE)
+  if [ $LINE_COUNT -gt $NEW_LINE_COUNT ]; then
+    echo "" >> $FILE
+    echo "${PROPERTY}=${VALUE}" >> $FILE 
+  fi
+}
+
+
-- 
cgit v1.2.3