diff --git a/alpine-mariadb-aarch64/files/run.sh b/alpine-mariadb-aarch64/files/run.sh index ca0382c..b44e941 100644 --- a/alpine-mariadb-aarch64/files/run.sh +++ b/alpine-mariadb-aarch64/files/run.sh @@ -12,35 +12,35 @@ read_secret() { # Set MYSQL_ variables based on MARIADB_ variables or secrets if MYSQL_ is not set for var in ROOT_PASSWORD DATABASE USER PASSWORD CHARSET COLLATION; do - mysql_var="MYSQL_${var}" - mariadb_var="MARIADB_${var}" + eval mysql_var="\$MYSQL_${var}" + eval mariadb_var="\$MARIADB_${var}" # Check environment variables - if [ -z "${!mysql_var}" ] && [ -n "${!mariadb_var}" ]; then - export "$mysql_var"="${!mariadb_var}" + if [ -z "$mysql_var" ] && [ -n "$mariadb_var" ]; then + eval "export MYSQL_${var}=\$mariadb_var" fi # Check secrets - mysql_secret="/run/secrets/mysql_${var,,}" - mariadb_secret="/run/secrets/mariadb_${var,,}" + mysql_secret="/run/secrets/mysql_$(echo $var | tr '[:upper:]' '[:lower:]')" + mariadb_secret="/run/secrets/mariadb_$(echo $var | tr '[:upper:]' '[:lower:]')" - if [ -z "${!mysql_var}" ] && [ -f "$mariadb_secret" ]; then - export "$mysql_var"=$(read_secret "$mariadb_secret") - elif [ -z "${!mysql_var}" ] && [ -f "$mysql_secret" ]; then - export "$mysql_var"=$(read_secret "$mysql_secret") + if [ -z "$mysql_var" ] && [ -f "$mariadb_secret" ]; then + eval "export MYSQL_${var}=$(read_secret "$mariadb_secret")" + elif [ -z "$mysql_var" ] && [ -f "$mysql_secret" ]; then + eval "export MYSQL_${var}=$(read_secret "$mysql_secret")" fi done # Handle *_FILE variables for var in ROOT_PASSWORD DATABASE USER PASSWORD; do - mysql_var="MYSQL_${var}" - mysql_file_var="MYSQL_${var}_FILE" - mariadb_file_var="MARIADB_${var}_FILE" + eval mysql_var="\$MYSQL_${var}" + eval mysql_file_var="\$MYSQL_${var}_FILE" + eval mariadb_file_var="\$MARIADB_${var}_FILE" - if [ -z "${!mysql_var}" ] && [ -n "${!mysql_file_var}" ]; then - export "$mysql_var"=$(read_secret "${!mysql_file_var}") - elif [ -z "${!mysql_var}" ] && [ -n "${!mariadb_file_var}" ]; then - export "$mysql_var"=$(read_secret "${!mariadb_file_var}") + if [ -z "$mysql_var" ] && [ -n "$mysql_file_var" ]; then + eval "export MYSQL_${var}=$(read_secret "$mysql_file_var")" + elif [ -z "$mysql_var" ] && [ -n "$mariadb_file_var" ]; then + eval "export MYSQL_${var}=$(read_secret "$mariadb_file_var")" fi done diff --git a/alpine-mariadb-amd64/files/run.sh b/alpine-mariadb-amd64/files/run.sh index ca0382c..b44e941 100644 --- a/alpine-mariadb-amd64/files/run.sh +++ b/alpine-mariadb-amd64/files/run.sh @@ -12,35 +12,35 @@ read_secret() { # Set MYSQL_ variables based on MARIADB_ variables or secrets if MYSQL_ is not set for var in ROOT_PASSWORD DATABASE USER PASSWORD CHARSET COLLATION; do - mysql_var="MYSQL_${var}" - mariadb_var="MARIADB_${var}" + eval mysql_var="\$MYSQL_${var}" + eval mariadb_var="\$MARIADB_${var}" # Check environment variables - if [ -z "${!mysql_var}" ] && [ -n "${!mariadb_var}" ]; then - export "$mysql_var"="${!mariadb_var}" + if [ -z "$mysql_var" ] && [ -n "$mariadb_var" ]; then + eval "export MYSQL_${var}=\$mariadb_var" fi # Check secrets - mysql_secret="/run/secrets/mysql_${var,,}" - mariadb_secret="/run/secrets/mariadb_${var,,}" + mysql_secret="/run/secrets/mysql_$(echo $var | tr '[:upper:]' '[:lower:]')" + mariadb_secret="/run/secrets/mariadb_$(echo $var | tr '[:upper:]' '[:lower:]')" - if [ -z "${!mysql_var}" ] && [ -f "$mariadb_secret" ]; then - export "$mysql_var"=$(read_secret "$mariadb_secret") - elif [ -z "${!mysql_var}" ] && [ -f "$mysql_secret" ]; then - export "$mysql_var"=$(read_secret "$mysql_secret") + if [ -z "$mysql_var" ] && [ -f "$mariadb_secret" ]; then + eval "export MYSQL_${var}=$(read_secret "$mariadb_secret")" + elif [ -z "$mysql_var" ] && [ -f "$mysql_secret" ]; then + eval "export MYSQL_${var}=$(read_secret "$mysql_secret")" fi done # Handle *_FILE variables for var in ROOT_PASSWORD DATABASE USER PASSWORD; do - mysql_var="MYSQL_${var}" - mysql_file_var="MYSQL_${var}_FILE" - mariadb_file_var="MARIADB_${var}_FILE" + eval mysql_var="\$MYSQL_${var}" + eval mysql_file_var="\$MYSQL_${var}_FILE" + eval mariadb_file_var="\$MARIADB_${var}_FILE" - if [ -z "${!mysql_var}" ] && [ -n "${!mysql_file_var}" ]; then - export "$mysql_var"=$(read_secret "${!mysql_file_var}") - elif [ -z "${!mysql_var}" ] && [ -n "${!mariadb_file_var}" ]; then - export "$mysql_var"=$(read_secret "${!mariadb_file_var}") + if [ -z "$mysql_var" ] && [ -n "$mysql_file_var" ]; then + eval "export MYSQL_${var}=$(read_secret "$mysql_file_var")" + elif [ -z "$mysql_var" ] && [ -n "$mariadb_file_var" ]; then + eval "export MYSQL_${var}=$(read_secret "$mariadb_file_var")" fi done diff --git a/alpine-mariadb-armhf/files/run.sh b/alpine-mariadb-armhf/files/run.sh index ca0382c..b44e941 100644 --- a/alpine-mariadb-armhf/files/run.sh +++ b/alpine-mariadb-armhf/files/run.sh @@ -12,35 +12,35 @@ read_secret() { # Set MYSQL_ variables based on MARIADB_ variables or secrets if MYSQL_ is not set for var in ROOT_PASSWORD DATABASE USER PASSWORD CHARSET COLLATION; do - mysql_var="MYSQL_${var}" - mariadb_var="MARIADB_${var}" + eval mysql_var="\$MYSQL_${var}" + eval mariadb_var="\$MARIADB_${var}" # Check environment variables - if [ -z "${!mysql_var}" ] && [ -n "${!mariadb_var}" ]; then - export "$mysql_var"="${!mariadb_var}" + if [ -z "$mysql_var" ] && [ -n "$mariadb_var" ]; then + eval "export MYSQL_${var}=\$mariadb_var" fi # Check secrets - mysql_secret="/run/secrets/mysql_${var,,}" - mariadb_secret="/run/secrets/mariadb_${var,,}" + mysql_secret="/run/secrets/mysql_$(echo $var | tr '[:upper:]' '[:lower:]')" + mariadb_secret="/run/secrets/mariadb_$(echo $var | tr '[:upper:]' '[:lower:]')" - if [ -z "${!mysql_var}" ] && [ -f "$mariadb_secret" ]; then - export "$mysql_var"=$(read_secret "$mariadb_secret") - elif [ -z "${!mysql_var}" ] && [ -f "$mysql_secret" ]; then - export "$mysql_var"=$(read_secret "$mysql_secret") + if [ -z "$mysql_var" ] && [ -f "$mariadb_secret" ]; then + eval "export MYSQL_${var}=$(read_secret "$mariadb_secret")" + elif [ -z "$mysql_var" ] && [ -f "$mysql_secret" ]; then + eval "export MYSQL_${var}=$(read_secret "$mysql_secret")" fi done # Handle *_FILE variables for var in ROOT_PASSWORD DATABASE USER PASSWORD; do - mysql_var="MYSQL_${var}" - mysql_file_var="MYSQL_${var}_FILE" - mariadb_file_var="MARIADB_${var}_FILE" + eval mysql_var="\$MYSQL_${var}" + eval mysql_file_var="\$MYSQL_${var}_FILE" + eval mariadb_file_var="\$MARIADB_${var}_FILE" - if [ -z "${!mysql_var}" ] && [ -n "${!mysql_file_var}" ]; then - export "$mysql_var"=$(read_secret "${!mysql_file_var}") - elif [ -z "${!mysql_var}" ] && [ -n "${!mariadb_file_var}" ]; then - export "$mysql_var"=$(read_secret "${!mariadb_file_var}") + if [ -z "$mysql_var" ] && [ -n "$mysql_file_var" ]; then + eval "export MYSQL_${var}=$(read_secret "$mysql_file_var")" + elif [ -z "$mysql_var" ] && [ -n "$mariadb_file_var" ]; then + eval "export MYSQL_${var}=$(read_secret "$mariadb_file_var")" fi done