# enter build directory manually
# because goreleaser needs git directory to be clean
cd "$SRCDIR"/trivy

abinfo "Building trivy ..."
# FIXME: trivy does not build simply with normal "go build"
#        use autobuild gomod template, drop goreleaser build-dep,
#        drop SUBDIR and drop copy-repo once goreleaser can be dropped
goreleaser build --single-target

abinfo "Installing trivy ..."
install -Dvm644 "$SRCDIR"/trivy/dist/*/trivy \
    "$PKGDIR"/usr/bin/trivy
chmod -v +x "$PKGDIR"/usr/bin/trivy

abinfo "Installing default templates ..."
mkdir -vp "$PKGDIR"/usr/share/trivy/templates
cp -v "$SRCDIR"/trivy/contrib/*.tpl \
    "$PKGDIR"/usr/share/trivy/templates
