-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathgenerate.sh
More file actions
executable file
·47 lines (38 loc) · 1021 Bytes
/
Copy pathgenerate.sh
File metadata and controls
executable file
·47 lines (38 loc) · 1021 Bytes
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
#!/usr/bin/env bash
set -e
set -o pipefail
set -x
main() {
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <data-file.ncl> <output-file>"
exit 1
fi
local script_dir
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
cd "$script_dir" || exit 1
local data_file
data_file=$(realpath "$1")
local output_file
output_file=$(realpath "$2")
if [ ! -f "$data_file" ]; then
echo "error: data file not found: $data_file"
exit 1
fi
if [ "${data_file##*.}" != "ncl" ]; then
echo "error: expected Nickel data file (*.ncl): $data_file"
exit 1
fi
local output_dir
output_dir=$(dirname "$output_file")
if [ ! -d "$output_dir" ]; then
echo "error: output directory does not exist: $output_dir"
exit 1
fi
nickel export --format text <<Nickel > "$output_file"
let render = import "${script_dir}/template/Dockerfile.ncl" in
let {Schema} = import "${script_dir}/template/schema.ncl" in
let config = import "${data_file}" in
render (config | Schema)
Nickel
}
main "$@"