-
Notifications
You must be signed in to change notification settings - Fork 3
/
idea.sh
executable file
·92 lines (77 loc) · 2.89 KB
/
idea.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
85
86
87
88
89
90
91
#!/usr/bin/env bash
# Launches IntelliJ IDEA inside a Docker container
# IDEA_IMAGE=${1:-kurron/docker-intellij:latest}
DOCKER=docker
if [ -x "$(command -v nvidia-docker)" ]; then
DOCKER=nvidia-docker
fi
echo "DOCKER cmd is $DOCKER"
DOCKER_GROUP_ID=$(cut -d: -f3 < <(getent group docker))
USER_ID=$(id -u "$(whoami)")
GROUP_ID=$(id -g "$(whoami)")
HOME_DIR=$(cut -d: -f6 < <(getent passwd "${USER_ID}"))
#
# Fixme: this is unsafe if building image within
# the container the container, as you get $HOME_DIR/DevContainerHome/DevContainerHome
#
HOME_DIR_HOST="$HOME_DIR/DevContainerHome"
WORK_DIR=${WORK_DIR:="$HOME_DIR/workspace"}
WORK_DIR_AUX=${WORK_DIR_AUX:="$HOME_DIR/workspaceAux"}
if [ ! -d "${WORK_DIR_AUX}" ]; then
WORK_DIR_AUX=${WORK_DIR}
fi
echo "WORK_DIR is ${WORK_DIR}"
echo "WORK_DIR_AUX is ${WORK_DIR_AUX}"
#
# Create sync config dir owned by user if not already
#
mkdir -p "${HOME_DIR_HOST}/.config/syncthing"
# Need to give the container access to your windowing system
# Further reading: http://wiki.ros.org/docker/Tutorials/GUI
# and http://gernotklingler.com/blog/howto-get-hardware-accelerated-opengl-support-docker/
export DISPLAY=${DISPLAY:=":0"}
xhost +
PULL="docker pull ${IDEA_IMAGE}"
echo "${PULL}"
"${PULL}"
CMD="${DOCKER} run --detach=true \
--privileged \
--group-add ${DOCKER_GROUP_ID} \
--env HOME=${HOME_DIR} \
--env DISPLAY \
--interactive \
--name DevContainer \
--net=host \
--rm \
--tty \
--user=${USER_ID}:${GROUP_ID} \
--volume /usr/local/MATLAB/R2017b:/opt/MATLAB \
--volume $HOME_DIR_HOST:${HOME_DIR} \
--volume $WORK_DIR:${WORK_DIR} \
--volume $WORK_DIR_AUX:${WORK_DIR_AUX} \
--volume /tmp/.X11-unix:/tmp/.X11-unix \
--volume /var/run/docker.sock:/var/run/docker.sock \
--volume /dev/snd:/dev/snd \
--volume /dev/shm:/dev/shm \
--volume /etc/machine-id:/etc/machine-id \
--volume /run/user/$USER_ID/pulse:/run/user/$USER_ID/pulse \
--volume /var/lib/dbus:/var/lib/dbus \
--volume $HOME_DIR_HOST/.pulse:$HOME_DIR/.pulse \
${IDEA_IMAGE}"
#
# TODO: dbus:
#
# --volume /var/run/dbus/system_bus_socket:/run/dbus/system_bus_socket \
echo "$CMD"
CONTAINER=$($CMD)
# Minor post-configuration
sleep 1s
docker exec --user=root "$CONTAINER" groupadd -g "$DOCKER_GROUP_ID" docker
WHO_AM_I=$(docker exec --user="$USER_ID" "$CONTAINER" whoami)
echo "whoami is ${WHO_AM_I}"
#DBUS_UUID=$(docker exec "$CONTAINER" /bin/bash -i -c 'dbus-uuidgen')
#docker exec --user=root "$CONTAINER" bash -c "chmod u+w /etc/machine-id && \
# echo ${DBUS_UUID} > /etc/machine-id && \
# chmod u-w /etc/machine-id
#"
docker attach "$CONTAINER"