diff options
author | Dennis Værum <6872940+dvaerum@users.noreply.github.com> | 2023-06-22 17:06:37 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-22 16:06:37 +0000 |
commit | d3251467e6844c9742a57bacc72a682e98ae2cce (patch) | |
tree | 3bc5398e53cb23aa39f3ed2d5cb00e1860b127f4 /docker-entrypoint.sh | |
parent | ceb2893af1c4ee9bec07082c82f5b638bb47cff7 (diff) |
Added entrypoint hooks for your own custom scripts (#1964)
* Added entrypoint hooks for your own custom scripts
Signed-off-by: Dennis Vestergaard Værum <github@varum.dk>
* Small changes:
- Only execute shell-scripts (mening files ending with .sh)
- Sort the files before executing them, had forgotten 😅
- Added a message when a hook script finish
- Added prefix arror to message to show the are related
Signed-off-by: Dennis Vestergaard Værum <github@varum.dk>
* Show in the search msg that it only searches for '*.sh' files
Signed-off-by: Dennis Vestergaard Værum <github@varum.dk>
* Fixed spelling mistake
Co-authored-by: J0WI <J0WI@users.noreply.github.com>
Signed-off-by: Dennis Værum <6872940+dvaerum@users.noreply.github.com>
* Updated the `README.md` file
Signed-off-by: Dennis Vestergaard Værum <github@varum.dk>
* change from using find to using a for-loop to located the `.sh` files
Signed-off-by: Dennis Vestergaard Værum <github@varum.dk>
* Fix bug - that would make docker-entrypoint.sh failed, hook folders was empty
Signed-off-by: Dennis Vestergaard Værum <github@varum.dk>
---------
Signed-off-by: Dennis Vestergaard Værum <github@varum.dk>
Signed-off-by: Dennis Værum <6872940+dvaerum@users.noreply.github.com>
Co-authored-by: J0WI <J0WI@users.noreply.github.com>
Diffstat (limited to 'docker-entrypoint.sh')
-rwxr-xr-x | docker-entrypoint.sh | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 37441fd8..941dc3ee 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -19,6 +19,39 @@ run_as() { fi } +# Execute all executable files in a given directory in alphanumeric order +run_path() { + local hook_folder_path="/docker-entrypoint-hooks.d/$1" + local return_code=0 + + 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" + 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 [ "${return_code}" -ne "0" ]; then + echo "==> Failed at executing \"${script_file_path}\". Exit code: ${return_code}" + exit 1 + fi + + echo "==> Finished the script: \"${script_file_path}\"" + done + ) +} + # usage: file_env VAR [DEFAULT] # ie: file_env 'XYZ_DB_PASSWORD' 'example' # (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of @@ -182,6 +215,8 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP fi if [ "$install" = true ]; then + run_path pre-installation + echo "Starting nextcloud installation" max_retries=10 try=0 @@ -204,12 +239,16 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP NC_TRUSTED_DOMAIN_IDX=$((NC_TRUSTED_DOMAIN_IDX+1)) done fi + + run_path post-installation else echo "Please run the web-based installer on first connect!" fi fi # Upgrade else + run_path pre-upgrade + run_as 'php /var/www/html/occ upgrade' run_as 'php /var/www/html/occ app:list' | sed -n "/Enabled:/,/Disabled:/p" > /tmp/list_after @@ -217,6 +256,7 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP diff /tmp/list_before /tmp/list_after | grep '<' | cut -d- -f2 | cut -d: -f1 rm -f /tmp/list_before /tmp/list_after + run_path post-upgrade fi echo "Initializing finished" @@ -227,6 +267,8 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP run_as 'php /var/www/html/occ maintenance:update:htaccess' fi ) 9> /var/www/html/nextcloud-init-sync.lock + + run_path before-starting fi exec "$@" |