summaryrefslogtreecommitdiff
path: root/tools/check_for_upgrade.sh
diff options
context:
space:
mode:
Diffstat (limited to 'tools/check_for_upgrade.sh')
-rw-r--r--tools/check_for_upgrade.sh29
1 files changed, 13 insertions, 16 deletions
diff --git a/tools/check_for_upgrade.sh b/tools/check_for_upgrade.sh
index 8264762b6..70cd21f84 100644
--- a/tools/check_for_upgrade.sh
+++ b/tools/check_for_upgrade.sh
@@ -58,23 +58,20 @@ function is_update_available() {
local local_head
local_head=$(git -C "$ZSH" rev-parse $branch 2>/dev/null) || return 0
- # Get remote HEAD. If we can't get it assume there are updates unless there is no connection:
- # - curl: 6 (could not resolve) or 7 (could not connect)
- # - wget: 4 (network unreachable)
- # - fetch: 1 (no route to host)
- local remote_head ret
+ # Get remote HEAD. If no suitable command is found assume there are updates
+ # On any other error, skip the update (connection may be down)
+ local remote_head
remote_head=$(
- curl -fsSL -H 'Accept: application/vnd.github.v3.sha' $api_url 2>/dev/null || {
- [[ $? -eq 6 || $? -eq 7 ]] && exit 1
- } || wget -O- --header='Accept: application/vnd.github.v3.sha' $api_url 2>/dev/null || {
- [[ $? -eq 4 ]] && exit 1
- } || HTTP_ACCEPT='Accept: application/vnd.github.v3.sha' fetch -o - $api_url 2>/dev/null || {
- [[ $? -eq 1 ]] && exit 1
- } || exit 0
- )
-
- # If can't fetch remote HEAD, return exit code
- ret=$?; [[ -n "$remote_head" ]] || return $ret
+ if (( ${+commands[curl]} )); then
+ curl -fsSL -H 'Accept: application/vnd.github.v3.sha' $api_url 2>/dev/null
+ elif (( ${+commands[wget]} )); then
+ wget -O- --header='Accept: application/vnd.github.v3.sha' $api_url 2>/dev/null
+ elif (( ${+commands[fetch]} )); then
+ HTTP_ACCEPT='Accept: application/vnd.github.v3.sha' fetch -o - $api_url 2>/dev/null
+ else
+ exit 0
+ fi
+ ) || return 1
# Compare local and remote HEADs
[[ "$local_head" != "$remote_head" ]]