#!/bin/bash
set -euE -o pipefail -o nounset

COMMAND="/usr/sbin/dhcpoptinj --version"
# Capture the binary version using the --version option:
VERSION="$($COMMAND | grep -Po 'version\s+\K[^$]+')"
# Get upstream version from installed package:
EXPECTED_VERSION="$(dpkg-query --showformat='${source:Upstream-Version}' --show dhcpoptinj)"

# Ensure that the versions match:
if [[ "$VERSION" != "$EXPECTED_VERSION" ]]; then
	>&2 echo "ERROR: The version \"$VERSION\" output by $COMMAND does not match the expected version \"$EXPECTED_VERSION\"."
	exit 1
fi
