[CLAMP,COMMON] Escape special chars in mysql passwords
[oom.git] / kubernetes / clamp / charts / mariadb / resources / config / init / docker-entrypoint.sh
index 6c69694..71f32e2 100755 (executable)
@@ -18,6 +18,11 @@ for arg; do
        esac
 done
 
+prepare_password()
+{
+       echo "$1" | sed -e "s/'/\\\\'/g; s/\"/\\\\\"/g"
+}
+
 # usage: file_env VAR [DEFAULT]
 #    ie: file_env 'XYZ_DB_PASSWORD' 'example'
 # (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of
@@ -36,7 +41,7 @@ file_env() {
        elif [ "${!fileVar:-}" ]; then
                val="$(< "${!fileVar}")"
        fi
-       val=`echo -n $val | sed -e "s/'/''/g"`
+       val=`prepare_password $val`
        export "$var"="$val"
        unset "$fileVar"
 }