-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathentrypoint.sh
executable file
·61 lines (59 loc) · 1.65 KB
/
entrypoint.sh
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
set -e
check() {
if ! test -w /proc/sys/fs/binfmt_misc/register; then
# kernel facility not already available; hope it's a module that we can force to be loaded
mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc || true
fi
if ! test -w /proc/sys/fs/binfmt_misc/register; then
# kernel facility still not available; hope it's a module that we could force to be loaded
echo No /proc/sys/fs/binfmt_misc/register in container. Please \`modprobe binfmt_misc\` and run with --privileged.
exit 1
fi
}
register() {
for binfmt in /usr/lib/binfmt.d/* ; do
name=$(cut -f2 -d: ${binfmt})
binary=$(cut -f7 -d: ${binfmt})
echo -n "${name}: "
if test -r /proc/sys/fs/binfmt_misc/${name} ; then
# clear previous registration
echo -n -1 > /proc/sys/fs/binfmt_misc/${name}
fi
if test -n "${BINDIR}" ; then
# optionally copy this binary to a volume
install -v "${binary}" "${BINDIR}/"
fi
if test -n "${CHCON}" ; then
# optionally try to relabel the binary
chcon -v ${CHCON} "${BINDIR:-/usr/bin}/${binary##*/}" || :
fi
sed "s#/usr/bin#${BINDIR:-/usr/bin}#g" ${binfmt} > /proc/sys/fs/binfmt_misc/register && echo ok
done
}
unregister() {
for binfmt in /usr/lib/binfmt.d/* ; do
name=$(cut -f2 -d: ${binfmt})
echo -n "${name}: "
echo -n -1 > /proc/sys/fs/binfmt_misc/${name} && echo ok
done
}
IMAGE=${IMAGE:-IMAGE}
runtime='$RUNTIME'
if test -f /run/.containerenv; then
runtime=podman
elif test -f /.dockerenv; then
runtime=docker
fi
case "$1" in
register)
check && register
;;
unregister)
check && unregister
;;
*)
check
echo "usage: ${runtime} run --rm --privileged ${IMAGE} register | unregister"
;;
esac