mirror of
https://github.com/SonarSource/sonarqube.git
synced 2024-09-08 13:46:05 +02:00
6cee9fdcad
This reverts commit b66e224d79
.
if FILE variable contains bash variables (such as $HOME) they are not resolved and script fails (because of 'set -euo pipefail')
56 lines
1.1 KiB
Bash
Executable File
56 lines
1.1 KiB
Bash
Executable File
#!/bin/bash
|
|
###############################
|
|
# exposes library functions to modify properties in a property
|
|
#
|
|
# TODO function append_property
|
|
#
|
|
###############################
|
|
|
|
set -euo pipefail
|
|
|
|
function cnt_lines() {
|
|
local FILE=$1
|
|
cat $FILE | wc -l
|
|
}
|
|
|
|
function write_prop() {
|
|
local PROPERTY=$1
|
|
local VALUE=$2
|
|
local FILE=$3
|
|
|
|
# uncomment below to help debug calls to set_property
|
|
#echo "setting property $PROPERTY to value $VALUE in $FILE"
|
|
|
|
echo "" >> $FILE
|
|
echo "${PROPERTY}=${VALUE}" >> $FILE
|
|
}
|
|
|
|
function set_property() {
|
|
local PROPERTY=$1
|
|
local VALUE=$2
|
|
local FILE=$3
|
|
|
|
local REGEXP="${PROPERTY//\./\\.}\\s*="
|
|
|
|
if grep -q "$REGEXP" "$FILE"; then
|
|
# delete line of specified property
|
|
LINE_COUNT=$(cnt_lines $FILE)
|
|
|
|
if [[ "$OSTYPE" == "darwin"* ]]; then
|
|
sed -i '' /${REGEXP}/d "$FILE"
|
|
else
|
|
sed -i /${REGEXP}/d "$FILE"
|
|
fi
|
|
|
|
# add property if at least one line deleted
|
|
local NEW_LINE_COUNT=$(cnt_lines $FILE)
|
|
|
|
if [[ $LINE_COUNT -gt $NEW_LINE_COUNT ]]; then
|
|
write_prop $PROPERTY $VALUE $FILE
|
|
fi
|
|
|
|
else
|
|
write_prop $PROPERTY $VALUE $FILE
|
|
fi
|
|
}
|