#!/bin/bash
pushd "${BASH_SOURCE%/*}" > /dev/null;
dirName="$(pwd)";
contextRoot="$(mktemp -d)";
pushd "$contextRoot" > /dev/null;

pkgName="logo-ls";
patchName="workaround.patch";

yay -G -f "$pkgName";
cd "$pkgName";
cp "$dirName/$patchName" .;

sed -i \
    -e "/^source=(/s/source=(/\0$patchName /" \
    -e "/^md5sums=(/s/^md5sums=(/\0SKIP /" \
    -e "/^build() {/,/}/{" \
        -e "/^[[:space:]]*cd/{" \
            -e "a cat ../$patchName | patch --strip 1 --forward --merge" \
        -e "}" \
    -e "}" \
    PKGBUILD;

makepkg --noconfirm -si --force;

popd > /dev/null;
rm -rf "$contextRoot";

. "../../../Common/Config/logo-ls/install.sh";
popd > /dev/null;