@@ -258,3 +258,49 @@ fix_capabilities() {
258
258
fi
259
259
echo " "
260
260
}
261
+
262
+ # New function to run custom initialization scripts
263
+ run_custom_init_scripts () {
264
+ local custom_init_dir=" /custom-cont-init.d"
265
+
266
+ # Check if the directory exists
267
+ if [ ! -d " $custom_init_dir " ]; then
268
+ echo " [i] Custom init directory $custom_init_dir does not exist, skipping"
269
+ return 0
270
+ fi
271
+
272
+ echo " [i] Checking for custom initialization scripts in $custom_init_dir "
273
+
274
+ # Find all executable scripts or make them executable
275
+ find " $custom_init_dir " -type f | sort | while read -r script; do
276
+ # Check if file is already executable
277
+ if [ ! -x " $script " ]; then
278
+ echo " [i] Making $script executable"
279
+ chmod +x " $script " 2> /dev/null || {
280
+ echo " [!] Failed to make $script executable, skipping"
281
+ continue
282
+ }
283
+ fi
284
+
285
+ # Extract the filename
286
+ filename=$( basename " $script " )
287
+
288
+ # Check if the filename starts with a number
289
+ if [[ " $filename " =~ ^[0-9]+ ]]; then
290
+ echo " [i] Running custom init script: $script "
291
+ # Run the script in background with output redirected to docker logs
292
+ # Use 'exec' to run in a subshell and avoid blocking
293
+ sleep 10
294
+ (exec " $script " 2>&1 | sed " s/^/[Custom Init: $filename ] /" ) &
295
+
296
+ # Store the PID in case we want to track it later
297
+ local script_pid=$!
298
+ echo " [i] Started $script with PID $script_pid "
299
+ else
300
+ echo " [i] Skipping $script , filename doesn't start with a number"
301
+ fi
302
+ done
303
+
304
+ echo " [i] Finished processing custom initialization scripts"
305
+ return 0
306
+ }
0 commit comments