Merge "[COMMON] Fix declare bashisms"
[oom.git] / kubernetes / portal / components / portal-mariadb / resources / config / mariadb / docker-entrypoint.sh
index fe496bc..63d266b 100644 (file)
@@ -1,7 +1,6 @@
 #!/bin/bash
 
 set -eo pipefail
-shopt -s nullglob
 
 # logging functions
 mysql_log() {
@@ -50,13 +49,6 @@ file_env() {
     unset "$fileVar"
 }
 
-# check to see if this file is being run or sourced from another script
-_is_sourced() {
-    # https://unix.stackexchange.com/a/215279
-    [ "${#FUNCNAME[@]}" -ge 2 ] \
-        && [ "${FUNCNAME[0]}" = '_is_sourced' ] \
-        && [ "${FUNCNAME[1]}" = 'source' ]
-}
 
 # usage: docker_process_init_files [file [file [...]]]
 #    ie: docker_process_init_files /always-initdb.d/*
@@ -177,11 +169,20 @@ docker_init_database_dir() {
     mysql_note "Database files initialized"
 }
 
+if [ -z "$DATADIR" ]; then
+    DATADIR='unknown'
+fi
+if [ -z "$SOCKET" ]; then
+    SOCKET='unknown'
+fi
+if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
+    DATABASE_ALREADY_EXISTS='false'
+fi
+
 # Loads various settings that are used elsewhere in the script
 # This should be called after mysql_check_config, but before any other functions
 docker_setup_env() {
     # Get config
-    declare -g DATADIR SOCKET
     DATADIR="$(mysql_get_config 'datadir' "$@")"
     SOCKET="$(mysql_get_config 'socket' "$@")"
 
@@ -193,7 +194,6 @@ docker_setup_env() {
     file_env 'MYSQL_ROOT_PASSWORD'
     file_env 'PORTAL_DB_TABLES'
 
-    declare -g DATABASE_ALREADY_EXISTS
     if [ -d "$DATADIR/mysql" ]; then
         DATABASE_ALREADY_EXISTS='true'
     fi
@@ -378,6 +378,7 @@ _main() {
 }
 
 # If we are sourced from elsewhere, don't perform any further actions
-if ! _is_sourced; then
+# https://stackoverflow.com/questions/2683279/how-to-detect-if-a-script-is-being-sourced/2942183#2942183
+if [ "$(basename $0)" = "docker-entrypoint.sh" ]; then
     _main "$@"
 fi