[POLICY-145] sed failed expanding special chars 55/6755/1
authorJorge Hernandez <jh1730@att.com>
Fri, 4 Aug 2017 21:26:24 +0000 (16:26 -0500)
committerJorge Hernandez <jh1730@att.com>
Fri, 4 Aug 2017 21:26:24 +0000 (16:26 -0500)
The install script fails when expanding configuration variables
with special characters, for example the delimiter.

This fix' scope is for the replacement string escaping.

Change-Id: Icfe8d89b46c7720bf5effaa2f3add6a19e2af2d2
Signed-off-by: Jorge Hernandez <jh1730@att.com>
policy-drools/docker-install.sh

index cedb212..aaa3d10 100644 (file)
@@ -144,7 +144,7 @@ function configure_component() {
                set -x
        fi
 
-       local CONF_FILE COMPONENT_ROOT_DIR name value
+       local CONF_FILE COMPONENT_ROOT_DIR SED_LINE SED_FILES name value
                
        CONF_FILE=$1
        COMPONENT_ROOT_DIR=$2
@@ -157,16 +157,15 @@ function configure_component() {
        SED_LINE+=" -e 's!\${{JAVA_HOME}}!${JAVA_HOME}!g' "
                
        while read line || [ -n "${line}" ]; do
-        if [[ -n $line ]] && [[ $line != *#* ]]; then
+        if [[ -n ${line} ]] && [[ ${line:0:1} != \# ]]; then
                name=$(echo "${line%%=*}")
                value=$(echo "${line#*=}")
                # escape ampersand so that sed does not replace it with the search string
-            value=${value//&/\\&}
+               value=$(echo "${value}" | sed -e 's/[\/&]/\\&/g')
                if [[ -z ${name} ]] || [[ -z ${value} ]]; then
                        echo "WARNING: ${line} missing name or value"
                fi
-               SED_LINE+=" -e 's!\${{${name}}}!${value}!g' "
-               
+               SED_LINE+=" -e 's/\${{${name}}}/${value}/g' "
         fi
        done < "$CONF_FILE"