Skip to content

Commit

Permalink
Add "set -u" for further accidental mistake protection
Browse files Browse the repository at this point in the history
  • Loading branch information
tianon committed Nov 17, 2016
1 parent 15dab9a commit 8ab70dd
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 30 deletions.
12 changes: 6 additions & 6 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
set -e
set -eu

# usage: file_env VAR [DEFAULT]
# ie: file_env 'XYZ_DB_PASSWORD' 'example'
Expand All @@ -9,14 +9,14 @@ file_env() {
local var="$1"
local fileVar="${var}_FILE"
local def="${2:-}"
if [ "${!var}" ] && [ "${!fileVar}" ]; then
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
echo >&2 "error: both $var and $fileVar are set (but are exclusive)"
exit 1
fi
local val="$def"
if [ "${!var}" ]; then
if [ "${!var:-}" ]; then
val="${!var}"
elif [ "${!fileVar}" ]; then
elif [ "${!fileVar:-}" ]; then
val="$(< "${!fileVar}")"
fi
export "$var"="$val"
Expand All @@ -28,9 +28,9 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
# if we're linked to MySQL and thus have credentials already, let's use them
file_env 'WORDPRESS_DB_USER' "${MYSQL_ENV_MYSQL_USER:-root}"
if [ "$WORDPRESS_DB_USER" = 'root' ]; then
file_env 'WORDPRESS_DB_PASSWORD' "$MYSQL_ENV_MYSQL_ROOT_PASSWORD"
file_env 'WORDPRESS_DB_PASSWORD' "${MYSQL_ENV_MYSQL_ROOT_PASSWORD:-}"
else
file_env 'WORDPRESS_DB_PASSWORD' "$MYSQL_ENV_MYSQL_PASSWORD"
file_env 'WORDPRESS_DB_PASSWORD' "${MYSQL_ENV_MYSQL_PASSWORD:-}"
fi
file_env 'WORDPRESS_DB_NAME' "${MYSQL_ENV_MYSQL_DATABASE:-wordpress}"
if [ -z "$WORDPRESS_DB_PASSWORD" ]; then
Expand Down
12 changes: 6 additions & 6 deletions php5.6/apache/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
set -e
set -eu

# usage: file_env VAR [DEFAULT]
# ie: file_env 'XYZ_DB_PASSWORD' 'example'
Expand All @@ -9,14 +9,14 @@ file_env() {
local var="$1"
local fileVar="${var}_FILE"
local def="${2:-}"
if [ "${!var}" ] && [ "${!fileVar}" ]; then
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
echo >&2 "error: both $var and $fileVar are set (but are exclusive)"
exit 1
fi
local val="$def"
if [ "${!var}" ]; then
if [ "${!var:-}" ]; then
val="${!var}"
elif [ "${!fileVar}" ]; then
elif [ "${!fileVar:-}" ]; then
val="$(< "${!fileVar}")"
fi
export "$var"="$val"
Expand All @@ -28,9 +28,9 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
# if we're linked to MySQL and thus have credentials already, let's use them
file_env 'WORDPRESS_DB_USER' "${MYSQL_ENV_MYSQL_USER:-root}"
if [ "$WORDPRESS_DB_USER" = 'root' ]; then
file_env 'WORDPRESS_DB_PASSWORD' "$MYSQL_ENV_MYSQL_ROOT_PASSWORD"
file_env 'WORDPRESS_DB_PASSWORD' "${MYSQL_ENV_MYSQL_ROOT_PASSWORD:-}"
else
file_env 'WORDPRESS_DB_PASSWORD' "$MYSQL_ENV_MYSQL_PASSWORD"
file_env 'WORDPRESS_DB_PASSWORD' "${MYSQL_ENV_MYSQL_PASSWORD:-}"
fi
file_env 'WORDPRESS_DB_NAME' "${MYSQL_ENV_MYSQL_DATABASE:-wordpress}"
if [ -z "$WORDPRESS_DB_PASSWORD" ]; then
Expand Down
12 changes: 6 additions & 6 deletions php5.6/fpm/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
set -e
set -eu

# usage: file_env VAR [DEFAULT]
# ie: file_env 'XYZ_DB_PASSWORD' 'example'
Expand All @@ -9,14 +9,14 @@ file_env() {
local var="$1"
local fileVar="${var}_FILE"
local def="${2:-}"
if [ "${!var}" ] && [ "${!fileVar}" ]; then
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
echo >&2 "error: both $var and $fileVar are set (but are exclusive)"
exit 1
fi
local val="$def"
if [ "${!var}" ]; then
if [ "${!var:-}" ]; then
val="${!var}"
elif [ "${!fileVar}" ]; then
elif [ "${!fileVar:-}" ]; then
val="$(< "${!fileVar}")"
fi
export "$var"="$val"
Expand All @@ -28,9 +28,9 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
# if we're linked to MySQL and thus have credentials already, let's use them
file_env 'WORDPRESS_DB_USER' "${MYSQL_ENV_MYSQL_USER:-root}"
if [ "$WORDPRESS_DB_USER" = 'root' ]; then
file_env 'WORDPRESS_DB_PASSWORD' "$MYSQL_ENV_MYSQL_ROOT_PASSWORD"
file_env 'WORDPRESS_DB_PASSWORD' "${MYSQL_ENV_MYSQL_ROOT_PASSWORD:-}"
else
file_env 'WORDPRESS_DB_PASSWORD' "$MYSQL_ENV_MYSQL_PASSWORD"
file_env 'WORDPRESS_DB_PASSWORD' "${MYSQL_ENV_MYSQL_PASSWORD:-}"
fi
file_env 'WORDPRESS_DB_NAME' "${MYSQL_ENV_MYSQL_DATABASE:-wordpress}"
if [ -z "$WORDPRESS_DB_PASSWORD" ]; then
Expand Down
12 changes: 6 additions & 6 deletions php7.0/apache/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
set -e
set -eu

# usage: file_env VAR [DEFAULT]
# ie: file_env 'XYZ_DB_PASSWORD' 'example'
Expand All @@ -9,14 +9,14 @@ file_env() {
local var="$1"
local fileVar="${var}_FILE"
local def="${2:-}"
if [ "${!var}" ] && [ "${!fileVar}" ]; then
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
echo >&2 "error: both $var and $fileVar are set (but are exclusive)"
exit 1
fi
local val="$def"
if [ "${!var}" ]; then
if [ "${!var:-}" ]; then
val="${!var}"
elif [ "${!fileVar}" ]; then
elif [ "${!fileVar:-}" ]; then
val="$(< "${!fileVar}")"
fi
export "$var"="$val"
Expand All @@ -28,9 +28,9 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
# if we're linked to MySQL and thus have credentials already, let's use them
file_env 'WORDPRESS_DB_USER' "${MYSQL_ENV_MYSQL_USER:-root}"
if [ "$WORDPRESS_DB_USER" = 'root' ]; then
file_env 'WORDPRESS_DB_PASSWORD' "$MYSQL_ENV_MYSQL_ROOT_PASSWORD"
file_env 'WORDPRESS_DB_PASSWORD' "${MYSQL_ENV_MYSQL_ROOT_PASSWORD:-}"
else
file_env 'WORDPRESS_DB_PASSWORD' "$MYSQL_ENV_MYSQL_PASSWORD"
file_env 'WORDPRESS_DB_PASSWORD' "${MYSQL_ENV_MYSQL_PASSWORD:-}"
fi
file_env 'WORDPRESS_DB_NAME' "${MYSQL_ENV_MYSQL_DATABASE:-wordpress}"
if [ -z "$WORDPRESS_DB_PASSWORD" ]; then
Expand Down
12 changes: 6 additions & 6 deletions php7.0/fpm/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
set -e
set -eu

# usage: file_env VAR [DEFAULT]
# ie: file_env 'XYZ_DB_PASSWORD' 'example'
Expand All @@ -9,14 +9,14 @@ file_env() {
local var="$1"
local fileVar="${var}_FILE"
local def="${2:-}"
if [ "${!var}" ] && [ "${!fileVar}" ]; then
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
echo >&2 "error: both $var and $fileVar are set (but are exclusive)"
exit 1
fi
local val="$def"
if [ "${!var}" ]; then
if [ "${!var:-}" ]; then
val="${!var}"
elif [ "${!fileVar}" ]; then
elif [ "${!fileVar:-}" ]; then
val="$(< "${!fileVar}")"
fi
export "$var"="$val"
Expand All @@ -28,9 +28,9 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
# if we're linked to MySQL and thus have credentials already, let's use them
file_env 'WORDPRESS_DB_USER' "${MYSQL_ENV_MYSQL_USER:-root}"
if [ "$WORDPRESS_DB_USER" = 'root' ]; then
file_env 'WORDPRESS_DB_PASSWORD' "$MYSQL_ENV_MYSQL_ROOT_PASSWORD"
file_env 'WORDPRESS_DB_PASSWORD' "${MYSQL_ENV_MYSQL_ROOT_PASSWORD:-}"
else
file_env 'WORDPRESS_DB_PASSWORD' "$MYSQL_ENV_MYSQL_PASSWORD"
file_env 'WORDPRESS_DB_PASSWORD' "${MYSQL_ENV_MYSQL_PASSWORD:-}"
fi
file_env 'WORDPRESS_DB_NAME' "${MYSQL_ENV_MYSQL_DATABASE:-wordpress}"
if [ -z "$WORDPRESS_DB_PASSWORD" ]; then
Expand Down

0 comments on commit 8ab70dd

Please sign in to comment.