aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/property_utils.sh
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2015-08-03 15:05:20 +0200
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2015-08-06 14:18:35 +0200
commitc31e0667170091488cfdaf1f4b7c576546832e11 (patch)
tree30ba9c4e85c44e32885f8eb85dfa4b0d692e2b23 /scripts/property_utils.sh
parent0ddae3998e34e24c5877b784332085a81a1ebe7e (diff)
downloadsonarqube-c31e0667170091488cfdaf1f4b7c576546832e11.tar.gz
sonarqube-c31e0667170091488cfdaf1f4b7c576546832e11.zip
[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
Diffstat (limited to 'scripts/property_utils.sh')
-rwxr-xr-xscripts/property_utils.sh43
1 files changed, 43 insertions, 0 deletions
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
+}
+
+