-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.sh
More file actions
executable file
·47 lines (37 loc) · 1.23 KB
/
entrypoint.sh
File metadata and controls
executable file
·47 lines (37 loc) · 1.23 KB
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
41
42
43
44
45
46
47
#!/bin/bash
set -euo pipefail
script_executable=${ACTION_EXEC:-bash}
interactive_executable=${INTERACTIVE_EXEC:-$script_executable}
is_real_executable() {
local path shebang
path="$(which "$1")"
# check for shebang
IFS= LC_ALL=C read -rn2 -d '' shebang < "$path"
if test "$shebang" = "#!"; then
return 0
fi
# check for binfmt
if file -L "$path" | grep -q ELF; then
return 0
fi
return 1
}
if test -n "${1:-}"; then
# we have arguments, so default to executing a file
executable=$script_executable
# However, check if the first argument is a valid executable, and use that instead.
# This allows a pattern of `docker run image exec` to run whatever excuteable you want.
if command -v -- "$1" >/dev/null 2>&1; then
# on windows, all files have executable mask, so check it is actually executable
if is_real_executable "$1"; then
# special case - the user has provided their own valid executable as
# the first argument, so switch to executing that
executable=$1
shift
fi
fi
else
# no arguments - we want the interactive executable
executable=$interactive_executable
fi
exec "$executable" "$@"