Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/CISOfy/lynis.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Boelen <michael.boelen@cisofy.com>2016-07-31 18:18:36 +0300
committerMichael Boelen <michael.boelen@cisofy.com>2016-07-31 18:18:36 +0300
commit9ae1aa749df9b72ff981e3aea157060edeaaa1eb (patch)
tree5f5938ea8e4bc61559b5206c104b2f4991b9364f
parentff38336e0bc471562fbd105f2d1385b8deb846b3 (diff)
Properly replace setting gathered from profiles
-rw-r--r--include/functions13
1 files changed, 9 insertions, 4 deletions
diff --git a/include/functions b/include/functions
index 1f49fba0..708bbd51 100644
--- a/include/functions
+++ b/include/functions
@@ -133,16 +133,21 @@
AddSetting() {
if [ $# -eq 3 ]; then
+ SETTING="$1"
+ VALUE="$2"
+ DESCRIPTION="$3"
if [ -z "${SETTINGS_FILE}" ]; then
CreateTempFile
SETTINGS_FILE="${TEMP_FILE}"
fi
- FIND=$(egrep "^$1;" ${SETTINGS_FILE})
+ FIND=$(egrep "^${SETTING};" ${SETTINGS_FILE})
if [ -z "${FIND}" ]; then
- echo "$1;$2;$3;" >> ${SETTINGS_FILE}
+ echo "${SETTING};${VALUE};${DESCRIPTION};" >> ${SETTINGS_FILE}
else
- Debug "Option $1 was already configured, overwriting previous value in ${SETTINGS_FILE}"
- sed -i -e "s/$1;.*$/$1;$2;$3;/" ${SETTINGS_FILE}
+ Debug "Setting '${SETTING}' was already configured, overwriting previous line '${FIND}' in ${SETTINGS_FILE} with value '${VALUE}'"
+ # Delete line first, then add new value (inline search and replace is messy)
+ sed -i -e '/^'"${SETTING}"';/d' ${SETTINGS_FILE}
+ echo "${SETTING};${VALUE};${DESCRIPTION};" >> ${SETTINGS_FILE}
fi
else
echo "Error: incorrect call to AddSetting. Needs 3 arguments."