Skip to content

Commit 206541a

Browse files
committed
Adjust printf to be more resilient; use exit code directly instead of a variable
1 parent 91785a5 commit 206541a

File tree

4 files changed

+20
-28
lines changed

4 files changed

+20
-28
lines changed

.template.Debian/docker-entrypoint.sh

+5-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ shopt -s nullglob
55
# logging functions
66
mysql_log() {
77
local type="$1"; shift
8-
printf "$(date --rfc-3339=seconds) [${type}] [Entrypoint]: $@\n"
8+
printf '%s [%s] [Entrypoint]: %s\n' "$(date --rfc-3339=seconds)" "$type" "$*"
99
}
1010
mysql_note() {
1111
mysql_log Note "$@"
@@ -68,7 +68,7 @@ docker_process_init_files() {
6868
mysql_check_config() {
6969
local toRun=( "$@" --verbose --help ) errors
7070
if ! errors="$("${toRun[@]}" 2>&1 >/dev/null)"; then
71-
mysql_error "mysqld failed while attempting to check config\n\tcommand was: ${toRun[*]}\n\t$errors"
71+
mysql_error $'mysqld failed while attempting to check config\n\tcommand was: '"${toRun[*]}"$'\n\t'"$errors"
7272
fi
7373
}
7474

@@ -114,17 +114,15 @@ docker_temp_server_start() {
114114
# Stop the server. When using a local socket file mysqladmin will block until
115115
# the shutdown is complete.
116116
docker_temp_server_stop() {
117-
local result=0
118-
mysqladmin --defaults-extra-file=<( _mysql_passfile ) shutdown -uroot --socket="${SOCKET}" || result=$?
119-
if [ "$result" != "0" ]; then
120-
mysql_error "Unable to shut down server. Status code $result."
117+
if ! mysqladmin --defaults-extra-file=<( _mysql_passfile ) shutdown -uroot --socket="${SOCKET}"; then
118+
mysql_error "Unable to shut down server."
121119
fi
122120
}
123121

124122
# Verify that the minimally required password settings are set for new databases.
125123
docker_verify_minimum_env() {
126124
if [ -z "$MYSQL_ROOT_PASSWORD" -a -z "$MYSQL_ALLOW_EMPTY_PASSWORD" -a -z "$MYSQL_RANDOM_ROOT_PASSWORD" ]; then
127-
mysql_error "Database is uninitialized and password option is not specified \n\tYou need to specify one of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD"
125+
mysql_error $'Database is uninitialized and password option is not specified\n\tYou need to specify one of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD'
128126
fi
129127
}
130128

5.6/docker-entrypoint.sh

+5-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ shopt -s nullglob
55
# logging functions
66
mysql_log() {
77
local type="$1"; shift
8-
printf "$(date --rfc-3339=seconds) [${type}] [Entrypoint]: $@\n"
8+
printf '%s [%s] [Entrypoint]: %s\n' "$(date --rfc-3339=seconds)" "$type" "$*"
99
}
1010
mysql_note() {
1111
mysql_log Note "$@"
@@ -68,7 +68,7 @@ docker_process_init_files() {
6868
mysql_check_config() {
6969
local toRun=( "$@" --verbose --help ) errors
7070
if ! errors="$("${toRun[@]}" 2>&1 >/dev/null)"; then
71-
mysql_error "mysqld failed while attempting to check config\n\tcommand was: ${toRun[*]}\n\t$errors"
71+
mysql_error $'mysqld failed while attempting to check config\n\tcommand was: '"${toRun[*]}"$'\n\t'"$errors"
7272
fi
7373
}
7474

@@ -114,17 +114,15 @@ docker_temp_server_start() {
114114
# Stop the server. When using a local socket file mysqladmin will block until
115115
# the shutdown is complete.
116116
docker_temp_server_stop() {
117-
local result=0
118-
mysqladmin --defaults-extra-file=<( _mysql_passfile ) shutdown -uroot --socket="${SOCKET}" || result=$?
119-
if [ "$result" != "0" ]; then
120-
mysql_error "Unable to shut down server. Status code $result."
117+
if ! mysqladmin --defaults-extra-file=<( _mysql_passfile ) shutdown -uroot --socket="${SOCKET}"; then
118+
mysql_error "Unable to shut down server."
121119
fi
122120
}
123121

124122
# Verify that the minimally required password settings are set for new databases.
125123
docker_verify_minimum_env() {
126124
if [ -z "$MYSQL_ROOT_PASSWORD" -a -z "$MYSQL_ALLOW_EMPTY_PASSWORD" -a -z "$MYSQL_RANDOM_ROOT_PASSWORD" ]; then
127-
mysql_error "Database is uninitialized and password option is not specified \n\tYou need to specify one of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD"
125+
mysql_error $'Database is uninitialized and password option is not specified\n\tYou need to specify one of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD'
128126
fi
129127
}
130128

5.7/docker-entrypoint.sh

+5-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ shopt -s nullglob
55
# logging functions
66
mysql_log() {
77
local type="$1"; shift
8-
printf "$(date --rfc-3339=seconds) [${type}] [Entrypoint]: $@\n"
8+
printf '%s [%s] [Entrypoint]: %s\n' "$(date --rfc-3339=seconds)" "$type" "$*"
99
}
1010
mysql_note() {
1111
mysql_log Note "$@"
@@ -68,7 +68,7 @@ docker_process_init_files() {
6868
mysql_check_config() {
6969
local toRun=( "$@" --verbose --help ) errors
7070
if ! errors="$("${toRun[@]}" 2>&1 >/dev/null)"; then
71-
mysql_error "mysqld failed while attempting to check config\n\tcommand was: ${toRun[*]}\n\t$errors"
71+
mysql_error $'mysqld failed while attempting to check config\n\tcommand was: '"${toRun[*]}"$'\n\t'"$errors"
7272
fi
7373
}
7474

@@ -114,17 +114,15 @@ docker_temp_server_start() {
114114
# Stop the server. When using a local socket file mysqladmin will block until
115115
# the shutdown is complete.
116116
docker_temp_server_stop() {
117-
local result=0
118-
mysqladmin --defaults-extra-file=<( _mysql_passfile ) shutdown -uroot --socket="${SOCKET}" || result=$?
119-
if [ "$result" != "0" ]; then
120-
mysql_error "Unable to shut down server. Status code $result."
117+
if ! mysqladmin --defaults-extra-file=<( _mysql_passfile ) shutdown -uroot --socket="${SOCKET}"; then
118+
mysql_error "Unable to shut down server."
121119
fi
122120
}
123121

124122
# Verify that the minimally required password settings are set for new databases.
125123
docker_verify_minimum_env() {
126124
if [ -z "$MYSQL_ROOT_PASSWORD" -a -z "$MYSQL_ALLOW_EMPTY_PASSWORD" -a -z "$MYSQL_RANDOM_ROOT_PASSWORD" ]; then
127-
mysql_error "Database is uninitialized and password option is not specified \n\tYou need to specify one of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD"
125+
mysql_error $'Database is uninitialized and password option is not specified\n\tYou need to specify one of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD'
128126
fi
129127
}
130128

8.0/docker-entrypoint.sh

+5-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ shopt -s nullglob
55
# logging functions
66
mysql_log() {
77
local type="$1"; shift
8-
printf "$(date --rfc-3339=seconds) [${type}] [Entrypoint]: $@\n"
8+
printf '%s [%s] [Entrypoint]: %s\n' "$(date --rfc-3339=seconds)" "$type" "$*"
99
}
1010
mysql_note() {
1111
mysql_log Note "$@"
@@ -68,7 +68,7 @@ docker_process_init_files() {
6868
mysql_check_config() {
6969
local toRun=( "$@" --verbose --help ) errors
7070
if ! errors="$("${toRun[@]}" 2>&1 >/dev/null)"; then
71-
mysql_error "mysqld failed while attempting to check config\n\tcommand was: ${toRun[*]}\n\t$errors"
71+
mysql_error $'mysqld failed while attempting to check config\n\tcommand was: '"${toRun[*]}"$'\n\t'"$errors"
7272
fi
7373
}
7474

@@ -114,17 +114,15 @@ docker_temp_server_start() {
114114
# Stop the server. When using a local socket file mysqladmin will block until
115115
# the shutdown is complete.
116116
docker_temp_server_stop() {
117-
local result=0
118-
mysqladmin --defaults-extra-file=<( _mysql_passfile ) shutdown -uroot --socket="${SOCKET}" || result=$?
119-
if [ "$result" != "0" ]; then
120-
mysql_error "Unable to shut down server. Status code $result."
117+
if ! mysqladmin --defaults-extra-file=<( _mysql_passfile ) shutdown -uroot --socket="${SOCKET}"; then
118+
mysql_error "Unable to shut down server."
121119
fi
122120
}
123121

124122
# Verify that the minimally required password settings are set for new databases.
125123
docker_verify_minimum_env() {
126124
if [ -z "$MYSQL_ROOT_PASSWORD" -a -z "$MYSQL_ALLOW_EMPTY_PASSWORD" -a -z "$MYSQL_RANDOM_ROOT_PASSWORD" ]; then
127-
mysql_error "Database is uninitialized and password option is not specified \n\tYou need to specify one of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD"
125+
mysql_error $'Database is uninitialized and password option is not specified\n\tYou need to specify one of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD'
128126
fi
129127
}
130128

0 commit comments

Comments
 (0)