#!/bin/bash
# Copyright 2023 - 2025, project-repo and the cagebreak contributors
# SPDX-License-Identifier: MIT

RESULT=0

# shellcheck disable=2164
cd "${MESONCURRENTCONFIGDIR}/keys"
stoday=$(date +%s)
signingmargin=120

# shellcheck disable=2046
skey13exptime=$(date --date=$(gpg --show-keys cagebreak_signing_key_13\@project-repo.co.pub | tail -2 | head -1 | cut -d " " -f 8 | rev | cut -c2- | rev) '+%s')
# shellcheck disable=2046
skey14exptime=$(date --date=$(gpg --show-keys cagebreak_signing_key_14\@project-repo.co.pub | tail -2 | head -1 | cut -d " " -f 8 | rev | cut -c2- | rev) '+%s')
# shellcheck disable=2046
mailexptime=$(date --date=$(gpg --show-keys cagebreak\@project-repo.co.pub | tail -2 | head -1 | cut -d " " -f 8 | rev | cut -c2- | rev) '+%s')

# signing keys
## signing key 13
if [[ $(( (stoday - skey13exptime) / 86400 )) -lt $signingmargin ]]
then
    echo "[x] signign key 13"
else
    RESULT=1
    echo "[ ] signing key 13"
fi
## signing key 14
if [[ $(( (stoday - skey14exptime) / 86400 )) -lt $signingmargin ]]
then
    echo "[x] signign key 14"
else
    RESULT=1
    echo "[ ] signing key 14"
fi

# email key
if [[ $(( (stoday - mailexptime) / 86400 )) -lt $signingmargin ]]
then
    echo "[x] mail key"
else
    RESULT=1
    echo "[ ] mail key"
fi

exit "${RESULT}"
