-
Notifications
You must be signed in to change notification settings - Fork 1
/
bootstrap.sh
executable file
·140 lines (105 loc) · 2.43 KB
/
bootstrap.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
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
#!/bin/bash
# Bootstrap script needed to launch the environement
#
DOCKER_IMAGE=benediction/barbarism
DSK_TEST=./barbarism.dsk
# OS detection code
UNAME=$(uname -s)
DETECTED_OS=linux
if test "$(expr substr $(uname -s) 1 5)" == "MINGW"
then
DETECTED_OS=windows
fi
# Sadly, there are some differences between windows and linux
case $DETECTED_OS in
linux)
LOCAL_WORKING_DIRECTORY=$(pwd)
DOCKER_WORKING_DIRECTORY=/home/arnold/project
DOCKER_X11_FORWARDING="-e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix --privileged"
;;
windows)
LOCAL_WORKING_DIRECTORY=/$(pwd)
DOCKER_WORKING_DIRECTORY=//home/arnold/project
DOCKER_X11_FORWARDING=""
;;
esac
DOCKER=docker
DOCKER_HOSTNAME=$(basename $(pwd))
function buildImage
{
$DOCKER build -t $DOCKER_IMAGE .
}
function launchImage
{
# create the image if it does not exists
if test "$($DOCKER images -q $DOCKER_IMAGE 2> /dev/null)" = ""
then
buildImage
fi
# Manage parameters for aft
# XXX Implement a better and more robust way to do things ...
case $DETECTED_OS in
linux) AFT_PORT=/dev/ttyUSB0 ;;
windows) AFT_PORT=/dev/ttyS3 ;;
esac
if test -e "$AFT_PORT"
then
AFT_OPTION="--device $AFT_PORT"
else
echo "aft unusable ($AFT_PORT does not exists)" >&2
AFt_OPTION=""
fi
ALL_OPTIONS=" -h $DOCKER_HOSTNAME
-v $LOCAL_WORKING_DIRECTORY:$DOCKER_WORKING_DIRECTORY
-w $DOCKER_WORKING_DIRECTORY
$DOCKER_X11_FORWARDING
$DOCKER_AFT_OPTION
$AFT_OPTION
--rm=true
-i
-t
$DOCKER_IMAGE
$*"
# launch the image
echo Use these options: "$ALL_OPTIONS"
$DOCKER run $ALL_OPTIONS
}
function removeImage
{
$DOCKER rmi $DOCKER_IMAGE
}
function doHelp
{
echo "$1 [help | rebildImage | removeImage | launchImage | <cmd ...>]"
echo -e '\thelp: display help'
echo -e '\trebuildImage: reconstruct the Docker image'
echo -e '\tremoveImage: delete the Docker image'
echo -e '\tlaunchImage: launch the docker image and provides a prompt'
echo -e '\ttest: launch an emulator on the result'
echo -e '\t<cmd ...>: execute the command on the docker image'
echo
echo The operation launchImage is operated if no option is given
}
function launch
{
xdg-open $DSK_TEST
}
case "$1" in
rebuildImage)
buildImage
;;
removeImage)
removeImage
;;
help)
doHelp $0
;;
test)
launch
;;
"")
launchImage
;;
*)
launchImage $*
esac