1#!/usr/bin/env bash
2# SPDX-License-Identifier: LGPL-2.1-or-later
3set -ex
4
5if [[ -n "$1" ]]; then
6    generator=$1
7elif [[ -x /usr/lib/systemd/systemd-network-generator ]]; then
8    generator=/usr/lib/systemd/systemd-network-generator
9elif [[ -x /lib/systemd/systemd-network-generator ]]; then
10    generator=/lib/systemd/systemd-network-generator
11else
12    exit 1
13fi
14
15src="$(dirname "$0")/testdata/test-network-generator-conversion"
16
17for f in "$src"/test-*.input; do
18    echo "*** Running $f"
19
20    (
21        out=$(mktemp --tmpdir --directory "test-network-generator-conversion.XXXXXXXXXX")
22        # shellcheck disable=SC2064
23        trap "rm -rf '$out'" EXIT INT QUIT PIPE
24
25        # shellcheck disable=SC2046
26        $generator --root "$out" -- $(cat "$f")
27
28        if ! diff -u "$out/run/systemd/network" "${f%.input}.expected"; then
29            echo "**** Unexpected output for $f"
30            exit 1
31        fi
32    ) || exit 1
33done
34