Skip to content

Commit

Permalink
Change the hook script (nextcloud#1964) to be execute as root
Browse files Browse the repository at this point in the history
  • Loading branch information
AkashiSN committed Jul 26, 2023
1 parent 7bd3b7b commit 4e04e5b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 16 additions & 13 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down

0 comments on commit 4e04e5b

Please sign in to comment.