#!/bin/bash

status=0

makepkg --syncdeps --asdeps --needed --noconfirm --clean --cleanbuild --force

status=$(( $status + $? ))

for i in *.pkg.tar.zst;
do
    if [ -f "${i}" ]; then
        echo "Удаление подписи $i.sig"
        rm -f $i.sig
        echo "Добавление подписи $i.sig"
        gpg --detach-sign --local-user BC8B600E8DDA1F4CB77B10D2BA803A261A5EE6B8 --output "$i.sig" "$i"
    fi
done

for i in *.pkg.tar.xz;
do
    if [ -f "${i}" ]; then
        echo "Удаление подписи $i.sig"
        rm -f $i.sig
        echo "Добавление подписи $i.sig"
        gpg --detach-sign --local-user BC8B600E8DDA1F4CB77B10D2BA803A261A5EE6B8 --output "$i.sig" "$i"
    fi
done

notify-send -a "$(basename $(pwd)): Make" -t 10000 "finished" "$(date '+%Y.%m.%d %H:%M:%S')"

echo "Ready"
if [ "$status" == 0 ]; then
    sleep 5

    process=$(ps x | grep konsole | grep $0 | awk '{print $1}')
    if [ $(( "$process" + 0 )) -ne 0 ]; then
        kill $(ps x | grep konsole | grep $0 | awk '{print $1}')
    fi
fi
