Skip to content

Commit

Permalink
🐛 Escape special chars for replace
Browse files Browse the repository at this point in the history
Signed-off-by: mathieu.brunot <[email protected]>
  • Loading branch information
madmath03 authored and mriedmann committed Sep 5, 2020
1 parent abfa5d5 commit 9c35b5c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
20 changes: 12 additions & 8 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ wait_for_db() {
done
}

escape_for_replace() {
printf '%s\n' "${1}" | sed -e 's/[\/&]/\\&/g'
}

echo "=="
if [ -f "/var/www/localhost/htdocs/protected/config/dynamic.php" ]; then
echo "Existing installation found!"
Expand Down Expand Up @@ -99,14 +103,14 @@ else
fi

echo "Config preprocessing before install ..."
sed -i \
-e "s/getenv('HUMHUB_REDIS_HOSTNAME')/'${HUMHUB_REDIS_HOSTNAME}'/g" \
-e "s/getenv('HUMHUB_REDIS_PORT')/${HUMHUB_REDIS_PORT}/g" \
-e "s/getenv('HUMHUB_REDIS_PASSWORD')/'${HUMHUB_REDIS_PASSWORD}'/g" \
-e "s/getenv('HUMHUB_CACHE_CLASS')/'${HUMHUB_CACHE_CLASS}'/g" \
-e "s/getenv('HUMHUB_QUEUE_CLASS')/'${HUMHUB_QUEUE_CLASS}'/g" \
-e "s/getenv('HUMHUB_PUSH_URL')/'${HUMHUB_PUSH_URL}'/g" \
-e "s/getenv('HUMHUB_PUSH_JWT_TOKEN')/'${HUMHUB_PUSH_JWT_TOKEN}'/g" \
sed \
"s|getenv('HUMHUB_REDIS_HOSTNAME')|'$(escape_for_replace ${HUMHUB_REDIS_HOSTNAME} )'|g;
s|getenv('HUMHUB_REDIS_PORT')|$(escape_for_replace ${HUMHUB_REDIS_PORT} )|g;
s|getenv('HUMHUB_REDIS_PASSWORD')|'$(escape_for_replace ${HUMHUB_REDIS_PASSWORD} )'|g;
s|getenv('HUMHUB_CACHE_CLASS')|'$(escape_for_replace ${HUMHUB_CACHE_CLASS} )'|g;
s|getenv('HUMHUB_QUEUE_CLASS')|'$(escape_for_replace ${HUMHUB_QUEUE_CLASS} )'|g;
s|getenv('HUMHUB_PUSH_URL')|'$(escape_for_replace ${HUMHUB_PUSH_URL} )'|g;
s|getenv('HUMHUB_PUSH_JWT_TOKEN')|'$(escape_for_replace ${HUMHUB_PUSH_JWT_TOKEN} )'|g" \
/var/www/localhost/htdocs/protected/config/common.php

if [ "$AUTOINSTALL" != "false" ]; then
Expand Down
2 changes: 1 addition & 1 deletion humhub/protected/config/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
$common['components']['redis'] = [
'class' => 'yii\redis\Connection',
'hostname' => getenv('HUMHUB_REDIS_HOSTNAME'),
'port' => getenv('HUMHUB_REDIS_PORT') ? getenv('HUMHUB_REDIS_PORT') : 6379,
'port' => !empty(getenv('HUMHUB_REDIS_PORT')) ? getenv('HUMHUB_REDIS_PORT') : 6379,
'database' => 0,
];
if (!empty(getenv('HUMHUB_REDIS_PASSWORD'))) {
Expand Down

0 comments on commit 9c35b5c

Please sign in to comment.