#!/bin/bash
set -eu

if [ "${BUILD_DIST+x}" != "x" ]; then
	echo "Not running in an OBS build container"
	exit 1
fi

BUILD_DATA="${BUILD_DIST/.dist/.data}"
if [ -r "$BUILD_DATA" ]; then
	. "${BUILD_DATA}"
fi

for file in *.kiwi; do
	if ! xsltproc /usr/lib/kiwi_label_helper/label_helper.xsl "$file" > "$file.new"; then
		rm "$file.new"
		echo "xsltproc failed"
		exit 1
	fi
	mv -f "$file.new" "$file"
done

