only check connectivity when an update is needed

This commit is contained in:
Eric Keller 2017-09-02 19:28:53 +02:00
commit 0b1716e5cd

View file

@ -11,6 +11,18 @@ function _update_zsh_update() {
} }
function _upgrade_zsh() { function _upgrade_zsh() {
# Skip when no internet connectivity, depends on curl
REMOTE=$(cd "$ZSH" && git remote get-url --all origin)
echo "$REMOTE" | grep -qa 'git@'
if [ $? -eq 0 ]
then
# convert the remote protocol to https
REMOTE=$(echo $REMOTE | tr ':' '/' | sed -e "s#git@#https://#")
fi
# -L follow redirect, -s silent,
# --max-time overall operation timeout, -I only download headers
whence curl > /dev/null && curl -L -s --max-time 3 -I ${REMOTE} > /dev/null || return 0
env ZSH=$ZSH sh $ZSH/tools/upgrade.sh env ZSH=$ZSH sh $ZSH/tools/upgrade.sh
# update the zsh file # update the zsh file
_update_zsh_update _update_zsh_update
@ -29,18 +41,6 @@ fi
# Cancel upgrade if git is unavailable on the system # Cancel upgrade if git is unavailable on the system
whence git >/dev/null || return 0 whence git >/dev/null || return 0
# Skip when no internet connectivity, depends on curl
REMOTE=$(cd "$ZSH" && git remote get-url --all origin)
echo "$REMOTE" | grep -qa 'git@'
if [ $? -eq 0 ]
then
# convert the remote protocol to https
REMOTE=$(echo $REMOTE | tr ':' '/' | sed -e "s#git@#https://#")
fi
# -L follow redirect, -s silent,
# --max-time overall operation timeout, -I only download headers
whence curl > /dev/null && curl -L -s --max-time 3 -I ${REMOTE} > /dev/null || return 0
if mkdir "$ZSH/log/update.lock" 2>/dev/null; then if mkdir "$ZSH/log/update.lock" 2>/dev/null; then
if [ -f ~/.zsh-update ]; then if [ -f ~/.zsh-update ]; then
. ~/.zsh-update . ~/.zsh-update