You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

property_utils.sh 880B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/bin/bash
  2. ###############################
  3. # exposes library functions to modify properties in a property
  4. #
  5. # TODO function append_property
  6. #
  7. ###############################
  8. set -euo pipefail
  9. if [[ "$OSTYPE" == "darwin"* ]]; then
  10. SED_DISABLE_BACKUP=" ''"
  11. else
  12. SED_DISABLE_BACKUP=""
  13. fi
  14. function cnt_lines() {
  15. FILE=$1
  16. cat $1 | wc -l
  17. }
  18. function set_property() {
  19. PROPERTY=$1
  20. VALUE=$2
  21. FILE=$3
  22. # uncomment below to help debug calls to set_property
  23. # echo "setting property $PROPERTY to value $VALUE in $FILE"
  24. # delete line of specified property
  25. LINE_COUNT=$(cnt_lines $FILE)
  26. REGEXP="${1//\./\\\.}\s*="
  27. sed -i $SED_DISABLE_BACKUP "/${REGEXP}/d" $FILE
  28. # add property if at least one line deleted
  29. NEW_LINE_COUNT=$(cnt_lines $FILE)
  30. if [ $LINE_COUNT -gt $NEW_LINE_COUNT ]; then
  31. echo "" >> $FILE
  32. echo "${PROPERTY}=${VALUE}" >> $FILE
  33. fi
  34. }