forked from LasseRafn/ui-avatars
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-with-entrypoint
executable file
·40 lines (32 loc) · 1.06 KB
/
run-with-entrypoint
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env bash
set -euo pipefail
usage() {
echo "Usage: $0 <entrypoint_script> <command_to_execute> [args...]"
echo
echo "Arguments:"
echo " <entrypoint_script> Path to the entrypoint script."
echo " <command_to_execute> Command to run after the entrypoint script."
echo " [args...] Optional arguments for the command."
echo
echo "Example:"
echo " $0 ./bin/docker-entrypoint-prod bundle exec sidekiq -C config/sidekiq/combined_workers.yml"
exit 1
}
if [ "$#" -lt 2 ]; then
echo "Error: Invalid number of arguments."
usage
fi
ENTRYPOINT_SCRIPT="$1"
shift
COMMAND_TO_EXECUTE=("$@")
if [ ! -f "$ENTRYPOINT_SCRIPT" ]; then
echo "Error: Entrypoint script '$ENTRYPOINT_SCRIPT' does not exist."
exit 1
fi
if [ ! -x "$ENTRYPOINT_SCRIPT" ]; then
echo "Entrypoint script '$ENTRYPOINT_SCRIPT' is not executable. Adding execute permissions."
chmod +x "$ENTRYPOINT_SCRIPT"
fi
echo "Running entrypoint script: $ENTRYPOINT_SCRIPT"
echo "Executing command: ${COMMAND_TO_EXECUTE[*]}"
exec "$ENTRYPOINT_SCRIPT" "${COMMAND_TO_EXECUTE[@]}"