From 40bfe5a4124be7b5983756cc81b54a4a4d5846e6 Mon Sep 17 00:00:00 2001 From: Fabian Wolff Date: Mon, 26 Sep 2016 21:41:42 +0200 Subject: Implement a locking mechanism to avoid multiple update prompts (fixes #3766) --- tools/check_for_upgrade.sh | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) (limited to 'tools/check_for_upgrade.sh') diff --git a/tools/check_for_upgrade.sh b/tools/check_for_upgrade.sh index bd9aba8be..d1b174c6d 100644 --- a/tools/check_for_upgrade.sh +++ b/tools/check_for_upgrade.sh @@ -29,31 +29,36 @@ fi # Cancel upgrade if git is unavailable on the system whence git >/dev/null || return 0 -if [ -f ~/.zsh-update ] +if mkdir "$ZSH/log/update.lock" 2>/dev/null then - . ~/.zsh-update + if [ -f ~/.zsh-update ] + then + . ~/.zsh-update - if [[ -z "$LAST_EPOCH" ]]; then - _update_zsh_update && return 0; - fi + if [[ -z "$LAST_EPOCH" ]]; then + _update_zsh_update && return 0; + fi - epoch_diff=$(($(_current_epoch) - $LAST_EPOCH)) - if [ $epoch_diff -gt $epoch_target ] - then - if [ "$DISABLE_UPDATE_PROMPT" = "true" ] + epoch_diff=$(($(_current_epoch) - $LAST_EPOCH)) + if [ $epoch_diff -gt $epoch_target ] then - _upgrade_zsh - else - echo "[Oh My Zsh] Would you like to check for updates? [Y/n]: \c" - read line - if [[ "$line" == Y* ]] || [[ "$line" == y* ]] || [ -z "$line" ]; then + if [ "$DISABLE_UPDATE_PROMPT" = "true" ] + then _upgrade_zsh else - _update_zsh_update + echo "[Oh My Zsh] Would you like to check for updates? [Y/n]: \c" + read line + if [[ "$line" == Y* ]] || [[ "$line" == y* ]] || [ -z "$line" ]; then + _upgrade_zsh + else + _update_zsh_update + fi fi fi + else + # create the zsh file + _update_zsh_update fi -else - # create the zsh file - _update_zsh_update + + rm -r $ZSH/log/update.lock fi -- cgit v1.2.3-70-g09d2 From 4fa6be02300ff1bbf3772be0c8f7993a46c3769e Mon Sep 17 00:00:00 2001 From: Fabian Wolff Date: Mon, 3 Oct 2016 11:52:25 +0200 Subject: Use rmdir instead of rm -r --- tools/check_for_upgrade.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/check_for_upgrade.sh') diff --git a/tools/check_for_upgrade.sh b/tools/check_for_upgrade.sh index d1b174c6d..3c9a4e4ca 100644 --- a/tools/check_for_upgrade.sh +++ b/tools/check_for_upgrade.sh @@ -60,5 +60,5 @@ then _update_zsh_update fi - rm -r $ZSH/log/update.lock + rmdir $ZSH/log/update.lock fi -- cgit v1.2.3-70-g09d2 From 1f64fa92f524d47a87320a4baf9d9883fd23ab5e Mon Sep 17 00:00:00 2001 From: Fabian Wolff Date: Mon, 3 Oct 2016 11:58:15 +0200 Subject: Convert "if then" statements to "if; then" one-liners --- tools/check_for_upgrade.sh | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'tools/check_for_upgrade.sh') diff --git a/tools/check_for_upgrade.sh b/tools/check_for_upgrade.sh index 3c9a4e4ca..a57f6da0f 100644 --- a/tools/check_for_upgrade.sh +++ b/tools/check_for_upgrade.sh @@ -29,10 +29,8 @@ fi # Cancel upgrade if git is unavailable on the system whence git >/dev/null || return 0 -if mkdir "$ZSH/log/update.lock" 2>/dev/null -then - if [ -f ~/.zsh-update ] - then +if mkdir "$ZSH/log/update.lock" 2>/dev/null; then + if [ -f ~/.zsh-update ]; then . ~/.zsh-update if [[ -z "$LAST_EPOCH" ]]; then @@ -40,10 +38,8 @@ then fi epoch_diff=$(($(_current_epoch) - $LAST_EPOCH)) - if [ $epoch_diff -gt $epoch_target ] - then - if [ "$DISABLE_UPDATE_PROMPT" = "true" ] - then + if [ $epoch_diff -gt $epoch_target ]; then + if [ "$DISABLE_UPDATE_PROMPT" = "true" ]; then _upgrade_zsh else echo "[Oh My Zsh] Would you like to check for updates? [Y/n]: \c" -- cgit v1.2.3-70-g09d2 From 2b7a41b0d2e6a67ad14f94f7cc00293491f2c3f8 Mon Sep 17 00:00:00 2001 From: Gert de Pagter Date: Tue, 15 May 2018 11:26:59 +0200 Subject: Update the update prompt (#6825) `[Oh My Zsh] Would you like to check for updates? [Y/n]: ` does not make sense, since answering yes will download/apply the new updates instead of checking for them. --- tools/check_for_upgrade.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/check_for_upgrade.sh') diff --git a/tools/check_for_upgrade.sh b/tools/check_for_upgrade.sh index a57f6da0f..b42b87750 100644 --- a/tools/check_for_upgrade.sh +++ b/tools/check_for_upgrade.sh @@ -42,7 +42,7 @@ if mkdir "$ZSH/log/update.lock" 2>/dev/null; then if [ "$DISABLE_UPDATE_PROMPT" = "true" ]; then _upgrade_zsh else - echo "[Oh My Zsh] Would you like to check for updates? [Y/n]: \c" + echo "[Oh My Zsh] Would you like to update? [Y/n]: \c" read line if [[ "$line" == Y* ]] || [[ "$line" == y* ]] || [ -z "$line" ]; then _upgrade_zsh -- cgit v1.2.3-70-g09d2 From de8299d6c4f50bc40286a05cd7e802b6bffe41f0 Mon Sep 17 00:00:00 2001 From: Chao Du Date: Mon, 2 Nov 2015 14:29:37 +0800 Subject: Fixed Issue #4550: Move ~/.zsh-update file to $ZSH_CACHE_DIR --- oh-my-zsh.sh | 14 +++++++------- tools/check_for_upgrade.sh | 8 ++++---- 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'tools/check_for_upgrade.sh') diff --git a/oh-my-zsh.sh b/oh-my-zsh.sh index 72527362f..ca505d1ba 100644 --- a/oh-my-zsh.sh +++ b/oh-my-zsh.sh @@ -1,6 +1,12 @@ +# Set ZSH_CACHE_DIR to the path where cache files should be created +# or else we will use the default cache/ +if [[ -z "$ZSH_CACHE_DIR" ]]; then + ZSH_CACHE_DIR="$ZSH/cache" +fi + # Check for updates on initial load... if [ "$DISABLE_AUTO_UPDATE" != "true" ]; then - env ZSH=$ZSH DISABLE_UPDATE_PROMPT=$DISABLE_UPDATE_PROMPT zsh -f $ZSH/tools/check_for_upgrade.sh + env ZSH=$ZSH ZSH_CACHE_DIR=$ZSH_CACHE_DIR DISABLE_UPDATE_PROMPT=$DISABLE_UPDATE_PROMPT zsh -f $ZSH/tools/check_for_upgrade.sh fi # Initializes Oh My Zsh @@ -17,12 +23,6 @@ if [[ -z "$ZSH_CUSTOM" ]]; then ZSH_CUSTOM="$ZSH/custom" fi -# Set ZSH_CACHE_DIR to the path where cache files should be created -# or else we will use the default cache/ -if [[ -z "$ZSH_CACHE_DIR" ]]; then - ZSH_CACHE_DIR="$ZSH/cache" -fi - # Load all of the config files in ~/oh-my-zsh that end in .zsh # TIP: Add files you don't want in git to .gitignore diff --git a/tools/check_for_upgrade.sh b/tools/check_for_upgrade.sh index b42b87750..05b31e8d4 100644 --- a/tools/check_for_upgrade.sh +++ b/tools/check_for_upgrade.sh @@ -7,7 +7,7 @@ function _current_epoch() { } function _update_zsh_update() { - echo "LAST_EPOCH=$(_current_epoch)" >! ~/.zsh-update + echo "LAST_EPOCH=$(_current_epoch)" >! ${ZSH_CACHE_DIR}/.zsh-update } function _upgrade_zsh() { @@ -30,11 +30,11 @@ fi whence git >/dev/null || return 0 if mkdir "$ZSH/log/update.lock" 2>/dev/null; then - if [ -f ~/.zsh-update ]; then - . ~/.zsh-update + if [ -f ${ZSH_CACHE_DIR}/.zsh-update ]; then + . ${ZSH_CACHE_DIR}/.zsh-update if [[ -z "$LAST_EPOCH" ]]; then - _update_zsh_update && return 0; + _update_zsh_update && return 0 fi epoch_diff=$(($(_current_epoch) - $LAST_EPOCH)) -- cgit v1.2.3-70-g09d2 From c23ab00990c8528a3334d178b9ec9135385cc99f Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Sun, 7 Apr 2019 20:39:25 +0200 Subject: upgrade: fix lock-out on first upgrade check This early return made it so the lock wasn't removed, therefore locking out the upgrade script from ever entering the upgrade routine. Fixes #6138 Note: the logic needs some rework. --- tools/check_for_upgrade.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'tools/check_for_upgrade.sh') diff --git a/tools/check_for_upgrade.sh b/tools/check_for_upgrade.sh index 05b31e8d4..c8dedcf77 100644 --- a/tools/check_for_upgrade.sh +++ b/tools/check_for_upgrade.sh @@ -34,7 +34,9 @@ if mkdir "$ZSH/log/update.lock" 2>/dev/null; then . ${ZSH_CACHE_DIR}/.zsh-update if [[ -z "$LAST_EPOCH" ]]; then - _update_zsh_update && return 0 + _update_zsh_update + rmdir $ZSH/log/update.lock # TODO: fix later + return 0 fi epoch_diff=$(($(_current_epoch) - $LAST_EPOCH)) -- cgit v1.2.3-70-g09d2