-
Notifications
You must be signed in to change notification settings - Fork 27
/
entry.sh
executable file
·77 lines (69 loc) · 1.65 KB
/
entry.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
# This command only works in privileged container
tmp_mount='/tmp/_balena'
mkdir -p "$tmp_mount"
if mount -t devtmpfs none "$tmp_mount" &> /dev/null; then
PRIVILEGED=true
umount "$tmp_mount"
else
PRIVILEGED=false
fi
rm -rf "$tmp_mount"
function mount_dev()
{
tmp_dir='/tmp/tmpmount'
mkdir -p "$tmp_dir"
mount -t devtmpfs none "$tmp_dir"
mkdir -p "$tmp_dir/shm"
mount --move /dev/shm "$tmp_dir/shm"
mkdir -p "$tmp_dir/mqueue"
mount --move /dev/mqueue "$tmp_dir/mqueue"
mkdir -p "$tmp_dir/pts"
mount --move /dev/pts "$tmp_dir/pts"
touch "$tmp_dir/console"
mount --move /dev/console "$tmp_dir/console"
umount /dev || true
mount --move "$tmp_dir" /dev
# Since the devpts is mounted with -o newinstance by Docker, we need to make
# /dev/ptmx point to its ptmx.
# ref: https://www.kernel.org/doc/Documentation/filesystems/devpts.txt
ln -sf /dev/pts/ptmx /dev/ptmx
mount -t debugfs nodev /sys/kernel/debug
}
function start_udev()
{
if [ "$UDEV" == "on" ]; then
if $PRIVILEGED; then
mount_dev
if command -v udevd &>/dev/null; then
unshare --net udevd --daemon &> /dev/null
else
unshare --net /lib/systemd/systemd-udevd --daemon &> /dev/null
fi
udevadm trigger &> /dev/null
else
echo "Unable to start udev, container must be run in privileged mode to start udev!"
fi
fi
}
function init()
{
# echo error message, when executable file doesn't exist.
if [ -n "$1" ]; then
if CMD=$(command -v "$1" 2>/dev/null); then
shift
exec "$CMD" "$@"
else
echo "Command not found: $1"
exit 1
fi
fi
}
UDEV=$(echo "$UDEV" | awk '{print tolower($0)}')
case "$UDEV" in
'1' | 'true')
UDEV='on'
;;
esac
start_udev
init "$@"