From a8e2f8503b74790b28c728c029b6e5c369c0df12 Mon Sep 17 00:00:00 2001 From: popcornmix Date: Tue, 30 May 2017 14:27:08 +0100 Subject: [PATCH] Include a specific check for github API limit being hit --- rpi-update | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/rpi-update b/rpi-update index 22bc59e..e04d8da 100755 --- a/rpi-update +++ b/rpi-update @@ -54,6 +54,13 @@ if [[ -n "${GITHUB_API_TOKEN}" ]]; then GITHUB_AUTH_PARAM="--header \"Authorization: token ${GITHUB_API_TOKEN}\"" fi +GITHUB_API_LIMITED=$(eval curl -Ls ${GITHUB_AUTH_PARAM} https://api.github.com/rate_limit | awk 'BEGIN {reset=0;} { if ($1 == "\"limit\":") limit=strtonum($2); else if ($1 == "\"remaining\":") remaining=strtonum($2); else if ($1 == "\"reset\":" && limit>0 && remaining==0) reset=strtonum($2);} END { print reset }') +if [ ${GITHUB_API_LIMITED} -gt 0 ]; then + echo " *** Github api is currently rate limited - please try again after $(date --date @${GITHUB_API_LIMITED})" + exit 1 +fi + + function update_self() { echo " *** Performing self-update" _tempFileName="$0.tmp"