diff options
Diffstat (limited to 'scripts/property_utils.sh')
-rwxr-xr-x | scripts/property_utils.sh | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/scripts/property_utils.sh b/scripts/property_utils.sh index 43c7dcb2085..e301bb47165 100755 --- a/scripts/property_utils.sh +++ b/scripts/property_utils.sh @@ -19,24 +19,36 @@ function cnt_lines() { cat $1 | wc -l } -function set_property() { +function write_prop() { PROPERTY=$1 VALUE=$2 FILE=$3 # uncomment below to help debug calls to set_property - # echo "setting property $PROPERTY to value $VALUE in $FILE" + #echo "setting property $PROPERTY to value $VALUE in $FILE" + + echo "" >> $FILE + echo "${PROPERTY}=${VALUE}" >> $FILE +} - # delete line of specified property - LINE_COUNT=$(cnt_lines $FILE) - REGEXP="${1//\./\\\.}\s*=" - sed -i $SED_DISABLE_BACKUP "/${REGEXP}/d" $FILE +function set_property() { + PROPERTY=$1 + VALUE=$2 + FILE=$3 - # 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 + REGEXP="${1//\./\\\.}\s*=" + if [ $(grep $REGEXP $FILE | wc -l) -eq 0 ]; then + write_prop $1 $2 $3 + else + # delete line of specified property + LINE_COUNT=$(cnt_lines $FILE) + 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 + write_prop $1 $2 $3 + fi fi } |