44
55# Generates osguard image configurations by merging base + delta YAML templates.
66# Usage:
7- # ./generate_osguard_configs.sh
7+ # ./generate-osguard-imageconfigs.sh
8+ # ./generate-osguard-imageconfigs.sh test
9+ # test: generate into a temporary directory and compare with the default
10+ # committed file, failing if they differ (ignores the '# Sources:' header).
811#
912# Optional env:
1013# PYTHON - Python executable to use (default: python3)
@@ -16,6 +19,10 @@ set -euo pipefail
1619
1720PYTHON_BIN=${PYTHON:- python3}
1821
22+ # Default output directory (relative to this script's CWD)
23+ OUT_DIR_DEFAULT=" ../imageconfigs"
24+
25+
1926# Ensure merge_yaml.py is available in the current directory
2027if [[ ! -f ./merge_yaml.py ]]; then
2128 echo " Error: merge_yaml.py not found in the current directory." >&2
2633BASE_TPL=" ../imageconfigs/templates/osguard-base.yaml"
2734DELTA_TPL=" ../imageconfigs/templates/osguard-no-ci-delta.yaml"
2835
29- OUT_STD=" ../imageconfigs/osguard-amd64.yaml"
36+ run_generate () {
37+ local out_dir=" $1 "
38+ mkdir -p " $out_dir "
39+ local out_std=" $out_dir /osguard-amd64.yaml"
40+ echo " Generating osguard configs..."
41+ echo " Output directory: $out_dir "
42+ " $PYTHON_BIN " ./merge_yaml.py " $BASE_TPL " " $DELTA_TPL " -o " $out_std "
43+ echo " Done. Wrote:"
44+ echo " $out_std "
45+ }
46+
47+ run_test () {
48+ echo " Running test: generate into temp dir and compare with default (ignoring '# Sources:' header)"
49+ local tmp_out_dir
50+ tmp_out_dir=" $( mktemp -d) "
51+ run_generate " $tmp_out_dir "
52+
53+ local generated_file default_file
54+ generated_file=" $tmp_out_dir /osguard-amd64.yaml"
55+ default_file=" ../imageconfigs/osguard-amd64.yaml"
56+
57+ echo " Comparing:"
58+ echo " Generated: $generated_file "
59+ echo " Default: $default_file "
60+
61+ # Filter out the variable header line that lists source paths
62+ local filt_gen filt_def
63+ filt_gen=" $( mktemp) "
64+ filt_def=" $( mktemp) "
65+ grep -v ' ^# Sources:' " $generated_file " > " $filt_gen "
66+ grep -v ' ^# Sources:' " $default_file " > " $filt_def "
67+
68+ if ! diff -u " $filt_gen " " $filt_def " ; then
69+ echo " Error: Generated osguard imageconfig differs from the committed default." >&2
70+ exit 1
71+ fi
72+ echo " Success: Generated osguard imageconfig matches the committed default."
73+ }
3074
31- echo " Generating osguard configs..."
32- " $PYTHON_BIN " ./merge_yaml.py " $BASE_TPL " " $DELTA_TPL " -o " $OUT_STD "
75+ main () {
76+ case " ${1:- } " in
77+ " " )
78+ run_generate " $OUT_DIR_DEFAULT "
79+ ;;
80+ test|--test )
81+ run_test
82+ ;;
83+ * )
84+ echo " Usage: $0 [test]" >&2
85+ exit 2
86+ ;;
87+ esac
88+ }
3389
34- echo " Done. Wrote:"
35- echo " $OUT_STD "
90+ main " $@ "
0 commit comments