7a2cb106258aa7a18bcd53e45df96c4871a03d5e
- Author
- Marc Cornellà <hello@mcornella.com>
- Committer
- Marc Cornellà <hello@mcornella.com>
- Date
Message
fix(updater): stop update if connection unavailable
Diff
1diff --git a/tools/check_for_upgrade.sh b/tools/check_for_upgrade.sh
2index 157b0cce2404dd2c9d7f134a48e3272a8577b022..8264762b6c5e3301f53a7e6245db710a2b85f976 100644
3--- a/tools/check_for_upgrade.sh
4+++ b/tools/check_for_upgrade.sh
5@@ -54,14 +54,27 @@ function is_update_available() {
6 [[ "$repo" = ohmyzsh/ohmyzsh ]] || return 0
7 local api_url="https://api.github.com/repos/${repo}/commits/${branch}"
8
9- # Get local and remote HEADs and compare them. If we can't get either assume there are updates
10- local local_head remote_head
11+ # Get local HEAD. If this fails assume there are updates
12+ local local_head
13 local_head=$(git -C "$ZSH" rev-parse $branch 2>/dev/null) || return 0
14
15- remote_head=$(curl -fsSL -H 'Accept: application/vnd.github.v3.sha' $api_url 2>/dev/null) \
16- || remote_head=$(wget -O- --header='Accept: application/vnd.github.v3.sha' $api_url 2>/dev/null) \
17- || remote_head=$(HTTP_ACCEPT='Accept: application/vnd.github.v3.sha' fetch -o - $api_url 2>/dev/null) \
18- || return 0
19+ # Get remote HEAD. If we can't get it assume there are updates unless there is no connection:
20+ # - curl: 6 (could not resolve) or 7 (could not connect)
21+ # - wget: 4 (network unreachable)
22+ # - fetch: 1 (no route to host)
23+ local remote_head ret
24+ remote_head=$(
25+ curl -fsSL -H 'Accept: application/vnd.github.v3.sha' $api_url 2>/dev/null || {
26+ [[ $? -eq 6 || $? -eq 7 ]] && exit 1
27+ } || wget -O- --header='Accept: application/vnd.github.v3.sha' $api_url 2>/dev/null || {
28+ [[ $? -eq 4 ]] && exit 1
29+ } || HTTP_ACCEPT='Accept: application/vnd.github.v3.sha' fetch -o - $api_url 2>/dev/null || {
30+ [[ $? -eq 1 ]] && exit 1
31+ } || exit 0
32+ )
33+
34+ # If can't fetch remote HEAD, return exit code
35+ ret=$?; [[ -n "$remote_head" ]] || return $ret
36
37 # Compare local and remote HEADs
38 [[ "$local_head" != "$remote_head" ]]