Repository navigation
Expand file tree
/
Copy pathgenerate.sh
More file actions
executable file
·139 lines (124 loc) · 3.15 KB
/
Copy pathgenerate.sh
File metadata and controls
executable file
·139 lines (124 loc) · 3.15 KB
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
#!/bin/bash
# Place ourselves in script directory
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
cd "$SCRIPT_DIR" || exit
# Check if JAVA_CMD is set, if not, set it to java
JAVA_CMD=${JAVA_CMD:-java}
JAR_PATH=./target/voxatile.jar
PARAMS_DIR=./examples
FORMATS_DIR=$PARAMS_DIR/formats
PROCESSES_DIR=$PARAMS_DIR/processes
PLACES_DIR=$PARAMS_DIR/places
list_yaml_files() {
find "$1" -name '*.yaml' -exec basename {} ".yaml" \; | sed -r "s/^/$2/"
}
usage() {
echo "$0 [options] <format> <process> <place> [<outputdir>]"
echo "available options:"
echo "-g Stops before generation"
echo "-s Stops before saving"
echo "-y Display Yaml configuration only"
echo "formats:"
list_yaml_files $FORMATS_DIR "\t"
echo "processes:"
list_yaml_files $PROCESSES_DIR "\t"
echo "places:"
list_yaml_files $PLACES_DIR "\t"
echo "outputdir is required if no option given (if directory exists, it will be emptied)"
}
output_dir_needed=1
voxatile_opt=""
while [[ "$1" == "-"* ]]; do
opt=$1
shift
case $opt in
-g)
voxatile_opt="$voxatile_opt --generation-disabled"
;;
-s)
voxatile_opt="$voxatile_opt --save-disabled"
unset output_dir_needed
;;
-y)
display_only=1
unset output_dir_needed
;;
-l)
case $1 in
formats)
list_yaml_files $FORMATS_DIR
;;
processes)
list_yaml_files $PROCESSES_DIR
;;
places)
list_yaml_files $PLACES_DIR
;;
*)
echo "Unknown -l option $1"
usage
exit 1
;;
esac
exit 0
;;
*)
echo "Unknown option $opt"
usage
exit 1
;;
esac
done
if [ $output_dir_needed ]; then
nargs=4
else
nargs=3
fi
if [[ $# -ne $nargs ]]; then
usage
exit 1
fi
format="$FORMATS_DIR/$1.yaml"
if [ ! -f "$format" ]; then
echo "Format '$1' is incorrect!"
usage
exit 1
fi
process="$PROCESSES_DIR/$2.yaml"
if [ ! -f "$process" ]; then
echo "Process '$2' is incorrect!"
usage
exit 1
fi
place="$PLACES_DIR/$3.yaml"
if [ ! -f "$place" ]; then
echo "Place '$3' is incorrect!"
usage
exit 1
fi
if [ $output_dir_needed ]; then
output_dir="$4"
if [ -d "$output_dir" ]; then
if ! rm -r "$output_dir"; then
echo "Could not delete directory $output_dir"
exit 1
fi
fi
if [ -e "$output_dir" ]; then
echo "$output_dir is not a directory"
exit 1
fi
if ! mkdir -p "$output_dir"; then
echo "Could create directory $output_dir"
exit 1
fi
output_dir=$(realpath "$output_dir")
fi
params=$({
cat "$format"; echo; cat "$process"; echo; cat "$place"
})
if [ "$display_only" ]; then
echo "$params"
exit 0
fi
VOXATILE_PARAMS=$params VOXATILE_MODULES_PATH=modules $JAVA_CMD -jar $JAR_PATH $voxatile_opt "$output_dir"