-
Notifications
You must be signed in to change notification settings - Fork 2
/
docker-entrypoint.sh
executable file
·72 lines (59 loc) · 1.69 KB
/
docker-entrypoint.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
#!/bin/sh
# docker-entrypoint.sh
set -e
export MATSIM_VERSION="$(cat resources/VERSION.txt)"
_print_header() {
header_text="$(cat resources/BANNER.txt)
Environment:
$(env -0 | sort -z | tr '\0 ' '\n' | grep MATSIM | awk '{print " ", $0}')"
printf '%s\n' "$header_text"
}
_print_help_input() {
help_text_input="
Error: The input directory $MATSIM_INPUT is empty.
Use the volume flag to bind a directory with the MATSim
input files from the host to the conatiner:
docker run \\
-v <host/path/to/input>:/opt/matsim/data/input:ro \\
-v <host/path/to/output>:/opt/matsim/data/output \\
[...] \\
maptic/matsim:latest
Exiting."
printf '%s\n' "$help_text_input"
}
_print_help_output() {
help_text_output="
Error: The output directory $MATSIM_OUTPUT is not
empty. Mount an empty folder or pass the environment
variable MATSIM_OUTPUT_OVERWRITE=true to the container:
docker run \\
-e MATSIM_OUTPUT_OVERWRITE=true \\
[...] \\
maptic/matsim:latest
Exiting."
printf '%s\n' "$help_text_output"
}
_check_input_directory() {
if [ -d "$MATSIM_INPUT" ] && files=$(ls -qAH -- "$MATSIM_INPUT") && [ -z "$files" ]; then
_print_help_input
exit 1
fi
}
_check_output_directory() {
if [ -d "$MATSIM_OUTPUT" ] && files=$(ls -qAH -- "$MATSIM_OUTPUT") && [ -z "$files" ]; then
:
else
if [ $MATSIM_OUTPUT_OVERWRITE ]; then
printf '\n%s\n' "Note: Overwriting the (not empty) output directory."
rm -rf $MATSIM_OUTPUT/*
else
_print_help_output
exit 1
fi
fi
}
_print_header
_check_input_directory
_check_output_directory
printf '%s\n' ""
exec "$@"