forked from crashcoredump/docker-vlm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dvlm
executable file
·151 lines (130 loc) · 3.9 KB
/
dvlm
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/env bash
#
# -*- mode: shell; -*-
#
################################################################
#
# This script is meant to be a wrapper around running
# Symbolics VLM under Docker.
#
# See 'dvlm -h' for help.
#
################################################################
function usage() {
cat <<end-of-message
Usage: dvlm build [-s <dir>] [-g <dir>] [-w <file>]
dvlm run
-h This help.
-s <dir> Set directory under which sys.sct can be found.
e.g. '-s /home/user/files' if sys.sct is under
/home/user/files/sys.sct. If this argument is
omitted, the default bundled sys.sct files will be
used.
-g <file> Set the path to an executable 'genera' on the local
host. If this argument is omitted, the default bundled
executable will be used instead.
-w <file> Run genera with the specified world load file from the host.
EXAMPLE: dvlm build -s ~/sources/ -g ~/vlm/genera -w ~/worlds/Genera-8-5.vlod
dvlm run
end-of-message
}
IMAGE="docker-vlm"
CONTAINER="docker-vlm"
SYSSCT=
DOPTS=
WORLD=Genera-8-5-A.vlod
OS='unknown'
unamestr=`uname`
if [[ "$unamestr" == 'Linux' ]] ; then
platform='linux'
elif [[ "$unamestr" == 'Darwin' ]] ; then
platform='darwin'
else
echo "Unknown platform '$unamestr'. Can't run." >&2
exit 1
fi
CMD=$1; shift
while getopts ":i:s:g:c:l:w:h" opt; do
case $opt in
s)
echo "Will use directory $OPTARG to find sys.sct"
DOPTS="$DOPTS -v $OPTARG:/var/lib/symbolics:rw"
;;
g)
dir=`dirname $OPTARG`
echo "Will use directory $dir to find genera binary"
DOPTS="$DOPTS -v $dir:/home/genera/bin:rw"
;;
w)
world=`basename $OPTARG`
dir=`dirname $OPTARG`
echo "Will use vload named $world from directory $dir"
DOPTS="$DOPTS -v $dir:/home/genera/worlds:rw"
WORLD=$world
;;
h)
usage
exit 1
;;
\?)
echo "Invalid option: -$OPTARG" >&2
;;
:)
echo "Option -$OPTARG requires an argument" >&2
;;
esac
done
#### Verify that /tmp/.X11-unix exists.
if [[ $platform == 'linux' ]] ; then
if [ ! -d /tmp/.X11-unix ] ; then
echo "*** ERROR: Can't find X11 socket directory /tmp/.X11-unix" >&2
exit 1
fi
fi
function dobuild {
#### Verify that a container for the image exists
local dobuild=0
if docker ps -a --format="{{.Image}}" | grep -q $IMAGE ; then
echo -n "WARNING: Container already exists. Overwrite? [y/n] "
read yn
if [ $yn = "y" ] ; then
docker kill docker-vlm > /dev/null 2>&1
docker rm docker-vlm > /dev/null 2>&1
dobuild=1
fi
else
dobuild=1
fi
if [ $dobuild -eq 1 ] ; then
echo "Creating docker container ${CONTAINER}"
if [ $platform = 'linux' ] ; then
docker create -ti --privileged -P $DOPTS \
-e "DISPLAY" \
-e "WORLD=$WORLD" \
-v "/tmp/.X11-unix/:/tmp/.X11-unix/:rw" \
--name $CONTAINER $IMAGE
elif [ $platform = 'darwin' ] ; then
docker create -ti --privileged -P $DOPTS \
-e "WORLD=$WORLD" \
-p 5901:5901 \
--entrypoint /home/genera/run-vnc.sh \
--name $CONTAINER $IMAGE
fi
fi
}
function dorun() {
# Make sure an image exists
if docker ps -a --format="{{.Image}}" | grep -q $IMAGE ; then
docker start -ai $CONTAINER
else
echo "No container found. Run 'dvlm build' first." >&2
fi
}
if [ "$CMD" = 'run' ] ; then
dorun
elif [ "$CMD" = 'build' ] ; then
dobuild
else
usage
exit 1
fi