From 9cf173b16b7b0382497c061e2dbee07f91bc712b Mon Sep 17 00:00:00 2001 From: Tho Ho Date: Fri, 23 Sep 2022 13:56:16 +0800 Subject: [PATCH 01/12] Extract host and port from DB_HOST --- root/etc/cont-init.d/50-config | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/root/etc/cont-init.d/50-config b/root/etc/cont-init.d/50-config index b3935db..ad9bee1 100644 --- a/root/etc/cont-init.d/50-config +++ b/root/etc/cont-init.d/50-config @@ -96,11 +96,21 @@ if ! grep -qx '^post_max_size.*$' /config/php/php-local.ini; then echo 'post_max_size = 100M' >> /config/php/php-local.ini fi +# extract actual host and port from DB_HOST endpoint format, not support IPv6 +# DB_HOST enpoint 'domainIp:port' or 'domainIp' +# DB_HOST_ONLY drop ':port' portion +# DB_PORT_ONLY drop host_only portion, remains '' or ':port' +# DB_PORT_ONLY drop ':' if any, remain '' or 'port' +# ${DB_PORT_ONLY:-3306} use default 3306 if missing +DB_HOST_ONLY=${DB_HOST%:*} +DB_PORT_ONLY=${DB_HOST#$DB_HOST_ONLY} +DB_PORT_ONLY=${DB_PORT_ONLY#:} + # check for the mysql endpoint for 30 seconds END=$((SECONDS+30)) -while [ ${SECONDS} -lt ${END} ] && [ -n "${DB_HOST+x}" ]; do - if /usr/bin/nc -z ${DB_HOST} 3306; then - if [ ! -z "$(/usr/bin/nc -w1 ${DB_HOST} 3306)" ]; then +while [ ${SECONDS} -lt ${END} ] && [ -n "${DB_HOST_ONLY+x}" ]; do + if /usr/bin/nc -z ${DB_HOST_ONLY} ${DB_PORT_ONLY:-3306}; then + if [ ! -z "$(/usr/bin/nc -w1 ${DB_HOST_ONLY} ${DB_PORT_ONLY:-3306})" ]; then if [ ! -z "${RUN}" ]; then break fi From 71750e16a3d29996c3db95ff58f7a0ef1343abc5 Mon Sep 17 00:00:00 2001 From: Tho Ho Date: Sun, 9 Oct 2022 02:48:57 +0800 Subject: [PATCH 02/12] Support DB_PORT --- root/etc/cont-init.d/50-config | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/root/etc/cont-init.d/50-config b/root/etc/cont-init.d/50-config index ad9bee1..6c1cfdb 100644 --- a/root/etc/cont-init.d/50-config +++ b/root/etc/cont-init.d/50-config @@ -13,6 +13,12 @@ mkdir -p \ # check for .env and copy default if needed if [[ ! -f "/config/www/.env" ]] || [[ ! -s "/config/www/.env" ]]; then cp /app/www/.env.example /config/www/.env + + if ! grep -Fxq "DB_PORT=3306" /config/www/.env; then + # add line DB_PORT=3306 to /config/www/.env because current /app/www/.env.example dont have it + sed -i "/DB_HOST=localhost/a DB_PORT=3306" /config/www/.env + echo "**** Insert DB_PORT=3306 into /config/www/.env ****" + fi fi # create symlinks @@ -68,6 +74,11 @@ if [ "${DB_USER}" ]; sed -i "s/DB_DATABASE=database_database/DB_DATABASE=${DB_DATABASE}/g" /config/www/.env sed -i "s/DB_USERNAME=database_username/DB_USERNAME=${DB_USER}/g" /config/www/.env sed -i "s/DB_PASSWORD=database_user_password/DB_PASSWORD=${ESCAPED_PASSWORD}/g" /config/www/.env + + if [ "${DB_PORT}" ]; + then + sed -i "s/DB_PORT=3306/DB_PORT=${DB_PORT}/g" /config/www/.env + fi fi # set appurl @@ -101,7 +112,7 @@ fi # DB_HOST_ONLY drop ':port' portion # DB_PORT_ONLY drop host_only portion, remains '' or ':port' # DB_PORT_ONLY drop ':' if any, remain '' or 'port' -# ${DB_PORT_ONLY:-3306} use default 3306 if missing +# ${DB_PORT_ONLY:-${DB_PORT:-3306}} use DB_PORT if no port provided in DB_HOST, use default 3306 if not provide DB_PORT DB_HOST_ONLY=${DB_HOST%:*} DB_PORT_ONLY=${DB_HOST#$DB_HOST_ONLY} DB_PORT_ONLY=${DB_PORT_ONLY#:} @@ -109,8 +120,8 @@ DB_PORT_ONLY=${DB_PORT_ONLY#:} # check for the mysql endpoint for 30 seconds END=$((SECONDS+30)) while [ ${SECONDS} -lt ${END} ] && [ -n "${DB_HOST_ONLY+x}" ]; do - if /usr/bin/nc -z ${DB_HOST_ONLY} ${DB_PORT_ONLY:-3306}; then - if [ ! -z "$(/usr/bin/nc -w1 ${DB_HOST_ONLY} ${DB_PORT_ONLY:-3306})" ]; then + if /usr/bin/nc -z ${DB_HOST_ONLY} ${DB_PORT_ONLY:-${DB_PORT:-3306}}; then + if [ ! -z "$(/usr/bin/nc -w1 ${DB_HOST_ONLY} ${DB_PORT_ONLY:-${DB_PORT:-3306}})" ]; then if [ ! -z "${RUN}" ]; then break fi From 5fa113279266a8ae6ee440956f898016a90af924 Mon Sep 17 00:00:00 2001 From: Tho Ho Date: Mon, 10 Oct 2022 14:30:21 +0800 Subject: [PATCH 03/12] Improve grep and seq matching --- root/etc/cont-init.d/50-config | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/root/etc/cont-init.d/50-config b/root/etc/cont-init.d/50-config index 6c1cfdb..0d21719 100644 --- a/root/etc/cont-init.d/50-config +++ b/root/etc/cont-init.d/50-config @@ -14,9 +14,9 @@ mkdir -p \ if [[ ! -f "/config/www/.env" ]] || [[ ! -s "/config/www/.env" ]]; then cp /app/www/.env.example /config/www/.env - if ! grep -Fxq "DB_PORT=3306" /config/www/.env; then + if ! grep -xq "^DB_PORT=.*" /config/www/.env; then # add line DB_PORT=3306 to /config/www/.env because current /app/www/.env.example dont have it - sed -i "/DB_HOST=localhost/a DB_PORT=3306" /config/www/.env + sed -i "/^DB_HOST=.*/a DB_PORT=3306" /config/www/.env echo "**** Insert DB_PORT=3306 into /config/www/.env ****" fi fi @@ -70,14 +70,13 @@ if [ "${DB_USER}" ]; then echo "Running config - db_user set" ESCAPED_PASSWORD=$(sed -E 's/('\'')/\\\1/g' <<< $DB_PASS) - sed -i "s/DB_HOST=localhost/DB_HOST=${DB_HOST}/g" /config/www/.env - sed -i "s/DB_DATABASE=database_database/DB_DATABASE=${DB_DATABASE}/g" /config/www/.env - sed -i "s/DB_USERNAME=database_username/DB_USERNAME=${DB_USER}/g" /config/www/.env - sed -i "s/DB_PASSWORD=database_user_password/DB_PASSWORD=${ESCAPED_PASSWORD}/g" /config/www/.env - - if [ "${DB_PORT}" ]; - then - sed -i "s/DB_PORT=3306/DB_PORT=${DB_PORT}/g" /config/www/.env + sed -i "s/^DB_HOST=.*/DB_HOST=${DB_HOST}/g" /config/www/.env + sed -i "s/^DB_DATABASE=.*/DB_DATABASE=${DB_DATABASE}/g" /config/www/.env + sed -i "s/^DB_USERNAME=.*/DB_USERNAME=${DB_USER}/g" /config/www/.env + sed -i "s/^DB_PASSWORD=.*/DB_PASSWORD=${ESCAPED_PASSWORD}/g" /config/www/.env + + if [ -n "${DB_PORT}" ]; then + sed -i "s/^DB_PORT=.*/DB_PORT=${DB_PORT}/g" /config/www/.env fi fi From f033396905edbf21fc232a4772685fc9b3a9d73a Mon Sep 17 00:00:00 2001 From: Tho Ho Date: Mon, 10 Oct 2022 14:52:34 +0800 Subject: [PATCH 04/12] Update README support DB_PORT --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 2aa0dc2..36db023 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,7 @@ services: - PGID=1000 - APP_URL= - DB_HOST=bookstack_db + - DB_PORT=3306 - DB_USER=bookstack - DB_PASS= - DB_DATABASE=bookstackapp @@ -137,6 +138,7 @@ docker run -d \ -e PGID=1000 \ -e APP_URL= \ -e DB_HOST= \ + -e DB_PORT= \ -e DB_USER= \ -e DB_PASS= \ -e DB_DATABASE=bookstackapp \ @@ -157,6 +159,7 @@ Container images are configured using parameters passed at runtime (such as thos | `-e PGID=1000` | for GroupID - see below for explanation | | `-e APP_URL=` | for specifying the IP:port or URL your application will be accessed on (ie. `http://192.168.1.1:6875` or `https://bookstack.mydomain.com` | | `-e DB_HOST=` | for specifying the database host | +| `-e DB_PORT=` | for specifying the database port if not default 3306 | | `-e DB_USER=` | for specifying the database user | | `-e DB_PASS=` | for specifying the database password | | `-e DB_DATABASE=bookstackapp` | for specifying the database to be used | From 10f9699fffc95fedaf444b09826fcf1070ca842e Mon Sep 17 00:00:00 2001 From: Tho Ho Date: Mon, 10 Oct 2022 15:48:57 +0800 Subject: [PATCH 05/12] Add DB_HOST= to .env if previous version not have --- root/etc/cont-init.d/50-config | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/root/etc/cont-init.d/50-config b/root/etc/cont-init.d/50-config index 0d21719..e4d3725 100644 --- a/root/etc/cont-init.d/50-config +++ b/root/etc/cont-init.d/50-config @@ -13,12 +13,6 @@ mkdir -p \ # check for .env and copy default if needed if [[ ! -f "/config/www/.env" ]] || [[ ! -s "/config/www/.env" ]]; then cp /app/www/.env.example /config/www/.env - - if ! grep -xq "^DB_PORT=.*" /config/www/.env; then - # add line DB_PORT=3306 to /config/www/.env because current /app/www/.env.example dont have it - sed -i "/^DB_HOST=.*/a DB_PORT=3306" /config/www/.env - echo "**** Insert DB_PORT=3306 into /config/www/.env ****" - fi fi # create symlinks @@ -76,7 +70,13 @@ if [ "${DB_USER}" ]; sed -i "s/^DB_PASSWORD=.*/DB_PASSWORD=${ESCAPED_PASSWORD}/g" /config/www/.env if [ -n "${DB_PORT}" ]; then - sed -i "s/^DB_PORT=.*/DB_PORT=${DB_PORT}/g" /config/www/.env + if ! grep -xq "^DB_PORT=.*" /config/www/.env; then + # add line DB_PORT=3306 to /config/www/.env because current /app/www/.env.example dont have it + sed -i "/^DB_HOST=.*/a DB_PORT=${DB_PORT}" /config/www/.env + echo "**** Insert DB_PORT=${DB_PORT} into /config/www/.env ****" + else + sed -i "s/^DB_PORT=.*/DB_PORT=${DB_PORT}/g" /config/www/.env + fi fi fi From f9bb8bc463c421c16d5b2c5935776f5a02ab1572 Mon Sep 17 00:00:00 2001 From: Tho Ho Date: Mon, 10 Oct 2022 22:59:14 +0800 Subject: [PATCH 06/12] Revert "Update README support DB_PORT" This reverts commit f033396905edbf21fc232a4772685fc9b3a9d73a. --- README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/README.md b/README.md index 36db023..2aa0dc2 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,6 @@ services: - PGID=1000 - APP_URL= - DB_HOST=bookstack_db - - DB_PORT=3306 - DB_USER=bookstack - DB_PASS= - DB_DATABASE=bookstackapp @@ -138,7 +137,6 @@ docker run -d \ -e PGID=1000 \ -e APP_URL= \ -e DB_HOST= \ - -e DB_PORT= \ -e DB_USER= \ -e DB_PASS= \ -e DB_DATABASE=bookstackapp \ @@ -159,7 +157,6 @@ Container images are configured using parameters passed at runtime (such as thos | `-e PGID=1000` | for GroupID - see below for explanation | | `-e APP_URL=` | for specifying the IP:port or URL your application will be accessed on (ie. `http://192.168.1.1:6875` or `https://bookstack.mydomain.com` | | `-e DB_HOST=` | for specifying the database host | -| `-e DB_PORT=` | for specifying the database port if not default 3306 | | `-e DB_USER=` | for specifying the database user | | `-e DB_PASS=` | for specifying the database password | | `-e DB_DATABASE=bookstackapp` | for specifying the database to be used | From 60ac384c42f9a931d896acccc26269d2f7347e57 Mon Sep 17 00:00:00 2001 From: Tho Ho Date: Mon, 10 Oct 2022 22:59:55 +0800 Subject: [PATCH 07/12] Update README support DB_PORT --- readme-vars.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/readme-vars.yml b/readme-vars.yml index 57fc1d5..8a60f65 100644 --- a/readme-vars.yml +++ b/readme-vars.yml @@ -27,6 +27,7 @@ param_usage_include_env: true param_env_vars: - { env_var: "APP_URL", env_value: "", desc: "for specifying the IP:port or URL your application will be accessed on (ie. `http://192.168.1.1:6875` or `https://bookstack.mydomain.com`"} - { env_var: "DB_HOST", env_value: "", desc: "for specifying the database host" } + - { env_var: "DB_PORT", env_value: "", desc: "for specifying the database port if not default 3306" } - { env_var: "DB_USER", env_value: "", desc: "for specifying the database user" } - { env_var: "DB_PASS", env_value: "", desc: "for specifying the database password" } - { env_var: "DB_DATABASE", env_value: "bookstackapp", desc: "for specifying the database to be used" } @@ -50,6 +51,7 @@ custom_compose: | - PGID=1000 - APP_URL= - DB_HOST=bookstack_db + - DB_PORT=3306 - DB_USER=bookstack - DB_PASS= - DB_DATABASE=bookstackapp From 014fb2a376d0178c125efd1fa4d76c3f2fb7c0e2 Mon Sep 17 00:00:00 2001 From: Tho Ho Date: Tue, 11 Oct 2022 16:23:51 +0800 Subject: [PATCH 08/12] fix readme-vars: properly escaped password --- readme-vars.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readme-vars.yml b/readme-vars.yml index fbe9593..ec12284 100644 --- a/readme-vars.yml +++ b/readme-vars.yml @@ -29,8 +29,8 @@ param_env_vars: - { env_var: "DB_HOST", env_value: "", desc: "for specifying the database host" } - { env_var: "DB_PORT", env_value: "", desc: "for specifying the database port if not default 3306" } - { env_var: "DB_USER", env_value: "", desc: "for specifying the database user" } - - { env_var: "DB_PASS", env_value: "", desc: "for specifying the database password" } - - { env_var: "DB_DATABASE", env_value: "bookstackapp", desc: "for specifying the database to be used (non-alphanumeric passwords must be properly escaped.)" } + - { env_var: "DB_PASS", env_value: "", desc: "for specifying the database password (non-alphanumeric passwords must be properly escaped.)" } + - { env_var: "DB_DATABASE", env_value: "bookstackapp", desc: "for specifying the database to be used" } param_usage_include_ports: true param_ports: From 16c3c51494a9195ffdfad3a22c5f8fe56b2b48a8 Mon Sep 17 00:00:00 2001 From: Eric Nemchik Date: Tue, 11 Oct 2022 14:52:42 -0500 Subject: [PATCH 09/12] Rework logic to account for ipv6 (#1) Also, always set host and port --- root/etc/cont-init.d/50-config | 119 +++++++++++++++++---------------- 1 file changed, 62 insertions(+), 57 deletions(-) diff --git a/root/etc/cont-init.d/50-config b/root/etc/cont-init.d/50-config index 3a9ebea..4ae8497 100644 --- a/root/etc/cont-init.d/50-config +++ b/root/etc/cont-init.d/50-config @@ -8,7 +8,7 @@ fi # create directory structure mkdir -p \ - /config/www/{uploads,files,images,themes} + /config/www/{uploads,files,images,themes} # check for .env and copy default if needed if [[ ! -f "/config/www/.env" ]] || [[ ! -s "/config/www/.env" ]]; then @@ -16,22 +16,21 @@ if [[ ! -f "/config/www/.env" ]] || [[ ! -s "/config/www/.env" ]]; then fi # create symlinks -symlinks=( \ -/app/www/themes \ -/app/www/storage/uploads/files \ -/app/www/storage/uploads/images \ -/app/www/public/uploads \ -/app/www/.env \ -/app/www/storage/logs/laravel.log +symlinks=( + /app/www/themes + /app/www/storage/uploads/files + /app/www/storage/uploads/images + /app/www/public/uploads + /app/www/.env + /app/www/storage/logs/laravel.log ) -for i in "${symlinks[@]}" -do - if [[ -e "$i" && ! -L "$i" ]]; then - rm -rf "$i" +for i in "${symlinks[@]}"; do + if [[ -e "${i}" && ! -L "${i}" ]]; then + rm -rf "${i}" fi - if [[ ! -L "$i" ]]; then - ln -s /config/www/"$(basename "$i")" "$i" + if [[ ! -L "${i}" ]]; then + ln -s /config/www/"$(basename "${i}")" "${i}" fi done @@ -41,42 +40,58 @@ if [ -n "${TEST_RUN}" ]; then fi # Create API key if needed -if [ ! -f "/config/BOOKSTACK_APP_KEY.txt" ]; - then +if [ ! -f "/config/BOOKSTACK_APP_KEY.txt" ]; then echo "Generating BookStack app key for first run" key=$(php /app/www/artisan key:generate --show) - echo $key > /config/BOOKSTACK_APP_KEY.txt - echo "App Key set to $key you can modify the file to update /config/BOOKSTACK_APP_KEY.txt" -elif [ -f "/config/BOOKSTACK_APP_KEY.txt" ]; - then + echo "${key}" >/config/BOOKSTACK_APP_KEY.txt + echo "App Key set to ${key} you can modify the file to update /config/BOOKSTACK_APP_KEY.txt" +elif [ -f "/config/BOOKSTACK_APP_KEY.txt" ]; then echo "App Key found - setting variable for seds" key=$(cat /config/BOOKSTACK_APP_KEY.txt) fi # .env file setup # check for the default app key or if it has been updated -if grep -Fxq "APP_KEY=SomeRandomString" /config/www/.env || \ -! grep -Fxq "APP_KEY=${key}" /config/www/.env; then +if ! grep -Fxq "APP_KEY=${key}" /config/www/.env; then sed -i "s#^APP_KEY=.*#APP_KEY=${key}#" /config/www/.env fi -# check to see if db_user is set, if it is then run seds and if not then leave them -if [ "${DB_USER}" ]; - then - echo "Running config - db_user set" - sed -i "s/^DB_HOST=.*/DB_HOST=${DB_HOST}/g" /config/www/.env - sed -i "s/^DB_DATABASE=.*/DB_DATABASE=${DB_DATABASE}/g" /config/www/.env - sed -i "s/^DB_USERNAME=.*/DB_USERNAME=${DB_USER}/g" /config/www/.env - sed -i "s/^DB_PASSWORD=.*/DB_PASSWORD=${DB_PASS}/g" /config/www/.env - - if [ -n "${DB_PORT}" ]; then - if ! grep -xq "^DB_PORT=.*" /config/www/.env; then - # add line DB_PORT=3306 to /config/www/.env because current /app/www/.env.example dont have it - sed -i "/^DB_HOST=.*/a DB_PORT=${DB_PORT}" /config/www/.env - echo "**** Insert DB_PORT=${DB_PORT} into /config/www/.env ****" - else - sed -i "s/^DB_PORT=.*/DB_PORT=${DB_PORT}/g" /config/www/.env - fi - fi + +# if DB_HOST contains a port +if echo "${DB_HOST}" | grep -qP '^(?:[0-9.]+|(?:\[[0-9a-fA-F:]+\]))(:[0-9]+)$'; then + DB_HOST_PORT="${DB_HOST}" +fi + +# if DB_HOST_PORT is set +if [[ -n "${DB_HOST_PORT}" ]]; then + # if DB_PORT is set + if [[ -n "${DB_PORT}" ]]; then + echo "DB_PORT is not supported when using DB_HOST with port" + sleep infinity + fi + DB_HOST="${DB_HOST_PORT%:*}" + DB_PORT="${DB_HOST_PORT##*:}" +fi + +# if DB_PORT is not set +if [[ -z "${DB_PORT}" ]]; then + DB_PORT="3306" +fi + +# check to see if DB_HOST is set, if it is then run seds and if not then leave them +if [[ -n "${DB_HOST}" ]]; then + echo "Running config - DB_HOST set" + + if ! grep -xq "^DB_PORT=.*" /config/www/.env; then + # add DB_PORT line to /config/www/.env because current /app/www/.env.example doesn't have it + sed -i "/^DB_HOST=.*/a DB_PORT=${DB_PORT}" /config/www/.env + echo "**** Insert DB_PORT=${DB_PORT} into /config/www/.env ****" + fi + + sed -i "s/^DB_HOST=.*/DB_HOST=${DB_HOST}/g" /config/www/.env + sed -i "s/^DB_PORT=.*/DB_PORT=${DB_PORT}/g" /config/www/.env + sed -i "s/^DB_DATABASE=.*/DB_DATABASE=${DB_DATABASE}/g" /config/www/.env + sed -i "s/^DB_USERNAME=.*/DB_USERNAME=${DB_USER}/g" /config/www/.env + sed -i "s/^DB_PASSWORD=.*/DB_PASSWORD=${DB_PASS}/g" /config/www/.env fi # set appurl @@ -99,28 +114,18 @@ fi ## Bump php upload max filesize and post max size to 100MB by default if ! grep -qx '^upload_max_filesize.*$' /config/php/php-local.ini; then - echo 'upload_max_filesize = 100M' >> /config/php/php-local.ini + echo 'upload_max_filesize = 100M' >>/config/php/php-local.ini fi if ! grep -qx '^post_max_size.*$' /config/php/php-local.ini; then - echo 'post_max_size = 100M' >> /config/php/php-local.ini + echo 'post_max_size = 100M' >>/config/php/php-local.ini fi -# extract actual host and port from DB_HOST endpoint format, not support IPv6 -# DB_HOST enpoint 'domainIp:port' or 'domainIp' -# DB_HOST_ONLY drop ':port' portion -# DB_PORT_ONLY drop host_only portion, remains '' or ':port' -# DB_PORT_ONLY drop ':' if any, remain '' or 'port' -# ${DB_PORT_ONLY:-${DB_PORT:-3306}} use DB_PORT if no port provided in DB_HOST, use default 3306 if not provide DB_PORT -DB_HOST_ONLY=${DB_HOST%:*} -DB_PORT_ONLY=${DB_HOST#$DB_HOST_ONLY} -DB_PORT_ONLY=${DB_PORT_ONLY#:} - # check for the mysql endpoint for 30 seconds -END=$((SECONDS+30)) -while [ ${SECONDS} -lt ${END} ] && [ -n "${DB_HOST_ONLY+x}" ]; do - if /usr/bin/nc -z ${DB_HOST_ONLY} ${DB_PORT_ONLY:-${DB_PORT:-3306}}; then - if [ ! -z "$(/usr/bin/nc -w1 ${DB_HOST_ONLY} ${DB_PORT_ONLY:-${DB_PORT:-3306}})" ]; then - if [ ! -z "${RUN}" ]; then +END=$((SECONDS + 30)) +while [ ${SECONDS} -lt ${END} ] && [ -n "${DB_HOST}" ]; do + if /usr/bin/nc -z "${DB_HOST}" "${DB_PORT}"; then + if [ -n "$(/usr/bin/nc -w1 "${DB_HOST}" "${DB_PORT}")" ]; then + if [ -n "${RUN}" ]; then break fi RUN="RAN" From 3b2550bfe271536d2345b35f2dc88b1a359a7c6d Mon Sep 17 00:00:00 2001 From: Tho Ho Date: Wed, 12 Oct 2022 02:37:19 +0800 Subject: [PATCH 10/12] support ipv4|[ipv6]|domain:port; fix Alpine grep P (cherry picked from commit 1fde0ad70e72c73e8062f4a2d299d2cda9a46dc6) --- root/etc/cont-init.d/50-config | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/root/etc/cont-init.d/50-config b/root/etc/cont-init.d/50-config index 4ae8497..a920392 100644 --- a/root/etc/cont-init.d/50-config +++ b/root/etc/cont-init.d/50-config @@ -56,8 +56,9 @@ if ! grep -Fxq "APP_KEY=${key}" /config/www/.env; then sed -i "s#^APP_KEY=.*#APP_KEY=${key}#" /config/www/.env fi -# if DB_HOST contains a port -if echo "${DB_HOST}" | grep -qP '^(?:[0-9.]+|(?:\[[0-9a-fA-F:]+\]))(:[0-9]+)$'; then +# if DB_HOST contains a port and DB_HOST is not a IPv6 without brackets [..] +# support ipv4:port, [ipv6]:port, and domain:port +if echo "$DB_HOST" | grep -qE ':[0-9]+$' && ! echo "$DB_HOST" | grep -qE '^(:{0,2}[a-fA-F0-9]{1,4})+$'; then DB_HOST_PORT="${DB_HOST}" fi From 987b111e0419e8f1fe0f2b01f3013f97a998f369 Mon Sep 17 00:00:00 2001 From: Tho Ho Date: Thu, 22 Dec 2022 22:12:55 +0800 Subject: [PATCH 11/12] Update root/etc/cont-init.d/50-config Avoid grep -E, change to regex Co-authored-by: Eric Nemchik --- root/etc/cont-init.d/50-config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/root/etc/cont-init.d/50-config b/root/etc/cont-init.d/50-config index a920392..3b934d8 100644 --- a/root/etc/cont-init.d/50-config +++ b/root/etc/cont-init.d/50-config @@ -58,7 +58,7 @@ fi # if DB_HOST contains a port and DB_HOST is not a IPv6 without brackets [..] # support ipv4:port, [ipv6]:port, and domain:port -if echo "$DB_HOST" | grep -qE ':[0-9]+$' && ! echo "$DB_HOST" | grep -qE '^(:{0,2}[a-fA-F0-9]{1,4})+$'; then +if [[ ${DB_HOST} =~ :[0-9]+$ ]] && ! [[ ${DB_HOST} =~ ^(:{0,2}[a-fA-F0-9]{1,4})+$ ]]; then DB_HOST_PORT="${DB_HOST}" fi From e2bd73702696e7a0ee4a06d41179242130355b17 Mon Sep 17 00:00:00 2001 From: Tho Ho Date: Fri, 23 Dec 2022 00:27:42 +0800 Subject: [PATCH 12/12] sed and grep to support .env.sample upstream comments with # --- root/etc/cont-init.d/50-config | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/root/etc/cont-init.d/50-config b/root/etc/cont-init.d/50-config index 3b934d8..5c249dc 100644 --- a/root/etc/cont-init.d/50-config +++ b/root/etc/cont-init.d/50-config @@ -82,17 +82,17 @@ fi if [[ -n "${DB_HOST}" ]]; then echo "Running config - DB_HOST set" - if ! grep -xq "^DB_PORT=.*" /config/www/.env; then + if ! grep -xqE "^[#]?DB_PORT=.*" /config/www/.env; then # add DB_PORT line to /config/www/.env because current /app/www/.env.example doesn't have it - sed -i "/^DB_HOST=.*/a DB_PORT=${DB_PORT}" /config/www/.env + sed -i -E "/^[#]?DB_HOST=.*/a DB_PORT=${DB_PORT}" /config/www/.env echo "**** Insert DB_PORT=${DB_PORT} into /config/www/.env ****" fi - sed -i "s/^DB_HOST=.*/DB_HOST=${DB_HOST}/g" /config/www/.env - sed -i "s/^DB_PORT=.*/DB_PORT=${DB_PORT}/g" /config/www/.env - sed -i "s/^DB_DATABASE=.*/DB_DATABASE=${DB_DATABASE}/g" /config/www/.env - sed -i "s/^DB_USERNAME=.*/DB_USERNAME=${DB_USER}/g" /config/www/.env - sed -i "s/^DB_PASSWORD=.*/DB_PASSWORD=${DB_PASS}/g" /config/www/.env + sed -i -E "s/^[#]?DB_HOST=.*/DB_HOST=${DB_HOST}/g" /config/www/.env + sed -i -E "s/^[#]?DB_PORT=.*/DB_PORT=${DB_PORT}/g" /config/www/.env + sed -i -E "s/^[#]?DB_DATABASE=.*/DB_DATABASE=${DB_DATABASE}/g" /config/www/.env + sed -i -E "s/^[#]?DB_USERNAME=.*/DB_USERNAME=${DB_USER}/g" /config/www/.env + sed -i -E "s/^[#]?DB_PASSWORD=.*/DB_PASSWORD=${DB_PASS}/g" /config/www/.env fi # set appurl