#!/bin/sh
# Fix .desktop files to be compliant with XDG specification

if [ -z "$RPM_BUILD_ROOT" ]; then
	printf '%s\n' "No build root defined" >&2
	exit 1
fi

if [ ! -d "$RPM_BUILD_ROOT" ]; then
	printf '%s\n' "Invalid build root" >&2
	exit 1
fi

# Find .desktop files
find "$RPM_BUILD_ROOT" -name "*.desktop" -type f -print | while read f; do
	# Add trailing semicolons to lines starting with 'Actions=' or 'MimeType='
	# if these lines do not end with '='
	sed -i 's/^\(Actions=.*\|MimeType=.*\|OnlyShowIn=.*\|Categories=.*\)\([[:alnum:]]\)[[:space:]]*$/\1\2;/' "$f"
done
