Merge pull request #1919 from ich777/patch-5

Make hook script compatible with busybox `date`
This commit is contained in:
tom mortensen
2024-11-15 16:02:54 -08:00
committed by GitHub

View File

@@ -249,11 +249,16 @@ fi
KEY_EXPIRY=$(tailscale status --json | jq -r '.Self.KeyExpiry')
if [ "${KEY_EXPIRY}" != "null" ]; then
EXPIRY_EPOCH=$(date -d "${KEY_EXPIRY}" +"%s" 2>/dev/null)
if [ -z "${EXPIRY_EPOCH}" ]; then
EXPIRY_EPOCH=$(date -d "$(echo "${KEY_EXPIRY}" | sed 's/T/ /; s/Z//')" +"%s")
fi
CUR_EPOCH=$(date -u +%s)
DIFF_EPOCH=$((EXPIRY_EPOCH - CUR_EPOCH))
DIFF_DAYS=$((DIFF_EPOCH / 86400))
HOST=$(tailscale status --json | jq -r '.Self.HostName')
if [ -n "${DIFF_DAYS}" ] && echo "${DIFF_DAYS}" | grep -Eq '^[0-9]+$'; then
if [ -z "${EXPIRY_EPOCH}" ]; then
echo "WARNING: An error occurred while retrieving the Tailscale key expiry!"
elif [ -n "${DIFF_DAYS}" ] && echo "${DIFF_DAYS}" | grep -Eq '^[0-9]+$'; then
echo "WARNING: Tailscale Key will expire in ${DIFF_DAYS} days."
echo " Navigate to https://login.tailscale.com/admin/machines and 'Disable Key Expiry' for ${HOST}"
else