@@ -19,6 +19,39 @@ run_as() {
1919 fi
2020}
2121
22+ # Execute all executable files in a given directory in alphanumeric order
23+ run_path () {
24+ local hook_folder_path=" /docker-entrypoint-hooks.d/$1 "
25+ local return_code=0
26+
27+ echo " => Searching for scripts (*.sh) to run, located in the folder: ${hook_folder_path} "
28+
29+ if [ -z " $( ls -A " ${hook_folder_path} " ) " ]; then
30+ echo " ==> but the hook folder \" $( basename " ${hook_folder_path} " ) \" is empty, so nothing to do"
31+ return 0
32+ fi
33+
34+ (
35+ for script_file_path in " ${hook_folder_path} /" * .sh; do
36+ if ! [ -x " ${script_file_path} " ] && [ -f " ${script_file_path} " ]; then
37+ echo " ==> The script \" ${script_file_path} \" in the folder \" ${hook_folder_path} \" was skipping, because it didn't have the executable flag"
38+ continue
39+ fi
40+
41+ echo " ==> Running the script (cwd: $( pwd) ): \" ${script_file_path} \" "
42+
43+ run_as " ${script_file_path} " || return_code=" $? "
44+
45+ if [ " ${return_code} " -ne " 0" ]; then
46+ echo " ==> Failed at executing \" ${script_file_path} \" . Exit code: ${return_code} "
47+ exit 1
48+ fi
49+
50+ echo " ==> Finished the script: \" ${script_file_path} \" "
51+ done
52+ )
53+ }
54+
2255# usage: file_env VAR [DEFAULT]
2356# ie: file_env 'XYZ_DB_PASSWORD' 'example'
2457# (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
182215 fi
183216
184217 if [ " $install " = true ]; then
218+ run_path pre-installation
219+
185220 echo " Starting nextcloud installation"
186221 max_retries=10
187222 try=0
@@ -204,19 +239,24 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP
204239 NC_TRUSTED_DOMAIN_IDX=$(( NC_TRUSTED_DOMAIN_IDX+ 1 ))
205240 done
206241 fi
242+
243+ run_path post-installation
207244 else
208245 echo " Please run the web-based installer on first connect!"
209246 fi
210247 fi
211248 # Upgrade
212249 else
250+ run_path pre-upgrade
251+
213252 run_as ' php /var/www/html/occ upgrade'
214253
215254 run_as ' php /var/www/html/occ app:list' | sed -n " /Enabled:/,/Disabled:/p" > /tmp/list_after
216255 echo " The following apps have been disabled:"
217256 diff /tmp/list_before /tmp/list_after | grep ' <' | cut -d- -f2 | cut -d: -f1
218257 rm -f /tmp/list_before /tmp/list_after
219258
259+ run_path post-upgrade
220260 fi
221261
222262 echo " Initializing finished"
@@ -227,6 +267,8 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP
227267 run_as ' php /var/www/html/occ maintenance:update:htaccess'
228268 fi
229269 ) 9> /var/www/html/nextcloud-init-sync.lock
270+
271+ run_path before-starting
230272fi
231273
232274exec " $@ "
0 commit comments