#!/bin/bash

# Maintainer: The EndeavourOS team (endeavouros.com)

# Latest yad release with a patch (if needed).

_yad-eos_prepare() {
    local curdir="$PWD"
    local suffix=_eos

    rm -rf /tmp/yad

    pushd /tmp >/dev/null || exit 1
    yay -G yad >/dev/null || exit 1

    pushd yad >/dev/null
    sed -i PKGBUILD -e "/autoreconf -ivf/i \  # patch for the dialog height issue\n  patch -u src/main.c -i '$curdir'/yad-github-issue-107.patch\n"

    local pkgver_orig="$(grep ^pkgver= PKGBUILD | cut -d'=' -f2)"
    sed -E -i PKGBUILD -e "s|^([ ]*cd[ ]+\"[^-]+-).*|\1$pkgver_orig\"|"

    source PKGBUILD

    source+=($url/yad-github-issue-107.patch)    # add the patch file to 'source'
    pkgver+="$suffix"                            # update pkgver because of this patch
    conflicts=(yad yad-git)
    provides=(yad)
    replaces=(yad-eos)                           # Former patched yad package was called 'yad-eos'.
    arch+=('aarch64' 'armv7h')                   # Add architectures

    popd >/dev/null
    popd >/dev/null
}

_yad-eos_prepare
unset -f _yad-eos_prepare

sha256sums=('dde047a915cd8d3892c32b6ba031876f5cda673e01882c99613f043867c88133'
            '9af007ad9472afc9fa24e753b30ce7b91cf2e73a37a0074a64ae01979010b30f')
sha512sums=('c2949846d9d6c34bc0c8f482a5b30fb978865308bcafe656694d8eb1bb903e9af76f9d3cdd748ecb0dac389e1a0204a15b10ab29b99262cdeffc44ed16ce902e'
            '058d6b762e14dee5a81e23199e0a70634e496994f3de456ed0cc3ed827c2de669e2a6e66f284c54323d6f8d7a5efcd758259657ac48da154a956812b5119d827')

