From 4e04e5b98d9c5c55758dc11a755a68ac6bec4055 Mon Sep 17 00:00:00 2001 From: AkashiSN Date: Wed, 26 Jul 2023 23:05:04 +0900 Subject: [PATCH] Change the hook script (#1964) to be execute as root --- README.md | 2 +- docker-entrypoint.sh | 29 ++++++++++++++++------------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 31531767ba..aa73856896 100644 --- a/README.md +++ b/README.md @@ -216,7 +216,7 @@ To use the hooks triggered by the `entrypoint` script, either - Added your script(s) to the individual of the hook folder(s), which are located at the path `/docker-entrypoint-hooks.d` in the container - Use volume(s) if you want to use script from the host system inside the container, see example. -**Note:** Only the script(s) located in a hook folder (not sub-folders), ending with `.sh` and marked as executable, will be executed. +**Note:** Only the script(s) located in a hook folder (not sub-folders), ending with `.sh` will be executed. **Example:** Mount using volumes ```yaml diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 4c85f6ad50..a553e1862b 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -27,26 +27,29 @@ run_path() { echo "=> Searching for scripts (*.sh) to run, located in the folder: ${hook_folder_path}" if [ -z "$(ls -A "${hook_folder_path}")" ]; then - echo "==> but the hook folder \"$(basename "${hook_folder_path}")\" is empty, so nothing to do" + echo "==> but the hook folder \"$(basename "${hook_folder_path}")\" is empty, so nothing to do" return 0 fi ( for script_file_path in "${hook_folder_path}/"*.sh; do - if ! [ -x "${script_file_path}" ] && [ -f "${script_file_path}" ]; then - echo "==> The script \"${script_file_path}\" in the folder \"${hook_folder_path}\" was skipping, because it didn't have the executable flag" - continue - fi - - echo "==> Running the script (cwd: $(pwd)): \"${script_file_path}\"" - - run_as "${script_file_path}" || return_code="$?" + if [ -f "${script_file_path}" ]; then + if [ -x "${script_file_path}" ]; then + echo "==> Running the script \"${script_file_path}\" (cwd: $(pwd))." + "${script_file_path}" + return_code="$?" + else + echo "==> Found the script \"${script_file_path}\", but it didn't have the executable flag," + echo " So running the script as \`user=$user /bin/bash \"${script_file_path}\"\` (cwd: $(pwd))." + user=$user /bin/bash "${script_file_path}" + return_code="$?" + fi - if [ "${return_code}" -ne "0" ]; then - echo "==> Failed at executing \"${script_file_path}\". Exit code: ${return_code}" - exit 1 + if [ "${return_code}" -ne "0" ]; then + echo "==> Failed at executing \"${script_file_path}\". Exit code: ${return_code}." + exit 1 + fi fi - echo "==> Finished the script: \"${script_file_path}\"" done )