-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun.sh
executable file
·39 lines (30 loc) · 967 Bytes
/
run.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
#!/usr/bin/env bash
ERROR_PREFIX="ERROR:"
if [[ ! -z `which docker` ]]
then
echo "Docker found." >&2
DOCKER_CMD=docker
else
echo "${ERROR_PREFIX} docker not found. Aborting." >&2
exit 1
fi
DIRECTORY=$1
if [ ! -d "$DIRECTORY" ]; then
echo "${ERROR_PREFIX} Directory '${DIRECTORY}' doesn't exist. Aborting." >&2
exit 2
fi
image_tag="cig2017_`basename $DIRECTORY`"
container_name=${image_tag}
run_version=0
while [[ ! -z `docker ps --format '{{.Names}}'|grep "^${container_name}$"` ]]
do
echo "WARNING: '${container_name}' is already a running docker container. Trying to run '${image_tag}_${run_version}'."
run_version=$(($run_version+1))
container_name=${image_tag}_${run_version}
done
if [ "`uname`" != "Linux" ]; then
echo "WARNING: GUI forwarding in Docker was tested only on a linux host."
fi
$DOCKER_CMD run --net=host -ti --rm --name ${container_name} \
--env="DISPLAY" --privileged \
${image_tag} "${@:2}"