0
0
Fork 0
mirror of https://github.com/nextcloud/docker.git synced 2025-05-22 15:30:53 +02:00

fix(shell): resolve ShellCheck SC3043 warnings in multiple entrypoint scripts

Dropped 'local' keyword and updated variable names for POSIX compliance.
Modified scripts in 29, 30, 31, and main docker-entrypoint.sh.

Fixes: #2428
Signed-off-by: Enoch Osarenren <osarenrenenoch@gmail.com>
This commit is contained in:
Enoch Osarenren 2025-05-17 20:19:20 +01:00
parent 5e0bfbff2d
commit 086e8ca7b3
3 changed files with 78 additions and 78 deletions

View file

@ -21,37 +21,37 @@ run_as() {
# Execute all executable files in a given directory in alphanumeric order # Execute all executable files in a given directory in alphanumeric order
run_path() { run_path() {
local hook_folder_path="/docker-entrypoint-hooks.d/$1" _hook_folder_path="/docker-entrypoint-hooks.d/$1"
local return_code=0 _return_code=0
local found=0 _found=0
echo "=> Searching for hook scripts (*.sh) to run, located in the folder \"${hook_folder_path}\"" echo "=> Searching for hook scripts (*.sh) to run, located in the folder \"${_hook_folder_path}\""
if ! [ -d "${hook_folder_path}" ] || directory_empty "${hook_folder_path}"; then if ! [ -d "${_hook_folder_path}" ] || directory_empty "${_hook_folder_path}"; then
echo "==> Skipped: the \"$1\" folder is empty (or does not exist)" echo "==> Skipped: the \"$1\" folder is empty (or does not exist)"
return 0 return 0
fi fi
find "${hook_folder_path}" -maxdepth 1 -iname '*.sh' '(' -type f -o -type l ')' -print | sort | ( find "${_hook_folder_path}" -maxdepth 1 -iname '*.sh' '(' -type f -o -type l ')' -print | sort | (
while read -r script_file_path; do while read -r script_file_path; do
if ! [ -x "${script_file_path}" ]; then if ! [ -x "${script_file_path}" ]; then
echo "==> The script \"${script_file_path}\" was skipped, because it lacks the executable flag" echo "==> The script \"${script_file_path}\" was skipped, because it lacks the executable flag"
found=$((found-1)) _found=$((_found-1))
continue continue
fi fi
echo "==> Running the script (cwd: $(pwd)): \"${script_file_path}\"" echo "==> Running the script (cwd: $(pwd)): \"${script_file_path}\""
found=$((found+1)) _found=$((_found+1))
run_as "${script_file_path}" || return_code="$?" run_as "${script_file_path}" || _return_code="$?"
if [ "${return_code}" -ne "0" ]; then if [ "${_return_code}" -ne "0" ]; then
echo "==> Failed at executing script \"${script_file_path}\". Exit code: ${return_code}" echo "==> Failed at executing script \"${script_file_path}\". Exit code: ${_return_code}"
exit 1 exit 1
fi fi
echo "==> Finished executing the script: \"${script_file_path}\"" echo "==> Finished executing the script: \"${script_file_path}\""
done done
if [ "$found" -lt "1" ]; then if [ "$_found" -lt "1" ]; then
echo "==> Skipped: the \"$1\" folder does not contain any valid scripts" echo "==> Skipped: the \"$1\" folder does not contain any valid scripts"
else else
echo "=> Completed executing scripts in the \"$1\" folder" echo "=> Completed executing scripts in the \"$1\" folder"
@ -64,23 +64,23 @@ run_path() {
# (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of # (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of
# "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature) # "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature)
file_env() { file_env() {
local var="$1" _var="$1"
local fileVar="${var}_FILE" _fileVar="${_var}_FILE"
local def="${2:-}" _def="${2:-}"
local varValue=$(env | grep -E "^${var}=" | sed -E -e "s/^${var}=//") _varValue=$(env | grep -E "^${_var}=" | sed -E -e "s/^${_var}=//")
local fileVarValue=$(env | grep -E "^${fileVar}=" | sed -E -e "s/^${fileVar}=//") _fileVarValue=$(env | grep -E "^${_fileVar}=" | sed -E -e "s/^${_fileVar}=//")
if [ -n "${varValue}" ] && [ -n "${fileVarValue}" ]; then if [ -n "${_varValue}" ] && [ -n "${_fileVarValue}" ]; then
echo >&2 "error: both $var and $fileVar are set (but are exclusive)" echo >&2 "error: both $_var and $_fileVar are set (but are exclusive)"
exit 1 exit 1
fi fi
if [ -n "${varValue}" ]; then if [ -n "${_varValue}" ]; then
export "$var"="${varValue}" export "$_var"="${_varValue}"
elif [ -n "${fileVarValue}" ]; then elif [ -n "${_fileVarValue}" ]; then
export "$var"="$(cat "${fileVarValue}")" export "$_var"="$(cat "${_fileVarValue}")"
elif [ -n "${def}" ]; then elif [ -n "${_def}" ]; then
export "$var"="$def" export "$_var"="$_def"
fi fi
unset "$fileVar" unset "$_fileVar"
} }
if expr "$1" : "apache" 1>/dev/null; then if expr "$1" : "apache" 1>/dev/null; then

View file

@ -21,37 +21,37 @@ run_as() {
# Execute all executable files in a given directory in alphanumeric order # Execute all executable files in a given directory in alphanumeric order
run_path() { run_path() {
local hook_folder_path="/docker-entrypoint-hooks.d/$1" _hook_folder_path="/docker-entrypoint-hooks.d/$1"
local return_code=0 _return_code=0
local found=0 _found=0
echo "=> Searching for hook scripts (*.sh) to run, located in the folder \"${hook_folder_path}\"" echo "=> Searching for hook scripts (*.sh) to run, located in the folder \"${_hook_folder_path}\""
if ! [ -d "${hook_folder_path}" ] || directory_empty "${hook_folder_path}"; then if ! [ -d "${_hook_folder_path}" ] || directory_empty "${_hook_folder_path}"; then
echo "==> Skipped: the \"$1\" folder is empty (or does not exist)" echo "==> Skipped: the \"$1\" folder is empty (or does not exist)"
return 0 return 0
fi fi
find "${hook_folder_path}" -maxdepth 1 -iname '*.sh' '(' -type f -o -type l ')' -print | sort | ( find "${_hook_folder_path}" -maxdepth 1 -iname '*.sh' '(' -type f -o -type l ')' -print | sort | (
while read -r script_file_path; do while read -r script_file_path; do
if ! [ -x "${script_file_path}" ]; then if ! [ -x "${script_file_path}" ]; then
echo "==> The script \"${script_file_path}\" was skipped, because it lacks the executable flag" echo "==> The script \"${script_file_path}\" was skipped, because it lacks the executable flag"
found=$((found-1)) _found=$((_found-1))
continue continue
fi fi
echo "==> Running the script (cwd: $(pwd)): \"${script_file_path}\"" echo "==> Running the script (cwd: $(pwd)): \"${script_file_path}\""
found=$((found+1)) _found=$((_found+1))
run_as "${script_file_path}" || return_code="$?" run_as "${script_file_path}" || _return_code="$?"
if [ "${return_code}" -ne "0" ]; then if [ "${_return_code}" -ne "0" ]; then
echo "==> Failed at executing script \"${script_file_path}\". Exit code: ${return_code}" echo "==> Failed at executing script \"${script_file_path}\". Exit code: ${_return_code}"
exit 1 exit 1
fi fi
echo "==> Finished executing the script: \"${script_file_path}\"" echo "==> Finished executing the script: \"${script_file_path}\""
done done
if [ "$found" -lt "1" ]; then if [ "$_found" -lt "1" ]; then
echo "==> Skipped: the \"$1\" folder does not contain any valid scripts" echo "==> Skipped: the \"$1\" folder does not contain any valid scripts"
else else
echo "=> Completed executing scripts in the \"$1\" folder" echo "=> Completed executing scripts in the \"$1\" folder"
@ -64,23 +64,23 @@ run_path() {
# (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of # (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of
# "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature) # "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature)
file_env() { file_env() {
local var="$1" _var="$1"
local fileVar="${var}_FILE" _fileVar="${_var}_FILE"
local def="${2:-}" _def="${2:-}"
local varValue=$(env | grep -E "^${var}=" | sed -E -e "s/^${var}=//") _varValue=$(env | grep -E "^${_var}=" | sed -E -e "s/^${_var}=//")
local fileVarValue=$(env | grep -E "^${fileVar}=" | sed -E -e "s/^${fileVar}=//") _fileVarValue=$(env | grep -E "^${_fileVar}=" | sed -E -e "s/^${_fileVar}=//")
if [ -n "${varValue}" ] && [ -n "${fileVarValue}" ]; then if [ -n "${_varValue}" ] && [ -n "${_fileVarValue}" ]; then
echo >&2 "error: both $var and $fileVar are set (but are exclusive)" echo >&2 "error: both $_var and $_fileVar are set (but are exclusive)"
exit 1 exit 1
fi fi
if [ -n "${varValue}" ]; then if [ -n "${_varValue}" ]; then
export "$var"="${varValue}" export "$_var"="${_varValue}"
elif [ -n "${fileVarValue}" ]; then elif [ -n "${_fileVarValue}" ]; then
export "$var"="$(cat "${fileVarValue}")" export "$_var"="$(cat "${_fileVarValue}")"
elif [ -n "${def}" ]; then elif [ -n "${_def}" ]; then
export "$var"="$def" export "$_var"="$_def"
fi fi
unset "$fileVar" unset "$_fileVar"
} }
if expr "$1" : "apache" 1>/dev/null; then if expr "$1" : "apache" 1>/dev/null; then

View file

@ -21,37 +21,37 @@ run_as() {
# Execute all executable files in a given directory in alphanumeric order # Execute all executable files in a given directory in alphanumeric order
run_path() { run_path() {
local hook_folder_path="/docker-entrypoint-hooks.d/$1" _hook_folder_path="/docker-entrypoint-hooks.d/$1"
local return_code=0 _return_code=0
local found=0 _found=0
echo "=> Searching for hook scripts (*.sh) to run, located in the folder \"${hook_folder_path}\"" echo "=> Searching for hook scripts (*.sh) to run, located in the folder \"${_hook_folder_path}\""
if ! [ -d "${hook_folder_path}" ] || directory_empty "${hook_folder_path}"; then if ! [ -d "${_hook_folder_path}" ] || directory_empty "${_hook_folder_path}"; then
echo "==> Skipped: the \"$1\" folder is empty (or does not exist)" echo "==> Skipped: the \"$1\" folder is empty (or does not exist)"
return 0 return 0
fi fi
find "${hook_folder_path}" -maxdepth 1 -iname '*.sh' '(' -type f -o -type l ')' -print | sort | ( find "${_hook_folder_path}" -maxdepth 1 -iname '*.sh' '(' -type f -o -type l ')' -print | sort | (
while read -r script_file_path; do while read -r script_file_path; do
if ! [ -x "${script_file_path}" ]; then if ! [ -x "${script_file_path}" ]; then
echo "==> The script \"${script_file_path}\" was skipped, because it lacks the executable flag" echo "==> The script \"${script_file_path}\" was skipped, because it lacks the executable flag"
found=$((found-1)) _found=$((_found-1))
continue continue
fi fi
echo "==> Running the script (cwd: $(pwd)): \"${script_file_path}\"" echo "==> Running the script (cwd: $(pwd)): \"${script_file_path}\""
found=$((found+1)) _found=$((_found+1))
run_as "${script_file_path}" || return_code="$?" run_as "${script_file_path}" || _return_code="$?"
if [ "${return_code}" -ne "0" ]; then if [ "${_return_code}" -ne "0" ]; then
echo "==> Failed at executing script \"${script_file_path}\". Exit code: ${return_code}" echo "==> Failed at executing script \"${script_file_path}\". Exit code: ${_return_code}"
exit 1 exit 1
fi fi
echo "==> Finished executing the script: \"${script_file_path}\"" echo "==> Finished executing the script: \"${script_file_path}\""
done done
if [ "$found" -lt "1" ]; then if [ "$_found" -lt "1" ]; then
echo "==> Skipped: the \"$1\" folder does not contain any valid scripts" echo "==> Skipped: the \"$1\" folder does not contain any valid scripts"
else else
echo "=> Completed executing scripts in the \"$1\" folder" echo "=> Completed executing scripts in the \"$1\" folder"
@ -64,23 +64,23 @@ run_path() {
# (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of # (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of
# "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature) # "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature)
file_env() { file_env() {
local var="$1" _var="$1"
local fileVar="${var}_FILE" _fileVar="${_var}_FILE"
local def="${2:-}" _def="${2:-}"
local varValue=$(env | grep -E "^${var}=" | sed -E -e "s/^${var}=//") _varValue=$(env | grep -E "^${_var}=" | sed -E -e "s/^${_var}=//")
local fileVarValue=$(env | grep -E "^${fileVar}=" | sed -E -e "s/^${fileVar}=//") _fileVarValue=$(env | grep -E "^${_fileVar}=" | sed -E -e "s/^${_fileVar}=//")
if [ -n "${varValue}" ] && [ -n "${fileVarValue}" ]; then if [ -n "${_varValue}" ] && [ -n "${_fileVarValue}" ]; then
echo >&2 "error: both $var and $fileVar are set (but are exclusive)" echo >&2 "error: both $_var and $_fileVar are set (but are exclusive)"
exit 1 exit 1
fi fi
if [ -n "${varValue}" ]; then if [ -n "${_varValue}" ]; then
export "$var"="${varValue}" export "$_var"="${_varValue}"
elif [ -n "${fileVarValue}" ]; then elif [ -n "${_fileVarValue}" ]; then
export "$var"="$(cat "${fileVarValue}")" export "$_var"="$(cat "${_fileVarValue}")"
elif [ -n "${def}" ]; then elif [ -n "${_def}" ]; then
export "$var"="$def" export "$_var"="$_def"
fi fi
unset "$fileVar" unset "$_fileVar"
} }
if expr "$1" : "apache" 1>/dev/null; then if expr "$1" : "apache" 1>/dev/null; then