Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility with BSD date #1

Merged
merged 8 commits into from
Mar 31, 2024
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 37 additions & 13 deletions securitytxt-signer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ if [ "$#" -lt 1 ]; then
exit 1
fi

# Prepare environment

[[ "$(uname)" == "Darwin" ]] && IS_MAC=1 || IS_MAC=0

# Check for requirements. Print all unmet requirements at once.

required_command() {
Expand Down Expand Up @@ -77,14 +81,25 @@ if ! [[ "$KEY" =~ ^0x[a-fA-F0-9]{8,40}$ ]]; then
else
KEY_INFO=$(gpg --list-secret-keys "$KEY" 2> >(sed $'s,.*,\e[33m&\e[m,'>&2))

KEY_EXPIRES=$(
echo "$KEY_INFO" \
| grep "sec" \
| grep -Eo 'expires:\ [0-9\-]+' \
| awk '{ print $2}' \
| date -Iseconds -u -f - \
| sed -e 's/+00:00$/Z/'
)
if (( IS_MAC )); then
KEY_EXPIRES=$(
echo "$KEY_INFO" \
| grep "sec" \
| grep -Eo 'expires:\ [0-9\-]+' \
| awk '{ print $2}' \
| date -Iseconds -u \
| sed -e 's/+00:00$/Z/'
)
else
KEY_EXPIRES=$(
echo "$KEY_INFO" \
| grep "sec" \
| grep -Eo 'expires:\ [0-9\-]+' \
| awk '{ print $2}' \
| date -Iseconds -u -f - \
| sed -e 's/+00:00$/Z/'
)
fi
echo

if [[ "$KEY_EXPIRES" = "" ]]; then
Expand All @@ -96,8 +111,8 @@ else
GREPABLE_KEY=${KEY//0x/}
FP=$(echo "$KEY_INFO" | grep -i "$GREPABLE_KEY" | sed -e 's/[^A-F0-9]//g')
KEY="0x${FP}"
if ! [[ "${KEY}" = "0x${GREPABLE_KEY^^}" ]]; then
echo -e "\033[0;33mEXPANDED 0x${GREPABLE_KEY^^} TO ${KEY}\033[0;0m"
if ! [[ "${KEY}" = "0x$(echo "${GREPABLE_KEY}" | awk '{print toupper($0)}')" ]]; then
echo -e "\033[0;33mEXPANDED 0x$(echo "${GREPABLE_KEY}" | awk '{print toupper($0)}') TO ${KEY}\033[0;0m"
fi
fi

Expand All @@ -115,13 +130,22 @@ fi
# Set expire date.
# If the key expires before the DAYS_MAX, use the key expiration date instead.

EXPIRES=$(date -Iseconds -u -d "${DAYS_MAX} days" | sed -e 's/+00:00$/Z/')
if (( IS_MAC )); then
EXPIRES=$(date -Iseconds -u -v+${DAYS_MAX}d | sed -e 's/+00:00$/Z/')
else
EXPIRES=$(date -Iseconds -u -d "${DAYS_MAX} days" | sed -e 's/+00:00$/Z/')
fi

if [ -z ${KEY_EXPIRES+x} ]; then
echo -e "\033[0;33mUSING EXPIRE (max ${DAYS_MAX} days): $EXPIRES\033[0;0m"
else
EXPIRES_COMPARABLE=$(date -d "$EXPIRES" +%s)
KEY_EXPIRES_COMPARABLE=$(date -d "$KEY_EXPIRES" +%s)
if (( IS_MAC )); then
EXPIRES_COMPARABLE=$(date -j -f "%Y-%m-%dT%H:%M:%SZ" "$EXPIRES" +%s)
KEY_EXPIRES_COMPARABLE=$(date -j -f "%Y-%m-%dT%H:%M:%SZ" "$KEY_EXPIRES" +%s)
else
EXPIRES_COMPARABLE=$(date -d "$EXPIRES" +%s)
KEY_EXPIRES_COMPARABLE=$(date -d "$KEY_EXPIRES" +%s)
fi

echo -e "\033[0;33mComparing ${EXPIRES} to key expr ${KEY_EXPIRES}.\033[0;0m"

Expand Down
Loading