#!/usr/bin/env bash

set -euo pipefail

repo_root=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)
tool_dir="$repo_root/plasma-always-show-unlock"
topdir="$repo_root/rpmbuild"

mkdir -p "$topdir"/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}
install -m 0755 \
    "$tool_dir/plasma-always-show-unlock" \
    "$topdir/SOURCES/plasma-always-show-unlock"
install -m 0644 \
    "$tool_dir/LockScreenUi.patch" \
    "$topdir/SOURCES/LockScreenUi.patch"
install -m 0755 \
    "$tool_dir/tests/test-plasma-always-show-unlock" \
    "$topdir/SOURCES/test-plasma-always-show-unlock"
install -m 0644 \
    "$tool_dir/tests/LockScreenUi.qml" \
    "$topdir/SOURCES/LockScreenUi.qml"
install -m 0644 "$repo_root/LICENSE" "$topdir/SOURCES/LICENSE"
install -m 0644 "$repo_root/README.md" "$topdir/SOURCES/README.md"
install -m 0644 "$tool_dir/FedoraToolsFingerprintRetry.qml" "$topdir/SOURCES/FedoraToolsFingerprintRetry.qml"
install -m 0644 "$tool_dir/tests/tst_fingerprintretry.qml" "$topdir/SOURCES/tst_fingerprintretry.qml"

rpmbuild \
    --define "_topdir $topdir" \
    -bb "$tool_dir/plasma-always-show-unlock.spec"
