-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrun.sh
77 lines (67 loc) · 1.69 KB
/
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
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
set -e
set -u
SCRIPTROOT="$( cd "$(dirname "\$0")" ; pwd -P )"
PROJECTNAME=$(basename "$(cd "$(dirname "\$0")"; cd ..; pwd -P)" | tr '[:upper:]' '[:lower:]')
HOMENAME=$(basename $HOME)
display_flag=""
gpus=""
usage() {
echo "Usage: bash $0 -g <gpus> -d <true/false>" 1>&2
exit 1
}
while getopts "g:d:" opt; do
case $opt in
g)
gpus=$OPTARG
;;
d)
display_flag=$OPTARG
;;
?)
usage
exit 1
;;
esac
done
shift $(( $OPTIND - 1 ))
errors=""
if [ -z "$gpus" ]; then
errors+="GPUs parameter is required.\n"
elif ! [[ "$gpus" =~ ^[1-9]+$ ]] && [ "$gpus" != "all" ]; then
errors+="Invalid GPUs parameter. Must be a numeric value or 'all'.\n"
fi
if [ -z "${display_flag}" ]; then
errors+="Display parameter is required.\n"
fi
if [ -n "$errors" ]; then
echo -e "$errors" >&2
usage
else
echo -e "Use Docker Image: $PROJECTNAME"
echo -e "Start Docker Container: ${PROJECTNAME}_container"
echo -e "Use GPU: $gpus"
echo -e "Use Display: $display_flag\n"
fi
if [ "$display_flag" = true ]; then
export DISPLAY=$DISPLAY
echo "Setting display to $DISPLAY"
xhost +
docker run -it --rm \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-v /home/${HOMENAME}/.Xauthority:/root/.Xauthority \
-e DISPLAY=$DISPLAY \
-v ${SCRIPTROOT}/..:/home/root/rl_ws \
--network=host \
--gpus="${gpus}" \
--name="${PROJECTNAME}_container" \
${PROJECTNAME} /home/root/rl_ws/rl_docker/setup.sh
else
echo "Running Docker without display"
docker run -it --rm \
-v ${SCRIPTROOT}/..:/home/root/rl_ws \
--network=host \
--gpus="${gpus}" \
--name="${PROJECTNAME}_container" \
${PROJECTNAME} /home/root/rl_ws/rl_docker/setup.sh
fi