forked from quartiq/artiq-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·84 lines (68 loc) · 2.13 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
ARTIQ_ENV="artiq-dev"
function init_artiq_env {
source activate $ARTIQ_ENV
}
# ---------------------------------------------------------------------------------------------------------------------
# Fail on error
set -e
# ---------------------------------------------------------------------------------------------------------------------
# Process arguments
while [ 1 ]; do
case $1 in
"--uid")
shift
HOST_UID="$1"
shift
;;
"--user")
shift
HOST_USER="$1"
shift
;;
"--gid")
shift
HOST_GID="$1"
shift
;;
"--group")
shift
HOST_GROUP="$1"
shift
;;
*)
break
;;
esac
done
# ---------------------------------------------------------------------------------------------------------------------
# Install packages, if external sources are used
# Copy is made to allow RO mounts of external sources
if [ -d /migen_ext ]; then
(init_artiq_env; rsync -a /migen_ext/* /tmp/migen; cd /tmp/migen; pip install -e .)
fi
if [ -d /misoc_ext ]; then
(init_artiq_env; rsync -a /misoc_ext/* /tmp/misoc; cd /tmp/misoc; pip install -e .)
fi
if [ -d /artiq_ext ]; then
(init_artiq_env; rsync -a /artiq_ext/* /tmp/artiq; cd /tmp/artiq; pip install -e .)
fi
echo "cd /workspace" >> /.bashrc
# ---------------------------------------------------------------------------------------------------------------------
# Create user if not root
if [ "$HOST_USER" != "root" ]; then
groupadd --gid $HOST_GID $HOST_GROUP
useradd --gid $HOST_GID --uid $HOST_UID --home-dir /home/user $HOST_USER
chown -R $HOST_UID:$HOST_GID /home/user
fi
# ---------------------------------------------------------------------------------------------------------------------
# Start command or console
# No additional arguments supplied mean start console
if [ "$1" == "" ]; then
exec gosu $HOST_USER /bin/bash --rcfile /.bashrc -i
# Otherwise execute supplied arguments
else
#init_artiq_env
CMD="source /.bashrc && $@"
exec gosu $HOST_USER /bin/bash -c "$CMD"
fi