#! /bin/bash

# Set globals
LIBDIR=/usr/share/manjaro-arm-tools/lib

# Import the library
source $LIBDIR/functions.sh

sign_file() {
    load_vars "$HOME/.makepkg.conf"
    load_vars /etc/makepkg.conf

    if [ ! -e "$1" ]; then
        info "%s does not exist, aborting" "$1"
        exit 1
    fi

    msg "Signing [%s] with key %s" "${1##*/}" "${GPGKEY}..."
    [[ -e "$1".sig ]] && rm "$1".sig
    gpg --detach-sign --use-agent -u "${GPGKEY}" "$1"
}

PKGS=$(find $PWD -maxdepth 1 -regex '.*\.pkg\.tar\.\(xz\|zst\)')
for f in $PKGS; do
    sign_file $f
done
